結果
問題 | No.879 Range Mod 2 Query |
ユーザー | e869120 |
提出日時 | 2019-09-06 22:27:03 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,563 bytes |
コンパイル時間 | 910 ms |
コンパイル使用メモリ | 78,320 KB |
実行使用メモリ | 8,320 KB |
最終ジャッジ日時 | 2024-06-24 22:11:49 |
合計ジャッジ時間 | 4,639 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | AC | 2 ms
5,376 KB |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | AC | 2 ms
5,376 KB |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | AC | 264 ms
8,064 KB |
testcase_20 | AC | 265 ms
7,936 KB |
testcase_21 | AC | 279 ms
8,192 KB |
ソースコード
#include <iostream> #include <vector> #include <algorithm> using namespace std; #pragma warning (disable: 4996) const int BACKET = 300; long long N, Q, A[1 << 18], T[1 << 18], L[1 << 18], R[1 << 18], X[1 << 18], ans[1 << 18]; long long S[1 << 18], Z1[1 << 18], Z2[1 << 18], ZADD[1 << 18], used[1 << 18]; void ranged(int l, int r) { vector<long long> C; for (int i = l; i < r; i++) { C.push_back(L[i]); C.push_back(R[i]); } sort(C.begin(), C.end()); C.erase(unique(C.begin(), C.end()), C.end()); for (int i = 0; i < C.size(); i++) { S[i] = 0; Z1[i] = 0; Z2[i] = 0; ZADD[i] = 0; used[i] = 0; } for (int i = 0; i < C.size() - 1; i++) { for (int j = C[i]; j < C[i + 1]; j++) { S[i] += A[j]; if (A[j] % 2 == 0) Z1[i]++; else Z2[i]++; } } for (int i = l; i < r; i++) { if (T[i] == 2) { int pos1 = lower_bound(C.begin(), C.end(), L[i]) - C.begin(); int pos2 = lower_bound(C.begin(), C.end(), R[i]) - C.begin(); for (int j = pos1; j < pos2; j++) { ZADD[j] += X[i]; } } if (T[i] == 1) { int pos1 = lower_bound(C.begin(), C.end(), L[i]) - C.begin(); int pos2 = lower_bound(C.begin(), C.end(), R[i]) - C.begin(); for (int j = pos1; j < pos2; j++) { if (used[j] == 0) { if (ZADD[j] % 2 == 0) used[j] = 1; else used[j] = 2; } if (used[j] == 1) { if (ZADD[j] % 2 == 0) used[j] = 1; else used[j] = 2; } if (used[j] == 2) { if (ZADD[j] % 2 == 0) used[j] = 2; else used[j] = 1; } if (ZADD[j] % 2 == 1) swap(Z1[j], Z2[j]); ZADD[j] = 0; } } if (T[i] == 3) { int pos1 = lower_bound(C.begin(), C.end(), L[i]) - C.begin(); int pos2 = lower_bound(C.begin(), C.end(), R[i]) - C.begin(); for (int j = pos1; j < pos2; j++) { if (used[j] == 0) ans[i] += S[j] + 1LL * (C[j + 1] - C[j]) * ZADD[j]; else ans[i] += Z2[j] + (C[j + 1] - C[j]) * ZADD[j]; } } } for (int i = 0; i < C.size() - 1; i++) { for (int j = C[i]; j < C[i + 1]; j++) { if (used[i] == 0) A[j] += ZADD[i]; if (used[i] == 1) { if (A[j] % 2 == 0) A[j] = 0LL + ZADD[i]; else A[j] = 1LL + ZADD[i]; } if (used[i] == 2) { if (A[j] % 2 == 0) A[j] = 1LL + ZADD[i]; else A[j] = 0LL + ZADD[i]; } } } } int main() { scanf("%lld%lld", &N, &Q); for (int i = 1; i <= N; i++) scanf("%lld", &A[i]); for (int i = 1; i <= Q; i++) { scanf("%lld%lld%lld", &T[i], &L[i], &R[i]); R[i]++; if (T[i] == 2) scanf("%lld", &X[i]); } for (int i = 1; i <= Q; i += BACKET) { int cl = i, cr = i + BACKET; cr = min(cr, (int)Q + 1); ranged(cl, cr); } for (int i = 1; i <= Q; i++) { if (T[i] == 3) printf("%lld\n", ans[i]); } return 0; }