Submission #401602

#TimeUsernameProblemLanguageResultExecution timeMemory
401602Jarif_RahmanFood Court (JOI21_foodcourt)C++17
21 / 100
678 ms31488 KiB
#include <bits/stdc++.h> #define pb push_back #define f first #define sc second using namespace std; typedef long long int ll; typedef string str; const ll inf = 1e16+1; struct segtree_beats{ struct node{ ll mn[2], cnt[2]; ll sm, lazy_add; node(){ mn[0] = 0, mn[1] = inf; cnt[0] = 1, cnt[1] = 0; sm = 0; lazy_add = 0; } node operator+(node a){ node rt; if(mn[0] < a.mn[0]){ rt.mn[0] = mn[0], rt.cnt[0] = cnt[0]; if(mn[1] < a.mn[0]) rt.mn[1] = mn[1], rt.cnt[1] = cnt[1]; else if(mn[1] > a.mn[0]) rt.mn[1] = a.mn[0], rt.cnt[1] = a.cnt[0]; else rt.mn[1] = mn[1], rt.cnt[1] = cnt[1]+a.cnt[0]; } else if(mn[0] > a.mn[0]){ rt.mn[0] = a.mn[0], rt.cnt[0] = a.cnt[0]; if(mn[0] < a.mn[1]) rt.mn[1] = mn[0], rt.cnt[1] = cnt[0]; else if(mn[0] > a.mn[1]) rt.mn[1] = a.mn[1], rt.cnt[1] = a.cnt[1]; else rt.mn[1] = mn[0], rt.cnt[1] = cnt[0]+a.cnt[1]; } else{ rt.mn[0] = mn[0], rt.cnt[0] = cnt[0]+a.cnt[0]; if(mn[1] < a.mn[1]) rt.mn[1] = mn[1], rt.cnt[1] = cnt[1]; else if(mn[1] > a.mn[1]) rt.mn[1] = a.mn[1], rt.cnt[1] = a.cnt[1]; else rt.mn[1] = mn[1], rt.cnt[1] = cnt[1]+a.cnt[1]; } rt.sm = sm+a.sm; return rt; } void propagate(node nd, int sz){ lazy_add+=nd.lazy_add; sm+=nd.lazy_add*sz; mn[0]+=nd.lazy_add; if(mn[1] != inf) mn[1]+=nd.lazy_add; if(nd.mn[0] <= mn[0]) return; sm+=(nd.mn[0]-mn[0])*sz; mn[0] = nd.mn[0]; } }; int k; vector<node> v; segtree_beats(int n){ k = 1; while(k < n) k*=2; k*=2; v.resize(k, node()); for(int i = k/2-1; i > 0; i--) v[i] = v[2*i]+v[2*i+1]; } void add(int l, int r, int nd, int a, int b, ll x){ if(a > r || b < l){ return; } if(a >= l && b <= r){ node nd0; nd0.lazy_add = x; nd0.mn[0] = -inf+1; v[nd].propagate(nd0, b-a+1); return; } int md = (a+b)/2; v[2*nd].propagate(v[nd], md-a+1); v[2*nd+1].propagate(v[nd], b-md); v[nd].lazy_add = 0; add(l, r, 2*nd, a, md, x); add(l, r, 2*nd+1, md+1, b, x); v[nd] = v[2*nd]+v[2*nd+1]; } void add(int l, int r, ll x){ add(l, r, 1, 0, k/2-1, x); } void chmx(int l, int r, int nd, int a, int b, ll x){ if(a > r || b < l || v[nd].mn[0] >= x){ return; } if(a >= l && b <= r && v[nd].mn[1] > x){ node nd0; nd0.mn[0] = x; v[nd].propagate(nd0, b-a+1); return; } int md = (a+b)/2; v[2*nd].propagate(v[nd], md-a+1); v[2*nd+1].propagate(v[nd], b-md); v[nd].lazy_add = 0; chmx(l, r, 2*nd, a, md, x); chmx(l, r, 2*nd+1, md+1, b, x); v[nd] = v[2*nd]+v[2*nd+1]; } void chmx(int l, int r, ll x){ chmx(l, r, 1, 0, k/2-1, x); } ll sum(int l, int r, int nd, int a, int b){ if(a > r || b < l){ return 0; } if(a >= l && b <= r){ return v[nd].sm; } int md = (a+b)/2; v[2*nd].propagate(v[nd], md-a+1); v[2*nd+1].propagate(v[nd], b-md); v[nd].lazy_add = 0; ll rt = sum(l, r, 2*nd, a, md) + sum(l, r, 2*nd+1, md+1, b); v[nd] = v[2*nd]+v[2*nd+1]; return rt; } ll sum(int l, int r){ return sum(l, r, 1, 0, k/2-1); } }; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int n, m, q; cin >> n >> m >> q; segtree_beats beats(n); while(q--){ int tt; cin >> tt; if(tt == 1){ int l, r, c; ll k; cin >> l >> r >> c >> k; l--, r--; beats.add(l, r, k); } else if(tt == 2){ int l, r; ll k; cin >> l >> r >> k; l--, r--; beats.add(l, r, -k); beats.chmx(l, r, 0LL); } else{ int a; ll b; cin >> a >> b; a--; cout << (beats.sum(a, a) >= b ? 1:0) << "\n"; } } }
#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...