結果
問題 | No.876 Range Compress Query |
ユーザー |
![]() |
提出日時 | 2024-06-13 00:01:58 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 230 ms / 2,000 ms |
コード長 | 1,474 bytes |
コンパイル時間 | 4,341 ms |
コンパイル使用メモリ | 252,888 KB |
最終ジャッジ日時 | 2025-02-21 21:25:51 |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 18 |
ソースコード
#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);if (l > 0) {long long x = val.sum(0, l), y = val.sum(0, l + 1);if (x == y) {same.add(l - 1, 1);}if (same.sum(l - 1, l) == 1 && x != y) {same.add(l - 1, -1);}}if (r < n - 1) {long long x = val.sum(0, r + 1), y = val.sum(0, r + 2);if (x == y) {same.add(r, 1);}if (same.sum(r, r + 1) == 1 && x != y) {same.add(r, -1);}}} else {long long ans = r - l + 1;ans -= same.sum(l, r);cout << ans << endl;}}}