Submission #914589

#TimeUsernameProblemLanguageResultExecution timeMemory
914589abcvuitunggioPyramid Base (IOI08_pyramid_base)C++17
45 / 100
849 ms113408 KiB
#include <bits/stdc++.h> using namespace std; const int M=1000001,P=400001; int m,n,b,p,x[P],y[P],u[P],v[P],c[P]; unsigned int t[M*4],sum[M*4]; vector <int> ve[M+1]; void update(int node, int l, int r, int u, int v, int val){ if (l>v||r<u) return; if (l>=u&&r<=v){ t[node]+=val; sum[node]+=val; return; } int mid=(l+r)>>1; update(node<<1,l,mid,u,v,val); update(node<<1|1,mid+1,r,u,v,val); t[node]=min(t[node<<1],t[node<<1|1])+sum[node]; } bool check(int sz){ for (int i=1;i<=m+1;i++) ve[i].clear(); for (int i=1;i<=n*4;i++) t[i]=sum[i]=0; for (int i=1;i<=p;i++){ int X=max(x[i]-sz+1,1); ve[X].push_back(i); ve[u[i]+1].push_back(-i); } for (int i=1;i<=m-sz+1;i++){ for (int j:ve[i]) update(1,1,n-sz+1,max(y[abs(j)]-sz+1,1),v[abs(j)],c[abs(j)]*(j<0?-1:1)); if (t[1]<=b) return true; } return false; } int st[M*4][4],lazy[M*4]; void build(int node, int l, int r){ st[node][0]=st[node][1]=st[node][2]=r-l+1; if (l==r) return; int mid=(l+r)>>1; build(node<<1,l,mid); build(node<<1|1,mid+1,r); } void update2(int node, int l, int r, int u, int v, int val){ if (l>v||r<u) return; if (l>=u&&r<=v){ st[node][3]+=val; lazy[node]+=val; return; } int mid=(l+r)>>1; update2(node<<1,l,mid,u,v,val); update2(node<<1|1,mid+1,r,u,v,val); int x=node<<1,y=node<<1|1; st[node][3]=min(st[x][3],st[y][3])+lazy[node]; if (st[x][3]!=st[y][3]){ int z=(st[x][3]<st[y][3]?x:y); for (int i=0;i<3;i++) st[node][i]=st[z][i]; if (z==x) st[node][2]=0; else st[node][1]=0; } else{ st[node][0]=max(max(st[x][0],st[y][0]),st[x][2]+st[y][1]); st[node][1]=st[x][1]+(st[x][1]==mid-l+1)*st[y][1]; st[node][2]=st[y][2]+(st[y][2]==r-mid)*st[x][2]; } } int main(){ ios_base::sync_with_stdio(NULL);cin.tie(nullptr); cin >> m >> n >> b >> p; for (int i=1;i<=p;i++){ cin >> x[i] >> y[i] >> u[i] >> v[i] >> c[i]; ve[x[i]].push_back(i); ve[u[i]].push_back(-i); } if (b){ int l=1,r=min(m,n),kq=0; while (l<=r){ int mid=(l+r)>>1; if (check(mid)){ kq=mid; l=mid+1; } else r=mid-1; } cout << kq; } int r=0,mx=0; build(1,1,n); for (int i=1;i<=m;i++){ while (r<=m&&!st[1][3]&&st[1][0]>=r-i+1){ r++; for (int i:ve[r]) if (i>0) update2(1,1,n,y[i],v[i],1); } mx=max(mx,r-i); for (int j:ve[i]) if (j<0) update2(1,1,n,y[-j],v[-j],-1); } cout << mx; }

Compilation message (stderr)

pyramid_base.cpp: In function 'bool check(int)':
pyramid_base.cpp:33:17: warning: comparison of integer expressions of different signedness: 'unsigned int' and 'int' [-Wsign-compare]
   33 |         if (t[1]<=b)
      |             ~~~~^~~
#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...
#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...