Submission #844796

#TimeUsernameProblemLanguageResultExecution timeMemory
844796CookieFood Court (JOI21_foodcourt)C++14
2 / 100
88 ms35160 KiB
#include<bits/stdc++.h> #define ll long long #define vt vector #define pb push_back #define sz(v) (int)v.size() #define pii pair<int, int> using namespace std; const ll base = 107, mod = 1e9 + 7; const int mxn = 250000 + 5, inf = 1e9, sq = 400; struct th{ int type, val, colour, id; }; struct Node{ int sm, suf, idsuf; }; int n, m, q; vt<th>events[mxn + 1]; vt<pii>ask[mxn + 1]; int ans[mxn + 1]; Node st[4 * mxn + 1]; int mn[4 * mxn + 1], lz[4 * mxn + 1], co[mxn + 1]; void pull(int nd){ st[nd].sm = st[nd << 1].sm + st[nd << 1 | 1].sm; ll cand1 = st[nd << 1 | 1].suf, cand2 = st[nd << 1 | 1].sm + st[nd << 1].suf; if(cand1 > cand2){ st[nd].suf = cand1; st[nd].idsuf = st[nd << 1 | 1].idsuf; }else{ st[nd].suf = cand2; st[nd].idsuf = st[nd << 1].idsuf; } mn[nd] = min(mn[nd << 1], mn[nd << 1 | 1]); return; } Node comb(Node a, Node b){ Node res; res.sm = a.sm + b.sm; ll cand1 = b.suf, cand2 = b.sm + a.suf; if(cand1 > cand2){ res.suf = cand1; res.idsuf = b.idsuf; }else{ res.suf = cand2; res.idsuf = a.idsuf; } return(res); } void push(int nd){ int &v = lz[nd]; lz[nd << 1] += v; lz[nd << 1 | 1] += v; mn[nd << 1] += v; mn[nd << 1 | 1] += v; v = 0; } void upd(int nd, int l, int r, int id, int v){ if(id < l || id > r)return; if(l == r){ st[nd].sm += v; if(st[nd].sm >= 0){ st[nd].suf = st[nd].sm; st[nd].idsuf = l; }else{ st[nd].suf = 0; st[nd].idsuf = l + 1; } return; } push(nd); int mid = (l + r) >> 1; upd(nd << 1, l, mid, id, v); upd(nd << 1 | 1, mid + 1, r, id, v); pull(nd); } void upd2(int nd, int l, int r, int ql, int qr, int v){ if(ql > r || qr < l)return; if(ql <= l && qr >= r){ mn[nd] += v; lz[nd] += v; return; } push(nd); int mid = (l + r) >> 1; upd2(nd << 1, l, mid, ql, qr, v); upd2(nd << 1 | 1, mid + 1, r, ql, qr, v); mn[nd] = min(mn[nd << 1], mn[nd << 1 | 1]); } Node get(int nd, int l, int r, int ql, int qr){ if(ql <= l && qr >= r)return(st[nd]); int mid = (l + r) >> 1; push(nd); if(qr <= mid)return(get(nd << 1, l, mid, ql, qr)); else if(ql > mid)return(get(nd << 1 | 1, mid + 1,r, ql, qr)); else return(comb(get(nd << 1, l, mid, ql, qr), get(nd << 1 | 1, mid + 1, r, ql, qr))); } struct BIT{ ll bit[mxn + 1]; void upd(int p, ll v){ while(p <= q){ bit[p] += v; p += p & (-p); } } ll get(int p){ ll ans = 0; while(p){ ans += bit[p]; p -= p & (-p); } return(ans); } ll query(int l, int r){ if(l > r)return(0); return(get(r) - get(l - 1)); } int kth(ll x){ ll sm = 0, id = 0; for(int i = 18; i >= 0; i--){ if(id + (1 << i) <= q && sm + bit[id + (1 << i)] < x){ id += (1 << i); sm += bit[id]; } } return(id + 1); } }; BIT one, two; int getp(int nd, int l, int r, int id){ if(id == 0)return(0); if(l == r)return(mn[nd]); int mid = (l + r) >> 1; push(nd); if(id <= mid)return(getp(nd << 1, l, mid, id)); return(getp(nd << 1 | 1, mid + 1, r, id)); } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m >> q; set<int>active; for(int i = 1; i <= q; i++){ upd(1, 1, q, i, 0); } for(int i = 1; i <= q; i++){ int idq; cin >> idq; if(idq == 1){ int l, r, x, k; cin >> l >> r >> k >> x; events[l].pb({1, x, k, i}); events[r + 1].pb({1, -x, k, i}); co[i] = k; }else if(idq == 2){ int l, r, k; cin >> l >> r >> k; events[l].pb({2, k, -1, i}); events[r + 1].pb({2, -k, -1, i}); }else{ int id, x; cin >> id >> x; ask[id].pb({x, i}); } } for(int i = 1; i <= n; i++){ for(auto [type, val, colour, id]: events[i]){ if(type == 1){ upd(1, 1, q, id, val); one.upd(id, val); }else{ upd(1, 1, q, id, -val); //upd2(1, 1, q, id, q, -val); two.upd(id, -val); } } for(auto [x, idq]: ask[i]){ Node cool = get(1, 1, q, 1, idq); if(cool.suf < x){ ans[idq] = -1; }else{ int idd = cool.idsuf; ll needid = -two.query(idd, idq) + x + one.query(1, idd - 1); ll idres = one.kth(needid); ans[idq] = co[idres]; } } } for(int i = 1; i <= q; i++){ if(ans[i]){ if(ans[i] == -1)cout << 0 << "\n"; else cout << ans[i] << "\n"; } } }

Compilation message (stderr)

foodcourt.cpp: In function 'int main()':
foodcourt.cpp:143:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  143 |         for(auto [type, val, colour, id]: events[i]){
      |                  ^
foodcourt.cpp:154:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  154 |         for(auto [x, idq]: ask[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...