#include<bits/stdc++.h>
using namespace std;
const int N=1e6+5;
const int K=1<<21;
const int INF=INT_MAX/2;
int n,m,b,p;
vector<tuple<int,int,int>> add[N],del[N];
struct SegTree{
int t[K],lz[K];
void apply(int i,int v){
t[i]+=v,lz[i]+=v;
}
void push(int i){
apply(i*2,lz[i]);
apply(i*2+1,lz[i]);
lz[i]=0;
}
void build(){
for(int i=0;i<K;i++)t[i]=lz[i]=0;
}
void update(int l,int r,int i,int x,int y,int v){
if(y<l||r<x)return;
if(x<=l&&r<=y)return apply(i,v);
int m=(l+r)/2;
push(i);
update(l,m,i*2,x,y,v);
update(m+1,r,i*2+1,x,y,v);
t[i]=min(t[i*2],t[i*2+1]);
}
void update(int x,int y,int v){
update(1,n,1,x,y,v);
}
int query(int l,int r,int i,int x,int y){
if(y<l||r<x)return INF;
if(x<=l&&r<=y)return t[i];
int m=(l+r)/2;
push(i);
return min(query(l,m,i*2,x,y),query(m+1,r,i*2+1,x,y));
}
int query(int x,int y){
return query(1,n,1,x,y);
}
}seg;
bool check(int k){
seg.build();
seg.update(1,k-1,INF);
for(int i=1;i<k;i++)for(auto [l,r,v]:add[i])seg.update(max(l,k),r+k-1,v);
for(int i=k;i<=m;i++){
for(auto [l,r,v]:add[i])seg.update(max(l,k),r+k-1,v);
for(auto [l,r,v]:del[i-k])seg.update(max(l,k),r+k-1,-v);
if(seg.t[1]<=b)return true;
}
return false;
}
int main(){
cin.tie(nullptr)->sync_with_stdio(false);
cin >> m >> n >> b >> p;
for(int i=0;i<p;i++){
int x1,y1,x2,y2,c;
cin >> x1 >> y1 >> x2 >> y2 >> c;
add[x1].emplace_back(y1,y2,c);
del[x2].emplace_back(y1,y2,c);
}
int l=0,r=min(n,m);
while(l<r){
int m=(l+r+1)/2;
if(check(m))l=m;
else r=m-1;
}
cout << l;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
31 ms |
63572 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
63568 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
43 ms |
63768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
35 ms |
63832 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
47 ms |
63740 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
83 ms |
63872 KB |
Output is correct |
2 |
Correct |
120 ms |
63832 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
143 ms |
63876 KB |
Output is correct |
2 |
Correct |
98 ms |
64336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
41 ms |
63824 KB |
Output is correct |
2 |
Correct |
61 ms |
63952 KB |
Output is correct |
3 |
Correct |
54 ms |
63832 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
120 ms |
64688 KB |
Output is correct |
2 |
Correct |
204 ms |
64424 KB |
Output is correct |
3 |
Correct |
175 ms |
64624 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
224 ms |
65056 KB |
Output is correct |
2 |
Correct |
57 ms |
64848 KB |
Output is correct |
3 |
Correct |
95 ms |
64592 KB |
Output is correct |
4 |
Correct |
294 ms |
64848 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
335 ms |
65364 KB |
Output is correct |
2 |
Correct |
586 ms |
65108 KB |
Output is correct |
3 |
Correct |
203 ms |
65104 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
310 ms |
65600 KB |
Output is correct |
2 |
Correct |
794 ms |
65556 KB |
Output is correct |
3 |
Correct |
647 ms |
65528 KB |
Output is correct |
4 |
Correct |
731 ms |
65524 KB |
Output is correct |
5 |
Correct |
745 ms |
65380 KB |
Output is correct |
6 |
Correct |
199 ms |
65656 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2903 ms |
75088 KB |
Output is correct |
2 |
Correct |
457 ms |
70084 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4791 ms |
80276 KB |
Output is correct |
2 |
Correct |
4964 ms |
77648 KB |
Output is correct |
3 |
Correct |
1559 ms |
72316 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4827 ms |
84956 KB |
Output is correct |
2 |
Execution timed out |
5068 ms |
83136 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |