This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |