Submission #722436

#TimeUsernameProblemLanguageResultExecution timeMemory
722436Abrar_Al_SamitFood Court (JOI21_foodcourt)C++17
14 / 100
1089 ms411004 KiB
#include<bits/stdc++.h> using namespace std; const int nax = 65003; int n, m, q; vector<pair<long long, int>>lines[nax]; struct BIT { long long bit[nax]; void update(int i, long long val) { while(i<nax) { bit[i] += val; i += i&-i; } } void update(int l, int r, long long val) { update(l, val); update(r+1, -val); } long long query(int i) { long long ret = 0; while(i>0) { ret += bit[i]; i -= i&-i; } return ret; } } T; long long fix(int i) { long long rem = T.query(i); if(lines[i].back().first<rem) { T.update(i, i, lines[i].back().first-rem); rem = lines[i].back().first; } return rem; } void PlayGround() { cin>>n>>m>>q; for(int i=1; i<=n; ++i) { lines[i].emplace_back(0LL, 0); } while(q--) { int tp; cin>>tp; if(tp==1) { long long l, r, c, k; cin>>l>>r>>c>>k; for(int i=l; i<=r; ++i) { fix(i); lines[i].emplace_back(lines[i].back().first+k, c); } } else if(tp==2) { long long l, r, k; cin>>l>>r>>k; T.update(l, r, k); } else { long long a, b; cin>>a>>b; long long rem = fix(a); b += rem; if(b > lines[a].back().first) { cout<<"0\n"; } else { auto it = lower_bound(lines[a].begin(), lines[a].end(), make_pair(b, -1)); cout<<it->second<<'\n'; } } } // cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); PlayGround(); return 0; }
#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...