Submission #952989

#TimeUsernameProblemLanguageResultExecution timeMemory
952989WonderfulWhaleFood Court (JOI21_foodcourt)C++17
14 / 100
1071 ms26576 KiB
#include<bits/stdc++.h> using namespace std; #define int int64_t #define pb push_back #define pii pair<int, int> #define st first #define nd second #define sz(x) (int)(x).size() #define all(x) (x).begin(), (x).end() const int INF = 1e18; const int MAXN = 250'009; struct SegTree { const static int T = 1<<18; int t[2*T]; void update(int l, int r, int val) { l+=T, r+=T; t[l]+=val; if(l!=r) t[r]+=val; if(l/2!=r/2) { if(l%2==0) t[l+1]+=val; if(r%2==1) t[r-1]+=val; l/=2; r/=2; } } int query(int x) { x+=T; int ret = 0; while(x){ ret += t[x]; x/=2; } return ret; } } seg, SEG; struct SegTree2 { const static int T = 1<<18; pii t[2*T]; int lz[2*T]; SegTree2() { for(int i=T;i<2*T;i++) { t[i] = {1e18, i-T}; } for(int i=T-1;i;i--) { t[i] = min(t[2*i], t[2*i+1]); } } void push(int v) { int l = 2*v, r = 2*v+1; t[l].st += lz[v]; t[r].st += lz[v]; lz[l] += lz[v]; lz[r] += lz[v]; lz[v] = 0; } void update(int l, int r, int val, int tl=0, int tr=T-1, int v=1) { // if(v==1) cerr << "update: " << l << " " << r << " " << val << "\n"; if(l>r) return; if(l==tl&&r==tr) { t[v].st += val; lz[v] += val; return; } push(v); int tm = (tl+tr)/2; update(l, min(r, tm), val, tl, tm, 2*v); update(max(tm+1, l), r, val, tm+1, tr, 2*v+1); t[v] = min(t[2*v], t[2*v+1]); } pii query(int l, int r, int tl=0, int tr=T-1, int v=1) { if(l>r) return make_pair(1e18, -1); if(l==tl&&r==tr) { return t[v]; } push(v); int tm = (tl+tr)/2; return min(query(l, min(r, tm), tl, tm, 2*v), query(max(tm+1, l), r, tm+1, tr, 2*v+1)); } } seg2; vector<tuple<int, int, int, int>> Q; int tab[MAXN]; int lim[MAXN]; pii info[MAXN]; int ans[MAXN]; int tmp[MAXN]; int del[MAXN]; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); vector<pii> zap; int n, m, q; cin >> n >> m >> q; int cnt = 0; int cnt3 = 0; for(int i=0;i<q;i++) { int type; cin >> type; if(type==1) { int l, r, c, k; cin >> l >> r >> k >> c; tab[cnt] = k; Q.pb({l, r, c, k}); cnt++; for(int i=l;i<=r;i++) { tmp[i] += c; } } if(type==2) { int l, r, c; cin >> l >> r >> c; seg.update(l, r, c); for(int i=l;i<=r;i++) { int val = min(c, tmp[i]); tmp[i] -= val; del[i] += val; } } if(type==3) { int a, b; cin >> a >> b; // cerr << "query: " << a << " " << b << "\n"; // b += seg.query(a); b += del[a]; // cerr << "we need: " << b << "\n"; // cerr << "we can process: " << cnt << "\n"; info[cnt3] = {cnt, b}; zap.pb({a, cnt3++}); } } sort(all(zap)); for(int i=0;i<cnt3;i++) { int num = zap[i].nd; // cerr << "hm: " << info[num].nd << "\n"; seg2.update(i, i, -INF+info[num].nd); pii X = seg2.query(i, i); // cerr << "just a quick check: " << X.st << " " << X.nd << "\n"; } for(int i=0;i<cnt;i++) { auto [l, r, C, k] = Q[i]; // cerr << "Now adding: " << l << " " << r << " " << C << " " << k << "\n"; int s = -1; int e = cnt3; while(e-s>1) { int m = (e+s)/2; if(zap[m].st>=l) e = m; else s = m; } int S = e; s = -1, e = cnt3; while(e-s>1) { int m = (e+s)/2; if(zap[m].st<=r) s = m; else e = m; } int E = s; // cerr << "we will affect queries: "<< S << " " << E << "\n"; seg2.update(S, E, -C); while(true) { pii x = seg2.query(0, cnt3-1); if(x.st>0) break; // cerr << "found: " << x.nd << " with new val: " << x.st << "\n"; if(i<info[zap[x.nd].nd].st) ans[zap[x.nd].nd] = tab[i]; seg2.update(x.nd, x.nd, 1e18); } } for(int i=0;i<cnt3;i++) { cout << ans[i] << "\n"; } }

Compilation message (stderr)

foodcourt.cpp: In function 'int32_t main()':
foodcourt.cpp:146:7: warning: variable 'X' set but not used [-Wunused-but-set-variable]
  146 |   pii X = seg2.query(i, i);
      |       ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...