Submission #387456

#TimeUsernameProblemLanguageResultExecution timeMemory
387456nathanlee726Food Court (JOI21_foodcourt)C++14
100 / 100
539 ms51444 KiB
//#include<i_am_noob_orz> #include<bits/stdc++.h> #include <ext/pb_ds/tree_policy.hpp> #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; using namespace std; #define ll long long #define int ll #define ull unsigned long long #define pii pair<int,int> #define X first #define Y second #define mod ((ll)1e9+7) #define pb push_back #define mp make_pair #define abs(x) ((x)>0?(x):(-(x))) #define F(n) Fi(i,n) #define Fi(i,n) Fl(i,0,n) #define Fl(i,l,n) for(int i=l;i<n;i++) #define memres(a) memset(a,0,sizeof(a)) #define all(a) a.begin(),a.end() #define sz(a) ((int)a.size()) #define ceiling(a,b) (((a)+(b)-1)/(b)) #define endl '\n' #define bit_count(x) __builtin_popcountll((x)) #define ykh mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); #define jimmy_is_kind false typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> rbtree; //#define LOCAL #ifdef LOCAL #define bug(...) cerr<<"#"<<__LINE__<<' '<<#__VA_ARGS__<<"- ", _do(__VA_ARGS__) template<typename T> void _do(T && x) {cerr<<x<<endl;} template<typename T, typename ...S> void _do(T && x, S&&...y) {cerr<<x<<", "; _do(y...);} #define IOS() #else #define IOS() ios_base::sync_with_stdio(0), cin.tie(0) #define endl '\n' #define bug(...) #endif int add(int a,int b){return(a+b>=mod?a+b-mod:a+b);} int sub(int a,int b){return(a<b?a+mod-b:a-b);} int po(int a,int b){ if(b==0)return 1; if(b==1)return(a%mod); int tem=po(a,b/2); if(b&1)return(((tem*tem)%mod)*a)%mod; else return(tem*tem)%mod; } int GCD(int a,int b){ int x=0; int ra,rb; while(a&&b){ if(((a&1)==0)&&((b&1)==0)){ a>>=1,b>>=1,x++; } else if((a^b)&1){ if(a&1)b>>=1; else a>>=1; } else{ ra=abs(a-b),rb=min(a,b); a=ra,b=rb; } } return max(a,b)<<x; } int gcd(int a,int b){if(b==0)return a;return gcd(b,a%b);} int n,m,q,balbit[250010],a[250010]; vector<pair<pii,int> > v1,v2; vector<pii> o; void ADD(int x,int v){ for(;x<=250001;x+=(x&(-x)))balbit[x]+=v; } int QRY(int x){ int re=0; for(;x>0;x-=(x&(-x)))re+=balbit[x]; return re; } struct seg_tree1{ struct NODE{ int v; pii tg; NODE():tg({0,0}),v(0){} }seg[1000010]; pii merge(pii p1,pii p2){ if(p1.Y<p2.X){ return {p1.X+p2.X-p1.Y,p2.Y}; } else return {p1.X,p1.Y-p2.X+p2.Y}; } void push(int p){ seg[p*2].tg=merge(seg[p*2].tg,seg[p].tg); seg[p*2].v=max(seg[p].tg.Y,seg[p].tg.Y-seg[p].tg.X+seg[p*2].v); seg[p*2+1].tg=merge(seg[p*2+1].tg,seg[p].tg); seg[p*2+1].v=max(seg[p].tg.Y,seg[p].tg.Y-seg[p].tg.X+seg[p*2+1].v); seg[p].tg={0,0}; } void modify(int p,int l,int r,int ql,int qr,pii vl){ if(l>qr||r<ql)return; if(l>=ql&&r<=qr){ seg[p].v=max(vl.Y,seg[p].v-vl.X+vl.Y); seg[p].tg=merge(seg[p].tg,vl); return; } int mi=(l+r)/2; push(p); modify(p*2,l,mi,ql,qr,vl); modify(p*2+1,mi+1,r,ql,qr,vl); } int qry(int p,int l,int r,int x){ if(l==r){ return seg[p].v; } push(p); int mi=(l+r)/2; if(mi>=x)return qry(p*2,l,mi,x); else return qry(p*2+1,mi+1,r,x); } }sgt; struct seg_tree2{ int seg[1000010]; void add(int p,int l,int r,int x,int vl){ if(l==r){ seg[p]+=vl; return; } int mi=(l+r)/2; if(mi>=x)add(p*2,l,mi,x,vl); else add(p*2+1,mi+1,r,x,vl); seg[p]=seg[p*2]+seg[p*2+1]; } int qry(int vl){ int l=0,r=q-1,p=1,re; bug(vl); while(1){ if(l==r){ if(vl>seg[p])re=-1; else re=l; break; } int mi=(l+r)/2; bug(seg[p*2],vl); if(seg[p*2]>=vl)r=mi,p=p*2; else vl-=seg[p*2],l=mi+1,p=p*2+1; } return re; } }sgt2; signed main(){ IOS(); cin>>n>>m>>q; F(q){ int ty; cin>>ty; if(ty==1){ int l,r,c,k; cin>>l>>r>>c>>k; --l,--r; a[i]=c; v1.pb({{l,k},i}); v1.pb({{r+1,-k},i}); sgt.modify(1,0,n-1,l,r,{0,k}); ADD(l+1,k); ADD(r+2,-k); } else if(ty==2){ int l,r,k; cin>>l>>r>>k; --l,--r; sgt.modify(1,0,n-1,l,r,{k,0}); } else{ int x,y; cin>>x>>y; --x; int tem=sgt.qry(1,0,n-1,x),temm=QRY(x+1); bug(temm,tem,y); if(tem<y)v2.pb({{-1,-1},i}); else v2.pb({{x,temm-tem+y},i}); } } sort(all(v1)); sort(all(v2)); int p=0; for(auto pi:v2){ if(pi.X.X==-1){ o.pb({pi.Y,-1}); continue; } while(p<sz(v1)&&v1[p].X.X<=pi.X.X){ sgt2.add(1,0,q-1,v1[p].Y,v1[p].X.Y); p++; } int re=sgt2.qry(pi.X.Y); if(re>pi.Y)re=-1; bug(re); o.pb({pi.Y,re}); } sort(all(o)); for(pii x:o)cout<<(x.Y==-1?0:a[x.Y])<<endl; return 0; }

Compilation message (stderr)

foodcourt.cpp: In constructor 'seg_tree1::NODE::NODE()':
foodcourt.cpp:84:7: warning: 'seg_tree1::NODE::tg' will be initialized after [-Wreorder]
   84 |   pii tg;
      |       ^~
foodcourt.cpp:83:7: warning:   'long long int seg_tree1::NODE::v' [-Wreorder]
   83 |   int v;
      |       ^
foodcourt.cpp:85:3: warning:   when initialized here [-Wreorder]
   85 |   NODE():tg({0,0}),v(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...