結果
問題 | No.230 Splarraay スプラレェーイ |
ユーザー | pekempey |
提出日時 | 2017-01-04 18:33:04 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 45 ms / 5,000 ms |
コード長 | 3,148 bytes |
コンパイル時間 | 3,066 ms |
コンパイル使用メモリ | 197,860 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-05-10 00:34:27 |
合計ジャッジ時間 | 4,231 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 2 ms
6,944 KB |
testcase_02 | AC | 2 ms
6,940 KB |
testcase_03 | AC | 2 ms
6,944 KB |
testcase_04 | AC | 2 ms
6,940 KB |
testcase_05 | AC | 2 ms
6,944 KB |
testcase_06 | AC | 4 ms
6,944 KB |
testcase_07 | AC | 2 ms
6,944 KB |
testcase_08 | AC | 2 ms
6,940 KB |
testcase_09 | AC | 22 ms
6,944 KB |
testcase_10 | AC | 19 ms
6,940 KB |
testcase_11 | AC | 13 ms
6,940 KB |
testcase_12 | AC | 23 ms
6,944 KB |
testcase_13 | AC | 5 ms
6,940 KB |
testcase_14 | AC | 14 ms
6,940 KB |
testcase_15 | AC | 32 ms
6,940 KB |
testcase_16 | AC | 38 ms
6,944 KB |
testcase_17 | AC | 45 ms
6,940 KB |
testcase_18 | AC | 24 ms
6,944 KB |
testcase_19 | AC | 27 ms
6,940 KB |
ソースコード
#pragma GCC optimize ("O3") #pragma GCC target ("avx") #include <bits/stdc++.h> using namespace std; #define getchar getchar_unlocked int in() { int n; int c; while ((c = getchar()) < '0') if (c == EOF) return -1; n = c - '0'; while ((c = getchar()) >= '0') n = n * 10 + c - '0'; return n; } struct RSQ { // RMQ (4 level decomposition) static const int S = 18; struct Tuple { int sum = 0; int lazy = -1; }; Tuple L1[S], L2[S * S], L3[S * S * S]; int L4[S * S * S * S]; void setLazy1(int k, int v) { L1[k].lazy = v; L1[k].sum = v * S * S * S; } void setLazy2(int k, int v) { L2[k].lazy = v; L2[k].sum = v * S * S; } void setLazy3(int k, int v) { L3[k].lazy = v; L3[k].sum = v * S; } void push(int k) { int b1 = k / S / S / S; if (L1[b1].lazy != -1) { for (int i = b1 * S; i < b1 * S + S; i++) { setLazy2(i, L1[b1].lazy); } L1[b1].lazy = -1; } int b2 = k / S / S; if (L2[b2].lazy != -1) { for (int i = b2 * S; i < b2 * S + S; i++) { setLazy3(i, L2[b2].lazy); } L2[b2].lazy = -1; } int b3 = k / S; if (L3[b3].lazy != -1) { for (int i = b3 * S; i < b3 * S + S; i++) { L4[i] = L3[b3].lazy; } L3[b3].lazy = -1; } } void fix(int k) { int b3 = k / S; if (L3[b3].lazy == -1) { L3[b3].sum = 0; for (int i = b3 * S; i < b3 * S + S; i++) { L3[b3].sum += L4[i]; } } int b2 = k / S / S; if (L2[b2].lazy == -1) { L2[b2].sum = 0; for (int i = b2 * S; i < b2 * S + S; i++) { L2[b2].sum += L3[i].sum; } } int b1 = k / S / S / S; if (L1[b1].lazy == -1) { L1[b1].sum = 0; for (int i = b1 * S; i < b1 * S + S; i++) { L1[b1].sum += L2[i].sum; } } } void fill(int l, int r, int k) { int ll = l; int rr = r - 1; push(l); push(r - 1); while (l < r && l % S != 0) L4[l++] = k; while (l < r && r % S != 0) L4[--r] = k; l /= S; r /= S; while (l < r && l % S != 0) setLazy3(l++, k); while (l < r && r % S != 0) setLazy3(--r, k); l /= S; r /= S; while (l < r && l % S != 0) setLazy2(l++, k); while (l < r && r % S != 0) setLazy2(--r, k); l /= S; r /= S; while (l < r) setLazy1(l++, k); fix(ll); fix(rr); } int query(int l, int r) { push(l); push(r - 1); int ret = 0; while (l < r && l % S != 0) ret += L4[l++]; while (l < r && r % S != 0) ret += L4[--r]; l /= S; r /= S; while (l < r && l % S != 0) ret += L3[l++].sum; while (l < r && r % S != 0) ret += L3[--r].sum; l /= S; r /= S; while (l < r && l % S != 0) ret += L2[l++].sum; while (l < r && r % S != 0) ret += L2[--r].sum; l /= S; r /= S; while (l < r) ret += L1[l++].sum; return ret; } }; RSQ rsq[2]; int main() { int n = in(); int q = in(); long long scoreA = 0; long long scoreB = 0; while (q--) { int x = in() - 1; int l = in(); int r = in() + 1; if (x == -1) { int a = rsq[0].query(l, r); int b = rsq[1].query(l, r); if (a > b) scoreA += a; if (a < b) scoreB += b; } else { rsq[x ^ 0].fill(l, r, 1); rsq[x ^ 1].fill(l, r, 0); } } scoreA += rsq[0].query(0, n); scoreB += rsq[1].query(0, n); cout << scoreA << " " << scoreB << endl; }