結果
問題 | No.879 Range Mod 2 Query |
ユーザー | pekempey |
提出日時 | 2019-09-07 18:14:48 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 240 ms / 3,000 ms |
コード長 | 4,932 bytes |
コンパイル時間 | 1,575 ms |
コンパイル使用メモリ | 170,956 KB |
実行使用メモリ | 14,976 KB |
最終ジャッジ日時 | 2024-06-27 00:15:08 |
合計ジャッジ時間 | 5,140 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 5 ms
11,648 KB |
testcase_01 | AC | 6 ms
11,776 KB |
testcase_02 | AC | 6 ms
11,520 KB |
testcase_03 | AC | 6 ms
11,648 KB |
testcase_04 | AC | 7 ms
11,520 KB |
testcase_05 | AC | 6 ms
11,648 KB |
testcase_06 | AC | 5 ms
11,520 KB |
testcase_07 | AC | 6 ms
11,776 KB |
testcase_08 | AC | 6 ms
11,776 KB |
testcase_09 | AC | 6 ms
11,648 KB |
testcase_10 | AC | 7 ms
11,648 KB |
testcase_11 | AC | 227 ms
14,208 KB |
testcase_12 | AC | 134 ms
14,208 KB |
testcase_13 | AC | 172 ms
14,080 KB |
testcase_14 | AC | 151 ms
14,748 KB |
testcase_15 | AC | 159 ms
13,768 KB |
testcase_16 | AC | 225 ms
14,848 KB |
testcase_17 | AC | 233 ms
14,864 KB |
testcase_18 | AC | 240 ms
14,720 KB |
testcase_19 | AC | 212 ms
14,688 KB |
testcase_20 | AC | 212 ms
14,976 KB |
testcase_21 | AC | 229 ms
14,720 KB |
ソースコード
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) #define repr(i, n) for (int i = (n) - 1; i >= 0; i--) #define range(a) a.begin(), a.end() using namespace std; using ll = long long; struct vec { ll x0; ll x1; ll x2; ll x3; }; vec operator+(vec a, vec b) { a.x0 += b.x0; a.x1 += b.x1; a.x2 += b.x2; a.x3 += b.x3; return a; } struct mat { int k; ll x0; }; mat operator*(mat a, mat b) { mat c; if (a.k == 0 && b.k == 0) { c.k = 2; c.x0 = a.x0; } if (a.k == 0 && b.k == 1) { c.k = 0; c.x0 = a.x0; } if (a.k == 0 && b.k == 2) { c.k = 0; c.x0 = a.x0; } if (a.k == 0 && b.k == 3) { c.k = 2; c.x0 = a.x0; } if (a.k == 0 && b.k == 4) { c.k = 2; c.x0 = a.x0; } if (a.k == 0 && b.k == 5) { c.k = 0; c.x0 = a.x0; } if (a.k == 1 && b.k == 0) { c.k = 3; c.x0 = a.x0; } if (a.k == 1 && b.k == 1) { c.k = 1; c.x0 = a.x0; } if (a.k == 1 && b.k == 2) { c.k = 1; c.x0 = a.x0; } if (a.k == 1 && b.k == 3) { c.k = 3; c.x0 = a.x0; } if (a.k == 1 && b.k == 4) { c.k = 3; c.x0 = a.x0; } if (a.k == 1 && b.k == 5) { c.k = 1; c.x0 = a.x0; } if (a.k == 2 && b.k == 0) { c.k = 0; c.x0 = a.x0; } if (a.k == 2 && b.k == 1) { c.k = 2; c.x0 = a.x0; } if (a.k == 2 && b.k == 2) { c.k = 2; c.x0 = a.x0; } if (a.k == 2 && b.k == 3) { c.k = 0; c.x0 = a.x0; } if (a.k == 2 && b.k == 4) { c.k = 0; c.x0 = a.x0; } if (a.k == 2 && b.k == 5) { c.k = 2; c.x0 = a.x0; } if (a.k == 3 && b.k == 0) { c.k = 1; c.x0 = a.x0; } if (a.k == 3 && b.k == 1) { c.k = 3; c.x0 = a.x0; } if (a.k == 3 && b.k == 2) { c.k = 3; c.x0 = a.x0; } if (a.k == 3 && b.k == 3) { c.k = 1; c.x0 = a.x0; } if (a.k == 3 && b.k == 4) { c.k = 1; c.x0 = a.x0; } if (a.k == 3 && b.k == 5) { c.k = 3; c.x0 = a.x0; } if (a.k == 4 && b.k == 0) { c.k = 1; c.x0 = b.x0 + a.x0; } if (a.k == 4 && b.k == 1) { c.k = 0; c.x0 = b.x0 + a.x0; } if (a.k == 4 && b.k == 2) { c.k = 3; c.x0 = b.x0 + a.x0; } if (a.k == 4 && b.k == 3) { c.k = 2; c.x0 = b.x0 + a.x0; } if (a.k == 4 && b.k == 4) { c.k = 5; c.x0 = b.x0 + a.x0; } if (a.k == 4 && b.k == 5) { c.k = 4; c.x0 = b.x0 + a.x0; } if (a.k == 5 && b.k == 0) { c.k = 0; c.x0 = b.x0 + a.x0; } if (a.k == 5 && b.k == 1) { c.k = 1; c.x0 = b.x0 + a.x0; } if (a.k == 5 && b.k == 2) { c.k = 2; c.x0 = b.x0 + a.x0; } if (a.k == 5 && b.k == 3) { c.k = 3; c.x0 = b.x0 + a.x0; } if (a.k == 5 && b.k == 4) { c.k = 4; c.x0 = b.x0 + a.x0; } if (a.k == 5 && b.k == 5) { c.k = 5; c.x0 = b.x0 + a.x0; } return c; } vec operator*(mat a, vec b) { vec c; if (a.k == 0) { c.x0 = b.x2 + a.x0*b.x3; c.x1 = b.x2; c.x2 = b.x1; c.x3 = b.x3; } if (a.k == 1) { c.x0 = b.x2 + a.x0*b.x3; c.x1 = b.x1; c.x2 = b.x2; c.x3 = b.x3; } if (a.k == 2) { c.x0 = b.x1 + a.x0*b.x3; c.x1 = b.x1; c.x2 = b.x2; c.x3 = b.x3; } if (a.k == 3) { c.x0 = b.x1 + a.x0*b.x3; c.x1 = b.x2; c.x2 = b.x1; c.x3 = b.x3; } if (a.k == 4) { c.x0 = b.x0 + a.x0*b.x3; c.x1 = b.x2; c.x2 = b.x1; c.x3 = b.x3; } if (a.k == 5) { c.x0 = b.x0 + a.x0*b.x3; c.x1 = b.x1; c.x2 = b.x2; c.x3 = b.x3; } return c; } mat identity() { mat a; a.k = 5; a.x0 = 0; return a; } mat typeA() { mat a; a.k = 2; a.x0 = 0; return a; } mat typeB(ll x0) { mat a; a.k = 4; a.x0 = x0; return a; } mat typeC(ll x0) { mat a; a.k = 5; a.x0 = x0; return a; } constexpr int U = 1 << 17; vec dat[U * 2]; mat lazy[U * 2]; void apply(int k, mat v) { lazy[k] = v * lazy[k]; dat[k] = v * dat[k]; } void push(int k) { apply(k * 2 + 0, lazy[k]); apply(k * 2 + 1, lazy[k]); lazy[k] = identity(); } void pull(int k) { dat[k] = dat[k * 2] + dat[k * 2 + 1]; } void update(int a, int b, mat v, int k = 1, int l = 0, int r = U) { if (r <= a || b <= l) return; if (a <= l && r <= b) { apply(k, v); return; } push(k); int m = (l + r) / 2; update(a, b, v, k * 2 + 0, l, m); update(a, b, v, k * 2 + 1, m, r); pull(k); } vec query(int a, int b, int k = 1, int l = 0, int r = U) { if (r <= a || b <= l) return vec{}; if (a <= l && r <= b) return dat[k]; push(k); int m = (l + r) / 2; vec vl = query(a, b, k * 2 + 0, l, m); vec vr = query(a, b, k * 2 + 1, m, r); return vl + vr; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int N, Q; cin >> N >> Q; vector<int> A(N); rep(i, U * 2) lazy[i] = identity(); rep(i, N) { cin >> A[i]; dat[i + U].x0 = A[i]; dat[i + U].x1 = A[i] % 2; dat[i + U].x2 = (A[i] + 1) % 2; dat[i + U].x3 = 1; } for (int i = U - 1; i >= 1; i--) pull(i); while (Q--) { int type; cin >> type; if (type == 1) { int l, r; cin >> l >> r; l--; update(l, r, typeA()); } else if (type == 2) { int l, r, x; cin >> l >> r >> x; l--; if (x % 2 == 1) { update(l, r, typeB(x)); } else { update(l, r, typeC(x)); } } else { int l, r; cin >> l >> r; l--; vec ans = query(l, r); cout << ans.x0 << '\n'; } } }