#include <bits/stdc++.h>
using namespace std;
const int M=1000001,P=400001;
int m,n,N,b,p,x[P],y[P],u[P],v[P],c[P];
unsigned int st[M*2],sum[M];
void update(int i, int val){
st[i]+=val;
if (i<N)
sum[i]+=val;
}
void update(int l, int r, int val){
if (l>N)
return;
r=min(r,N);
for (int L=l+N-1,R=r+N;L<R;L>>=1,R>>=1){
if (L&1)
update(L++,val);
if (R&1)
update(--R,val);
}
while (l>1){
l>>=1;
st[l]=min(st[l<<1],st[l<<1|1])+sum[l];
}
r--;
while (r>1){
r>>=1;
st[r]=min(st[r<<1],st[r<<1|1])+sum[r];
}
}
void down(int i){
for (int k=20;k;k--){
int j=i>>k;
if (sum[j]){
update(j<<1,sum[j]);
update(j<<1|1,sum[j]);
sum[j]=0;
}
}
}
unsigned int get(int l, int r){
down(l-1);
down(r-2);
unsigned int res=3e9;
for (int L=l+N-1,R=r+N;L<R;L>>=1,R>>=1){
if (L&1)
res=min(res,st[L++]);
if (R&1)
res=min(res,st[--R]);
}
return res;
}
vector <int> ve[M+1];
bool check(int sz){
N=n-sz+1;
for (int i=1;i<=m+1;i++)
ve[i].clear();
memset(st,0,sizeof(st));
memset(sum,0,sizeof(sum));
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(max(y[abs(j)]-sz+1,1),v[abs(j)],c[abs(j)]*(j<0?-1:1));
if (get(1,N)<=b)
return true;
}
return false;
}
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];
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;
}
Compilation message
pyramid_base.cpp: In function 'bool check(int)':
pyramid_base.cpp:68:21: warning: comparison of integer expressions of different signedness: 'unsigned int' and 'int' [-Wsign-compare]
68 | if (get(1,N)<=b)
| ~~~~~~~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
12 ms |
41560 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
41560 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
15 ms |
41668 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
17 ms |
41820 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
86 ms |
42176 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
211 ms |
42068 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
961 ms |
42500 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
41816 KB |
Output is correct |
2 |
Correct |
42 ms |
42072 KB |
Output is correct |
3 |
Incorrect |
43 ms |
42032 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
130 ms |
43700 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
380 ms |
46452 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
723 ms |
48928 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
496 ms |
47072 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4633 ms |
73156 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5086 ms |
74848 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5046 ms |
75472 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |