結果

問題 No.3265 地元に帰れば天才扱い!
ユーザー kk0414
提出日時 2025-09-14 20:49:37
言語 C++17(clang)
(17.0.6 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 3,522 bytes
コンパイル時間 4,547 ms
コンパイル使用メモリ 189,396 KB
実行使用メモリ 10,752 KB
最終ジャッジ日時 2025-09-14 20:49:55
合計ジャッジ時間 17,428 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 3 RE * 1
other RE * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

#ifndef HIDDEN_IN_VS // 折りたたみ用

#include <bits/stdc++.h>

using namespace std;
// 型名の短縮
using ll = long long; using ull = unsigned long long; // -2^63 ~ 2^63 = 9 * 10^18(int は -2^31 ~ 2^31 = 2 * 10^9)
using pii = pair<int, int>;	using pll = pair<ll, ll>;	using pil = pair<int, ll>;	using pli = pair<ll, int>;
using vi = vector<int>;		using vvi = vector<vi>;		using vvvi = vector<vvi>;	using vvvvi = vector<vvvi>;
using vl = vector<ll>;		using vvl = vector<vl>;		using vvvl = vector<vvl>;	using vvvvl = vector<vvvl>;
using vb = vector<bool>;	using vvb = vector<vb>;		using vvvb = vector<vvb>;
using vc = vector<char>;	using vvc = vector<vc>;		using vvvc = vector<vvc>;
using vd = vector<double>;	using vvd = vector<vd>;		using vvvd = vector<vvd>;

template <class T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
template <typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template <typename T> bool chmin(T &m, const T q) { if (m > q) {m = q; return true;} else return false; }

#define all(a) a.begin(),a.end()
#define rep(i, n) for(int i = 0, i##_end = int(n); i < i##_end; ++i) // 0 から n-1 まで昇順
#define repi(i, s, t) for(int i = int(s), i##_end = int(t); i <= i##_end; ++i) // s から t まで昇順
#define repir(i, s, t) for(int i = int(s), i##_end = int(t); i >= i##_end; --i) // s から t まで降順
#define repe(v, a) for(const auto& v : (a)) // a の全要素(変更不可能)
#define repea(v, a) for(auto& v : (a)) // a の全要素(変更可能)
#define repb(set, d) for(int set = 0; set < (1 << int(d)); ++set) // d ビット全探索(昇順)
#define repp(a) sort(all(a)); for(bool a##_perm = true; a##_perm; a##_perm = next_permutation(all(a))) // a の順列全て(昇順)
#define smod(n, m) ((((n) % (m)) + (m)) % (m)) // 非負mod
#define uniq(a) {sort(all(a)); (a).erase(unique(all(a)), (a).end());} // 重複除去
// template <class T> inline T smod(T n, T m) { n %= m; if (n < 0) n += m; return n; } // 非負mod

long long TEN(int x) { return x == 0 ? 1 : TEN(x - 1) * 10; }


#endif

#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;


#if local_mode
#include "local.hpp"
#else
#define dump(...)
#define dumpel(v)
#endif

struct fast_io { fast_io() { cin.tie(nullptr); ios::sync_with_stdio(false); } } fastIOtmp;


int main() {
    int n,m;
    cin >> n >> m;
    // fenwick_tree<int> ft(m);
    vl V(n);
    vi P(m,-1);
    vl L(n);
    fenwick_tree<int> lc(m+1);
    vl R(n);
    fenwick_tree<int> rc(m+1);
    rep(i,n){
        cin >> V[i] >> L[i] >> R[i];
        P[i]=i;
        L[i]--;
        lc.add(L[i],1);
        rc.add(R[i],1);
        // ft.add(i,1);
    }
    ll sum =0;

    rep(i,n){
        sum += (R[i]-L[i])*V[i];
        int v = min(lc.sum(0,P[i]+1),rc.sum(P[i],m));
        sum -= v*V[i];
        // sum -= (ft.sum(L[i],R[i])-1)
    }

    int Q;
    cin >> Q;
    rep(_,Q){
        int x,y,u,v;
        cin >> x >> y >> u >> v;
        x--;y--;u--;
        sum-= (R[P[x]]-L[P[x]])*V[P[x]];
        int vx = min(lc.sum(0,P[x]+1),rc.sum(P[x],m));
        sum+= vx*V[P[x]];
        lc.add(L[P[x]],-1);
        rc.add(R[P[x]],-1);
        P[y] = P[x];
        P[x]=-1;
        L[P[y]]=u;
        R[P[y]]=v;
        
        lc.add(u,1);
        rc.add(v,1);
        sum+= (R[P[y]]-L[P[y]])*V[P[y]];
        vx = min(lc.sum(0,P[y]+1),rc.sum(P[y],m));
        sum-= vx*V[P[y]];
        cout << sum << "\n";
    }
    
}
   
0