diff --git a/S2OJ/1446/1446.cpp b/S2OJ/1446/1446.cpp new file mode 100644 index 00000000..60ddfe7b --- /dev/null +++ b/S2OJ/1446/1446.cpp @@ -0,0 +1,94 @@ +#include +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 1e5 + 5; + +int n, c, t, a[N], st[N], ed[N], pos[N], rep[N]; + +inline void pushdown(int x) { + if (rep[x] != -1) { + for (int i = st[x]; i <= ed[x]; i++) a[i] = rep[x]; + rep[x] = -1; + } +} + +int solve(int l, int r, int c) { + int p = pos[l], + q = pos[r]; + int res = 0; + + if (p == q) { + pushdown(p); + for (int i = l; i <= r; i++) { + if (a[i] == c) res++; + a[i] = c; + } + + return res; + } + + pushdown(p); + for (int i = l; i <= ed[p]; i++) { + if (a[i] == c) res++; + a[i] = c; + } + + pushdown(q); + for (int i = st[q]; i <= r; i++) { + if (a[i] == c) res++; + a[i] = c; + } + + for (int i = p + 1; i <= q - 1; i++) { + if (rep[i] != -1) { + if (rep[i] == c) res += ed[i] - st[i] + 1; + } else { + for (int j = st[i]; j <= ed[i]; j++) { + if (a[j] == c) res++; + a[j] = c; + } + } + rep[i] = c; + } + + return res; +} + +int main() { + std::ios::sync_with_stdio(false); + + memset(rep, 0xff, sizeof(rep)); + + cin >> n; + + for (int i = 1; i <= n; i++) { + cin >> a[i]; + } + + t = std::sqrt(n); + + for (c = 1;; c++) { + st[c] = (c - 1) * t + 1; + ed[c] = std::min(n, c * t); + + if (c * t >= n) break; + } + + for (int i = 1; i <= c; i++) { + for (int j = st[i]; j <= ed[i]; j++) { + pos[j] = i; + } + } + + for (int i = 1, l, r, c; i <= n; i++) { + cin >> l >> r >> c; + cout << solve(l, r, c) << endl; + } + + return 0; +} diff --git a/S2OJ/1446/data/a1.in b/S2OJ/1446/data/a1.in new file mode 100644 index 00000000..69e5187e --- /dev/null +++ b/S2OJ/1446/data/a1.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:50b6049d9e7f4598daa87487d00d4ce50b17892e2f50fcabe0dd1969a826194e +size 157818 diff --git a/S2OJ/1446/data/a1.out b/S2OJ/1446/data/a1.out new file mode 100644 index 00000000..4fd3885d --- /dev/null +++ b/S2OJ/1446/data/a1.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:16c19a30543215918faa48c02216c7d7755fabf1f4762766feb5a54dfe9295a6 +size 12515 diff --git a/S2OJ/1446/data/a10.in b/S2OJ/1446/data/a10.in new file mode 100644 index 00000000..8131351a --- /dev/null +++ b/S2OJ/1446/data/a10.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e110af7fdfd9bceefb4e1c7a0ecace4eda4783c2fa867abc3e63b436a5b5c248 +size 3377820 diff --git a/S2OJ/1446/data/a10.out b/S2OJ/1446/data/a10.out new file mode 100644 index 00000000..daec74ae --- /dev/null +++ b/S2OJ/1446/data/a10.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ceec1d2daea3255818c0351228c8268a7473406f4ee26839bb027657d0736d04 +size 280797 diff --git a/S2OJ/1446/data/a2.in b/S2OJ/1446/data/a2.in new file mode 100644 index 00000000..69e5187e --- /dev/null +++ b/S2OJ/1446/data/a2.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:50b6049d9e7f4598daa87487d00d4ce50b17892e2f50fcabe0dd1969a826194e +size 157818 diff --git a/S2OJ/1446/data/a2.out b/S2OJ/1446/data/a2.out new file mode 100644 index 00000000..4fd3885d --- /dev/null +++ b/S2OJ/1446/data/a2.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:16c19a30543215918faa48c02216c7d7755fabf1f4762766feb5a54dfe9295a6 +size 12515 diff --git a/S2OJ/1446/data/a3.in b/S2OJ/1446/data/a3.in new file mode 100644 index 00000000..69e5187e --- /dev/null +++ b/S2OJ/1446/data/a3.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:50b6049d9e7f4598daa87487d00d4ce50b17892e2f50fcabe0dd1969a826194e +size 157818 diff --git a/S2OJ/1446/data/a3.out b/S2OJ/1446/data/a3.out new file mode 100644 index 00000000..4fd3885d --- /dev/null +++ b/S2OJ/1446/data/a3.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:16c19a30543215918faa48c02216c7d7755fabf1f4762766feb5a54dfe9295a6 +size 12515 diff --git a/S2OJ/1446/data/a4.in b/S2OJ/1446/data/a4.in new file mode 100644 index 00000000..aa867795 --- /dev/null +++ b/S2OJ/1446/data/a4.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0117ccc558449674f7f9ca7c5c449ac8a5d3fa5637ef4c8a9d3cf03386d340b6 +size 3378066 diff --git a/S2OJ/1446/data/a4.out b/S2OJ/1446/data/a4.out new file mode 100644 index 00000000..d0e4a876 --- /dev/null +++ b/S2OJ/1446/data/a4.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5a3bb861df15ebc679538e51b45be68d1dd26d20c9b390e4718d55d093555c5c +size 280935 diff --git a/S2OJ/1446/data/a5.in b/S2OJ/1446/data/a5.in new file mode 100644 index 00000000..aa867795 --- /dev/null +++ b/S2OJ/1446/data/a5.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0117ccc558449674f7f9ca7c5c449ac8a5d3fa5637ef4c8a9d3cf03386d340b6 +size 3378066 diff --git a/S2OJ/1446/data/a5.out b/S2OJ/1446/data/a5.out new file mode 100644 index 00000000..d0e4a876 --- /dev/null +++ b/S2OJ/1446/data/a5.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5a3bb861df15ebc679538e51b45be68d1dd26d20c9b390e4718d55d093555c5c +size 280935 diff --git a/S2OJ/1446/data/a6.in b/S2OJ/1446/data/a6.in new file mode 100644 index 00000000..1a4e6c2a --- /dev/null +++ b/S2OJ/1446/data/a6.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ec4340c03c79aafdab34eb79c1bef3cc1f56451a77cb6042c8bdb0981a9c54d2 +size 3377474 diff --git a/S2OJ/1446/data/a6.out b/S2OJ/1446/data/a6.out new file mode 100644 index 00000000..856b3a92 --- /dev/null +++ b/S2OJ/1446/data/a6.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:91b4bc927d9707d03b87f697fb674362d81c1c3d23ed3149956d46c2c128f733 +size 281005 diff --git a/S2OJ/1446/data/a7.in b/S2OJ/1446/data/a7.in new file mode 100644 index 00000000..1a4e6c2a --- /dev/null +++ b/S2OJ/1446/data/a7.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ec4340c03c79aafdab34eb79c1bef3cc1f56451a77cb6042c8bdb0981a9c54d2 +size 3377474 diff --git a/S2OJ/1446/data/a7.out b/S2OJ/1446/data/a7.out new file mode 100644 index 00000000..856b3a92 --- /dev/null +++ b/S2OJ/1446/data/a7.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:91b4bc927d9707d03b87f697fb674362d81c1c3d23ed3149956d46c2c128f733 +size 281005 diff --git a/S2OJ/1446/data/a8.in b/S2OJ/1446/data/a8.in new file mode 100644 index 00000000..96c168a8 --- /dev/null +++ b/S2OJ/1446/data/a8.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8866ea254b339a86feeccfead24b36468af40e6d10349fb7ef80416523dca9be +size 3377827 diff --git a/S2OJ/1446/data/a8.out b/S2OJ/1446/data/a8.out new file mode 100644 index 00000000..64b2125d --- /dev/null +++ b/S2OJ/1446/data/a8.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:123792996fc648d0c0305bd77fc1fdc33ada16bffa0c57f0312f80bb80d76d40 +size 281258 diff --git a/S2OJ/1446/data/a9.in b/S2OJ/1446/data/a9.in new file mode 100644 index 00000000..96c168a8 --- /dev/null +++ b/S2OJ/1446/data/a9.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8866ea254b339a86feeccfead24b36468af40e6d10349fb7ef80416523dca9be +size 3377827 diff --git a/S2OJ/1446/data/a9.out b/S2OJ/1446/data/a9.out new file mode 100644 index 00000000..64b2125d --- /dev/null +++ b/S2OJ/1446/data/a9.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:123792996fc648d0c0305bd77fc1fdc33ada16bffa0c57f0312f80bb80d76d40 +size 281258