#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]?0: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,max(r-i,(st[1][3]?0:st[1][0])));
for (int j:ve[i])
if (j<0)
update2(1,1,n,y[-j],v[-j],-1);
}
cout << mx;
}
Compilation message
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 time |
Memory |
Grader output |
1 |
Incorrect |
10 ms |
35160 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
35268 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
10 ms |
35164 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
10 ms |
35420 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
14 ms |
41560 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
76600 KB |
Output is correct |
2 |
Correct |
28 ms |
76632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
29 ms |
72540 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
16 ms |
37724 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
117 ms |
47952 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
378 ms |
110228 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
558 ms |
113488 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
425 ms |
110932 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
503 ms |
87168 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
661 ms |
90652 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
812 ms |
86104 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |