diff --git a/Luogu/P3059/P3059.cpp b/Luogu/P3059/P3059.cpp new file mode 100644 index 00000000..7bc817ae --- /dev/null +++ b/Luogu/P3059/P3059.cpp @@ -0,0 +1,81 @@ +#include +#include +#include +#include +#include + +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 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(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 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; +} diff --git a/Luogu/P3059/data/P3059_1.in b/Luogu/P3059/data/P3059_1.in new file mode 100644 index 00000000..d875c84b --- /dev/null +++ b/Luogu/P3059/data/P3059_1.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:630636bc1348777cb2f08f49aa2a917464bbc008da2710a5008b3268c5925009 +size 50 diff --git a/Luogu/P3059/data/P3059_1.out b/Luogu/P3059/data/P3059_1.out new file mode 100644 index 00000000..ca267b30 --- /dev/null +++ b/Luogu/P3059/data/P3059_1.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1121cfccd5913f0a63fec40a6ffd44ea64f9dc135c66634ba001d10bcf4302a2 +size 2 diff --git a/Luogu/P3059/data/P3059_2.in b/Luogu/P3059/data/P3059_2.in new file mode 100644 index 00000000..8d2e2a20 --- /dev/null +++ b/Luogu/P3059/data/P3059_2.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:87aff564c87d04be519609d07714a81b0ca5e4d1933944758aed3cbe6074de1c +size 200012 diff --git a/Luogu/P3059/data/P3059_2.out b/Luogu/P3059/data/P3059_2.out new file mode 100644 index 00000000..3b8bc861 --- /dev/null +++ b/Luogu/P3059/data/P3059_2.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e3421522827625fedbc5cad2ca2fe32ec46b0f7ee53ee2e7f50215cd6cb6bb75 +size 4 diff --git a/Luogu/P3059/data/P3059_3.in b/Luogu/P3059/data/P3059_3.in new file mode 100644 index 00000000..d0936815 --- /dev/null +++ b/Luogu/P3059/data/P3059_3.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c7e9bfc0da63562461244f7bf868b3701766d063a9616853d0d625dc315fa3f2 +size 500019 diff --git a/Luogu/P3059/data/P3059_3.out b/Luogu/P3059/data/P3059_3.out new file mode 100644 index 00000000..fed0a030 --- /dev/null +++ b/Luogu/P3059/data/P3059_3.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:dcd29fcba35ffc953808262baffb971b9ceae5b1d54958c95bee9f8845e8434c +size 4 diff --git a/Luogu/P3059/data/P3059_4.in b/Luogu/P3059/data/P3059_4.in new file mode 100644 index 00000000..9c01b3e2 --- /dev/null +++ b/Luogu/P3059/data/P3059_4.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:bb15753b401c05eeebad67873a7a0c83a1a594dc5716edbf50a68d89e34f2dda +size 500019 diff --git a/Luogu/P3059/data/P3059_4.out b/Luogu/P3059/data/P3059_4.out new file mode 100644 index 00000000..41acbe3a --- /dev/null +++ b/Luogu/P3059/data/P3059_4.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:95c9a722010e30da9ceb3ff60556c15c679f0ee0ab29c3711da3a4d4f91fa25f +size 4 diff --git a/Luogu/P3059/data/P3059_7.in b/Luogu/P3059/data/P3059_7.in new file mode 100644 index 00000000..9ecdd60c --- /dev/null +++ b/Luogu/P3059/data/P3059_7.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4886995f3ca459b387d443dc8d6dc51d5d7a79aea61686ade4d3a6569f0e92dd +size 500019 diff --git a/Luogu/P3059/data/P3059_7.out b/Luogu/P3059/data/P3059_7.out new file mode 100644 index 00000000..2d8412e9 --- /dev/null +++ b/Luogu/P3059/data/P3059_7.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:40bbade878b24011d1883b4e5f3bdeb095045dc13bfaa579ef3262c58d56dbd1 +size 6 diff --git a/Luogu/P3059/data/P3059_9.in b/Luogu/P3059/data/P3059_9.in new file mode 100644 index 00000000..99f78aa6 --- /dev/null +++ b/Luogu/P3059/data/P3059_9.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a67e6684771611849c1b9046befe785038de2d39c6efe7f5ea2a95c730dd93dc +size 68 diff --git a/Luogu/P3059/data/P3059_9.out b/Luogu/P3059/data/P3059_9.out new file mode 100644 index 00000000..ca267b30 --- /dev/null +++ b/Luogu/P3059/data/P3059_9.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1121cfccd5913f0a63fec40a6ffd44ea64f9dc135c66634ba001d10bcf4302a2 +size 2