結果
| 問題 |
No.876 Range Compress Query
|
| コンテスト | |
| ユーザー |
Tatsu_mr
|
| 提出日時 | 2024-06-12 11:52:11 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 312 ms / 2,000 ms |
| コード長 | 1,220 bytes |
| コンパイル時間 | 4,466 ms |
| コンパイル使用メモリ | 256,832 KB |
| 最終ジャッジ日時 | 2025-02-21 21:14:36 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 18 |
ソースコード
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using lint = long long;
struct S {
lint left, sum, right;
};
S op(S a, S b) {
S res;
if (a.left == 0) {
res = b;
} else if (b.right == 0) {
res = a;
res.sum++;
} else {
res.left = a.left;
res.sum = (a.right == b.left ? a.sum + b.sum : a.sum + b.sum + 1);
res.right = b.right;
}
return res;
}
S e() {
return {0LL, 0LL, 0LL};
}
S mapping(lint x, S s) {
return {s.left + x, s.sum, s.right + x};
}
lint composition(lint f, lint g) {
return f + g;
}
lint id() {
return 0LL;
}
int main() {
int n, q;
cin >> n >> q;
vector<lint> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
lazy_segtree<S, op, e, lint, mapping, composition, id> seg(n);
for (int i = 0; i < n; i++) {
seg.set(i, {a[i], 0LL, a[i]});
}
while (q--) {
int t, l, r;
cin >> t >> l >> r;
l--;
r--;
if (t == 1) {
lint x;
cin >> x;
seg.apply(l, r + 1, x);
} else {
cout << seg.prod(l, r + 1).sum << endl;
}
}
}
Tatsu_mr