結果
問題 |
No.3265 地元に帰れば天才扱い!
|
ユーザー |
![]() |
提出日時 | 2025-09-06 14:27:59 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 895 ms / 2,500 ms |
コード長 | 1,899 bytes |
コンパイル時間 | 5,277 ms |
コンパイル使用メモリ | 262,712 KB |
実行使用メモリ | 23,812 KB |
最終ジャッジ日時 | 2025-09-06 14:28:28 |
合計ジャッジ時間 | 26,813 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 21 |
ソースコード
#include <bits/stdc++.h> #include <atcoder/all> using namespace std; using isize = size_t; using i32 = int; using u32 = unsigned int; using i64 = long long; using u64 = unsigned long long; using i128 = __int128_t; using u128 = __uint128_t; using f64 = long double; using p2 = pair<i64, i64>; using el = tuple<i64, i64, i64>; using mint = atcoder::modint998244353; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(18); _main(); } i64 pow(i64 x, i64 n) { i64 res = 1; i64 t = x; while (n > 0) { if (n & 1) res *= t; t *= t; n >>= 1; } return res; } i64 op(i64 a, i64 b) {return a + b;} i64 e() {return 0;} p2 ops(p2 a, p2 b) {return {a.first + b.first, a.second + b.second};} p2 es() {return {0, 0};} p2 mpn(i64 f, p2 x) {return {x.first + f * x.second, x.second};} i64 cmp(i64 f, i64 g) {return f + g;} i64 idn() {return 0;} void _main() { i64 n, m; cin >> n >> m; atcoder::segtree<i64, op, e> segs(m); atcoder::lazy_segtree<p2, ops, es, i64, mpn, cmp, idn> segc(m); vector<el> alr(n); vector<i64> p(n); i64 ans = 0; for (i64 i = 0; i < m; i++) segc.set(i, {0, 1}); for (i64 i = 0; i < n; i++) { i64 a, l, r; cin >> a >> l >> r; l--; alr[i] = {a, l, r}; p[i] = i; segs.set(i, a); segc.apply(l, r, 1); ans += (r - l) * a; } for (i64 i = 0; i < m; i++) ans -= segc.get(i).first * segs.get(i); i64 q; cin >> q; for (;q--;) { i64 x, y, u, v; cin >> x >> y >> u >> v; x--, y--, u--; auto [a, l, r] = alr[x]; ans += a * segc.get(p[x]).first; ans -= a * segc.get(y).first; segs.set(p[x], 0); segs.set(y, a); p[x] = y; ans += segs.prod(l, r); ans -= (r - l) * a; segc.apply(l, r, -1); ans -= segs.prod(u, v); ans += (v - u) * a; segc.apply(u, v, 1); alr[x] = {a, u, v}; cout << ans << "\n"; } }