結果
問題 |
No.3265 地元に帰れば天才扱い!
|
ユーザー |
![]() |
提出日時 | 2025-08-18 01:26:42 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 1,059 ms / 2,500 ms |
コード長 | 1,222 bytes |
コンパイル時間 | 4,109 ms |
コンパイル使用メモリ | 177,460 KB |
実行使用メモリ | 15,212 KB |
最終ジャッジ日時 | 2025-09-06 12:32:58 |
合計ジャッジ時間 | 28,776 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 21 |
ソースコード
#include <iostream> #include <algorithm> #include <atcoder/all> using namespace std; using namespace atcoder; using ll = long long; //#define endl "\n"; ll N, M, Q, A[200009], L[200009], R[200009], pos[200009]; using S = ll; S op(S a, S b) { return a+b; } S e() { return 0LL; } int main(){ cin >> N >> M; ll ans = 0; segtree<S, op, e> seg(M + 1); fenwick_tree<ll> fw(M + 1); for(int i = 0; i < N; i++){ cin >> A[i] >> L[i] >> R[i]; L[i]--; ans += (R[i] - L[i]) * A[i]; pos[i] = i; seg.set(i, A[i]); fw.add(L[i], 1); fw.add(R[i], -1); } for(int i = 0; i < N; i++) ans -= seg.prod(L[i], R[i]); cin >> Q; for(int i = 1; i <= Q; i++){ ll x, y, l, r; cin >> x >> y >> l >> r; x--, y--, l--; ans -= (R[x] - L[x]) * A[x]; ll deg = fw.sum(0, pos[x] + 1); ans += A[x] * deg; fw.add(L[x], -1); fw.add(R[x], 1); seg.set(pos[x], 0); ans += seg.prod(L[x], R[x]); pos[x] = y; L[x] = l, R[x] = r; ans += (R[x] - L[x]) * A[x]; deg = fw.sum(0, pos[x] + 1); ans -= A[x] * deg; seg.set(pos[x], A[x]); fw.add(L[x], 1); fw.add(R[x], -1); ans -= seg.prod(L[x], R[x]); cout << ans << endl; } return 0; }