結果
| 問題 |
No.1000 Point Add and Array Add
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-04-02 18:21:11 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 405 ms / 2,000 ms |
| コード長 | 914 bytes |
| コンパイル時間 | 2,971 ms |
| コンパイル使用メモリ | 203,392 KB |
| 最終ジャッジ日時 | 2025-02-20 19:41:07 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 22 |
ソースコード
#include <bits/stdc++.h>
#include <atcoder/lazysegtree>
using namespace std;
using namespace atcoder;
using ll = long long;
struct S{
ll sum;
ll size;
};
S op(S a, S b) {
return {a.sum+b.sum, a.size+b.size};
}
S e() {return {0, 0};}
S mapping(ll f, S x) {return {x.sum + f, x.size};}
ll composition(ll f, ll g) {return f + g;}
ll id() {return 0;}
int main() {
int N, Q;cin >> N >> Q;
vector<ll> A(N + 1, 0);
for (int i = 1;i <= N;i++) cin >> A[i];
vector<S> B(N + 1, {0, 1});
lazy_segtree<S, op, e, ll, mapping, composition, id> seg(B);
vector<ll> ans(N + 1, 0);
while (Q--) {
char c;cin >> c;
if (c == 'A') {
int x;ll y;cin >> x >> y;
ans[x] += A[x] * seg.get(x).sum;
seg.set(x, {0, 1});
A[x] += y;
} else {
int x, y;cin >> x >> y;
seg.apply(x, y + 1, 1);
}
}
for (int i = 1;i <= N;i++) {
ans[i] += seg.get(i).sum * A[i];
cout << ans[i]<< " ";
}
cout << endl;
}