#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e6+5;
#define pii pair<int,int>
#define fi first
#define se second
int N,M,B,P,C[maxn];
struct Rec{
int x,y,u,v;
}R[maxn];
namespace B1{
int tree[4*maxn],lazy[4*maxn];
vector<int> pos[maxn];
void update(int l,int r,int id,int tl,int tr,int val){
if(tr<l || r<tl) return;
if(tl<=l && r<=tr){
tree[id]+=val;
lazy[id]+=val;
return;
}
int mid=(l+r)>>1;
update(l,mid,id<<1,tl,tr,val);update(mid+1,r,id<<1|1,tl,tr,val);
tree[id]=min(tree[id<<1],tree[id<<1|1])+lazy[id];
}
void solve(){
auto check = [&](int d){
for(int i=1;i<=N-d+1;i++) pos[i].clear();
for(int i=1;i<=4*(M-d+1);i++) tree[i]=lazy[i]=0;
for(int i=1;i<=P;i++){
int x=max(1,R[i].x-d+1),u=R[i].u;
pos[x].push_back(i);pos[u+1].push_back(i);
}
for(int i=1;i<=N-d+1;i++){
for(int id:pos[i]){
int l=max(1,R[id].y-d+1),r=R[id].v,c=C[id];
if(i==R[id].u+1) c=-c;
update(1,M-d+1,1,l,r,c);
}
//cout << i << ' ' << tree[1] << '\n';
if(tree[1]<=B) return true;
}
return false;
};
int l=1,r=min(N,M),res=0;
while(l<=r){
int mid=(l+r)>>1;
if(check(mid)) res=mid,l=mid+1;
else r=mid-1;
}
cout << res << '\n';
}
}
namespace B0{
vector<int> add[maxn],del[maxn];
pii tree[4*maxn];
void build(int l,int r,int id){
tree[id].se=r-l+1;
if(l==r) return;
int mid=(l+r)>>1;
build(l,mid,id<<1);build(mid+1,r,id<<1|1);
}
int lazy[4*maxn];
void update(int l,int r,int id,int tl,int tr,int val){
if(tr<l || r<tl) return;
if(tl<=l && r<=tr){
tree[id].fi+=val;
lazy[id]+=val;
return;
}
int mid=(l+r)>>1;
update(l,mid,id<<1,tl,tr,val);update(mid+1,r,id<<1|1,tl,tr,val);
tree[id].fi=min(tree[id<<1].fi,tree[id<<1|1].fi);
tree[id].se=(tree[id<<1].fi==tree[id].fi)*tree[id<<1].se+(tree[id<<1|1].fi==tree[id].fi)*tree[id<<1|1].se;
tree[id].fi+=lazy[id];
}
void solve(){
for(int i=1;i<=P;i++){
add[R[i].x].push_back(i);
del[R[i].u].push_back(i);
}
int res=0;
build(1,M,1);
for(int i=1,j=0;i<=N;i++){
while(j<=N){
for(int id:add[j]) update(1,M,1,R[id].y,R[id].v,1);
if((!tree[1].fi)*tree[1].se>=j-i+1) j++;
else break;
}
res=max(res,j-i);
for(int id:del[i]) update(1,M,1,R[id].y,R[id].v,-1);
}
cout << res << '\n';
}
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);cout.tie(NULL);
cin >> N >> M >> B >> P;
for(int i=1;i<=P;i++) cin >> R[i].x >> R[i].y >> R[i].u >> R[i].v >> C[i];
if(B) B1::solve();
else B0::solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
27 ms |
70736 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
70896 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
28 ms |
70992 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
27 ms |
71164 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
29 ms |
74076 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
40 ms |
91984 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
39 ms |
90004 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
71852 KB |
Output is correct |
2 |
Correct |
55 ms |
71764 KB |
Output is correct |
3 |
Correct |
48 ms |
71760 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
113 ms |
76624 KB |
Output is correct |
2 |
Correct |
207 ms |
77192 KB |
Output is correct |
3 |
Correct |
177 ms |
77400 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
162 ms |
93652 KB |
Output is correct |
2 |
Correct |
62 ms |
76116 KB |
Output is correct |
3 |
Correct |
130 ms |
103760 KB |
Output is correct |
4 |
Correct |
375 ms |
110160 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
289 ms |
104360 KB |
Output is correct |
2 |
Correct |
575 ms |
113248 KB |
Output is correct |
3 |
Correct |
108 ms |
92500 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
211 ms |
95632 KB |
Output is correct |
2 |
Correct |
749 ms |
116048 KB |
Output is correct |
3 |
Correct |
698 ms |
115664 KB |
Output is correct |
4 |
Correct |
759 ms |
115916 KB |
Output is correct |
5 |
Correct |
797 ms |
116116 KB |
Output is correct |
6 |
Correct |
82 ms |
93264 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
469 ms |
116312 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
584 ms |
125776 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
699 ms |
133356 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |