Submission #955358

#TimeUsernameProblemLanguageResultExecution timeMemory
955358vjudge1Food Court (JOI21_foodcourt)C++17
20 / 100
1033 ms145588 KiB
#include <bits/stdc++.h> #pragma optimize("Ofast") #pragma target("avx2") using namespace std; #define ll long long #define ld long double #define pb push_back #define pf push_front #define pii pair<int,int> #define all(v) v.begin(),v.end() #define F first #define S second #define mem(a,i) memset(a,i,sizeof(a)) #define sz(s) (int)s.size() #define y1 yy #define ppb pop_back #define lb lower_bound #define ub upper_bound #define gcd(a,b) __gcd(a,b) #define in insert #define int ll const int MAX=3e5+15; const int B=300; const int N=104; const int block=400; const int maxB=MAX/B+10; const ll inf=1e18; const int mod=998244353; const int mod1=1e9+9; const ld eps=1e-9; int dx[8]={1,0,-1,0,1,-1,-1,1}; int dy[8]={0,1,0,-1,1,-1,1,-1}; int binpow(int a,int n){ if(!n)return 1; if(n%2==1)return a*binpow(a,n-1)%mod; int k=binpow(a,n/2); return k*k%mod; } int n,m,q; struct node{ int t,l,r; node(){ t=0,l=0,r=0; } node(int tl,int tr,int s){ t=s; l=tl; r=tr; } }; struct segtree{ vector<pii> roots; node t[20*MAX]; int cur; void build(int v,int tl,int tr){ if(tl==tr){ return; } int tm=(tl+tr)/2; t[v].l=++cur; t[v].r=++cur; build(t[v].l,tl,tm); build(t[v].r,tm+1,tr); } void update(int v,int tl,int tr,int pos,int x){ if(tl==tr){ t[v].t+=x; // cout<<v<<" "<<tl<<" "<<tr<<" "<<t[v].t<<"\n"; return; } int tm=(tl+tr)/2; if(pos<=tm){ cur++; t[cur]=node(t[t[v].l].l,t[t[v].l].r,t[t[v].l].t); t[v].l=cur; update(t[v].l,tl,tm,pos,x); } else{ cur++; // cout<<v<<" "<<cur<<" "<<t[v].r<<"\n"; t[cur]=node(t[t[v].r].l,t[t[v].r].r,t[t[v].r].t); t[v].r=cur; update(t[v].r,tm+1,tr,pos,x); } // cout<<v<<" "<<tl<<" "<<tr<<" "<<t[v].t<<" "<<t[v].l<<" "<<t[v].r<<"\n"; t[v].t=t[t[v].l].t+t[t[v].r].t; // cout<<v<<" "<<tl<<" "<<tr<<" "<<t[v].t<<" "<<t[v].l<<" "<<t[v].r<<"\n"; } int get(int v,int tl,int tr,int l,int r){ if(l>r||tl>r||l>tr)return 0; if(l<=tl&&tr<=r){ return t[v].t; } int tm=(tl+tr)/2; return get(t[v].l,tl,tm,l,r)+get(t[v].r,tm+1,tr,l,r); } }t; int z[MAX]; int f[MAX]; void solve(){ cin>>n>>m>>q; t.roots.pb({1,0}); t.cur=1; t.build(1,1,n); for(int i=1;i<=q;i++){ // cout<<"!!! "<<i<<"\n"; // for(int i=1;i<=n;i++){ // cout<<t.get(t.roots.back().F,1,n,i,i)<<" "; // } // cout<<"\n"; int type; cin>>type; if(type==1){ int l,r,x; cin>>l>>r>>z[i]>>x; int nroot=++t.cur; int lroot=t.roots.back().F; t.t[nroot]=node(t.t[lroot].l,t.t[lroot].r,t.t[lroot].t); // cout<<x<<"\n"; t.update(nroot,1,n,l,x); if(r+1<=n)t.update(nroot,1,n,r+1,-x); t.roots.pb({nroot,i}); } else if(type==2){ int l,r,x; cin>>l>>r>>x; for(int i=l;i<=r;i++){ f[i]=min(f[i]+x,t.get(t.roots.back().F,1,n,1,i)); } } else{ int v,pos; cin>>v>>pos; pos+=f[v]; int l=0,r=sz(t.roots)-1,res=sz(t.roots)-1; // cout<<f[v]<<" "<<t.get(t.roots.back().F,1,n,1,v)<<" "<<pos<<"\n"; if(t.get(t.roots.back().F,1,n,1,v)<pos){ cout<<0<<"\n"; continue; } while(l<=r){ int m=(l+r)/2; if(t.get(t.roots[m].F,1,n,1,v)<pos){ l=m+1; } else{ r=m-1; res=m; } } cout<<z[t.roots[res].S]<<"\n"; } } } signed main(){ // freopen("help.in","r",stdin); // freopen("help.out","w",stdout); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); // prec(); int t=1; // cin>>t; while(t--)solve(); }

Compilation message (stderr)

foodcourt.cpp:3: warning: ignoring '#pragma optimize ' [-Wunknown-pragmas]
    3 | #pragma optimize("Ofast")
      | 
foodcourt.cpp:4: warning: ignoring '#pragma target ' [-Wunknown-pragmas]
    4 | #pragma target("avx2")
      |
#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...