結果
問題 | No.876 Range Compress Query |
ユーザー | Tatsu_mr |
提出日時 | 2024-06-12 23:29:56 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 1,328 bytes |
コンパイル時間 | 5,235 ms |
コンパイル使用メモリ | 264,344 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-06-12 23:30:06 |
合計ジャッジ時間 | 8,263 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | RE | - |
testcase_02 | AC | 2 ms
6,944 KB |
testcase_03 | RE | - |
testcase_04 | AC | 3 ms
6,940 KB |
testcase_05 | AC | 3 ms
6,940 KB |
testcase_06 | RE | - |
testcase_07 | RE | - |
testcase_08 | AC | 4 ms
6,944 KB |
testcase_09 | RE | - |
testcase_10 | RE | - |
testcase_11 | AC | 200 ms
6,944 KB |
testcase_12 | RE | - |
testcase_13 | AC | 169 ms
6,940 KB |
testcase_14 | RE | - |
testcase_15 | AC | 153 ms
6,944 KB |
testcase_16 | RE | - |
testcase_17 | RE | - |
testcase_18 | RE | - |
ソースコード
#include <bits/stdc++.h> #include <atcoder/all> using namespace std; using namespace atcoder; int main() { int n, q; cin >> n >> q; vector<long long> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } fenwick_tree<long long> same(n), val(n + 1); for (int i = 0; i < n - 1; i++) { if (a[i] == a[i + 1]) { same.add(i, 1); } } for (int i = 0; i < n; i++) { val.add(i, a[i]); val.add(i + 1, -a[i]); } while (q--) { int t, l, r; cin >> t >> l >> r; l--; r--; if (t == 1) { long long x; cin >> x; val.add(l, x); val.add(r + 1, -x); long long LL = val.sum(l - 1, l), L = val.sum(l, l + 1), R = val.sum(r, r + 1), RR = val.sum(r + 1, r + 2); if (LL == L) { same.add(l - 1, 1); } if (same.sum(l - 1, l) == 1 && LL != L) { same.add(l - 1, -1); } if (R == RR) { same.add(r, 1); } if (same.sum(r, r + 1) == 1 && R != RR) { same.add(r, -1); } } else { long long ans = r - l + 1; ans -= same.sum(l, r); cout << ans << endl; } } }