結果

問題 No.3265 地元に帰れば天才扱い!
ユーザー umimel
提出日時 2025-09-06 14:04:09
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 924 ms / 2,500 ms
コード長 2,126 bytes
コンパイル時間 4,235 ms
コンパイル使用メモリ 227,748 KB
実行使用メモリ 26,236 KB
最終ジャッジ日時 2025-09-06 14:04:49
合計ジャッジ時間 27,658 ms
ジャッジサーバーID
(参考情報)
judge / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define fi first
#define se second
mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());
const ll MOD1000000007 = 1000000007;
const ll MOD998244353 = 998244353;
const ll MOD[3] = {999727999, 1070777777, 1000000007};
const ll LINF = 1LL << 60LL;
const int IINF = (1 << 30) - 1;

#include <atcoder/all>
using namespace atcoder;

struct S{
    long long value;
    int size;
};
using F = long long;

S op(S a, S b){ return {a.value+b.value, a.size+b.size}; }
S e(){ return {0, 0}; }
S mapping(F f, S x){ return {x.value + f*x.size, x.size}; }
F composition(F f, F g){ return f+g; }
F id(){ return 0; }

ll op2(ll a, ll b){
    return a+b;
}

ll e2(){
    return 0LL;
}

void solve(){
    int N, M; cin >> N >> M;
    vector<ll> A(N);
    vector<int> L(N), R(N);
    vector<int> H(N);
    for(int i=0; i<N; i++){
        cin >> A[i] >> L[i] >> R[i];
        L[i]--; R[i]--;
        H[i] = i;
    }

    vector<S> v(M, {0, 1});
    lazy_segtree<S, op, e, F, mapping, composition, id> cnt(v);
    for(int i=0; i<N; i++) cnt.apply(L[i], R[i]+1, 1);
    segtree<ll, op2, e2> seg(M);
    for(int i=0; i<N; i++) seg.set(i, A[i]);

    ll ans = 0LL;
    for(int i=0; i<N; i++) ans += (ll)(R[i]-L[i]+1)*A[i] - seg.prod(L[i], R[i]+1);

    int Q; cin >> Q;
    while(Q--){
        int X, Y, U, V; cin >> X >> Y >> U >> V;
        X--; Y--; U--; V--;
        
        // erase X
        ans -= (ll)(R[X]-L[X]+1)*A[X] - seg.prod(L[X], R[X]+1);
        cnt.apply(L[X], R[X]+1, -1);
        ans += A[X]*cnt.prod(H[X], H[X]+1).value;
        seg.set(H[X], 0);

        // remove home Y
        H[X] = Y;
        L[X] = U, R[X] = V;
        seg.set(Y, A[X]);
        ans += (ll)(R[X]-L[X]+1)*A[X] - seg.prod(L[X], R[X]+1);
        ans -= A[X]*cnt.prod(H[X], H[X]+1).value;
        cnt.apply(L[X], R[X]+1, 1);

        cout << ans << "\n";
    }
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int T=1;
    //cin >> T;
    while(T--) solve();
}
0