0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-09-16 19:45:24 +00:00

3015. [Usaco2012 Nov]Concurrently Balanced Strings

This commit is contained in:
Baoshuo Ren 2022-08-18 08:04:09 +08:00
parent ac163af77c
commit ba8cf8cd9d
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A
33 changed files with 177 additions and 0 deletions

81
BZOJ/3015/3015.cpp Normal file
View File

@ -0,0 +1,81 @@
#include <iostream>
#include <algorithm>
#include <stack>
#include <string>
#include <vector>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 50005;
const int hash = 1000003;
const int mod = 1e9 + 7;
int k, n, a[15][N], s[15][N], e[N], next[15][N], ans;
std::vector<int> nums, p[N];
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> k >> n;
for (int i = 1; i <= k; i++) {
std::string str;
cin >> str;
for (int j = 1; j <= n; j++) {
a[i][j] = str[j - 1] == '(' ? 1 : -1;
s[i][j] = s[i][j - 1] + a[i][j];
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= k; j++) {
e[i] = ((static_cast<long long>(e[i]) * hash % mod + s[j][i]) % mod + mod) % mod;
}
nums.push_back(e[i]);
}
std::sort(nums.begin(), nums.end());
nums.erase(std::unique(nums.begin(), nums.end()), nums.end());
p[0].emplace_back(0);
for (int i = 1; i <= n; i++) {
e[i] = std::lower_bound(nums.begin(), nums.end(), e[i]) - nums.begin() + 1;
p[e[i]].emplace_back(i);
}
for (int i = 1; i <= k; i++) {
std::stack<int> st;
for (int j = 1; j <= n; j++) {
while (!st.empty() && s[i][st.top()] > s[i][j]) {
next[i][st.top()] = j;
st.pop();
}
st.emplace(j);
}
}
for (int i = 1; i <= n; i++) {
int min = n;
for (int j = 1; j <= k; j++) {
if (next[j][i]) {
min = std::min(min, next[j][i]);
}
}
ans += std::upper_bound(p[e[i]].begin(), p[e[i]].end(), min) - std::lower_bound(p[e[i]].begin(), p[e[i]].end(), i + 1);
}
cout << ans << endl;
return 0;
}

BIN
BZOJ/3015/data/1.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/3015/data/1.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/3015/data/10.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/3015/data/10.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/3015/data/11.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/3015/data/11.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/3015/data/12.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/3015/data/12.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/3015/data/13.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/3015/data/13.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/3015/data/14.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/3015/data/14.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/3015/data/15.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/3015/data/15.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/3015/data/16.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/3015/data/16.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/3015/data/2.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/3015/data/2.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/3015/data/3.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/3015/data/3.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/3015/data/4.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/3015/data/4.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/3015/data/5.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/3015/data/5.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/3015/data/6.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/3015/data/6.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/3015/data/7.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/3015/data/7.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/3015/data/8.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/3015/data/8.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/3015/data/9.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/3015/data/9.out (Stored with Git LFS) Normal file

Binary file not shown.