#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,int,int>> obs;
vector<tuple<int,int,int>> event[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(int l,int r,int i){
t[i]=0,lz[i]=0;
if(l==r)return;
int m=(l+r)/2;
build(l,m,i*2);
build(m+1,r,i*2+1);
}
void build(){
build(1,n,1);
}
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){
for(int i=k;i<=m;i++)event[i].clear();
for(auto &[x1,y1,x2,y2,c]:obs){
event[max(x1,k)].emplace_back(max(y1,k),y2+k-1,c);
if(x2+k<=m)event[x2+k].emplace_back(max(y1,k),y2+k-1,-c);
}
seg.build();
seg.update(1,k-1,INF);
for(int i=k;i<=m;i++){
for(auto &[l,r,v]:event[i])seg.update(l,r,v);
if(seg.t[1]<=b)return true;
}
return false;
}
int main(){
cin.tie(nullptr)->sync_with_stdio(false);
cin >> m >> n >> b >> p;
obs.resize(p);
for(auto &[x1,y1,x2,y2,c]:obs)cin >> x1 >> y1 >> x2 >> 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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
23900 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
23716 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
23900 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
24412 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
26448 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
75 ms |
40532 KB |
Output is correct |
2 |
Correct |
141 ms |
40724 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
137 ms |
40988 KB |
Output is correct |
2 |
Correct |
86 ms |
40788 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
25432 KB |
Output is correct |
2 |
Correct |
36 ms |
24928 KB |
Output is correct |
3 |
Correct |
31 ms |
24912 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
104 ms |
29724 KB |
Output is correct |
2 |
Correct |
168 ms |
29524 KB |
Output is correct |
3 |
Correct |
151 ms |
29776 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
191 ms |
48464 KB |
Output is correct |
2 |
Correct |
42 ms |
29268 KB |
Output is correct |
3 |
Correct |
93 ms |
43136 KB |
Output is correct |
4 |
Correct |
359 ms |
50612 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
330 ms |
51280 KB |
Output is correct |
2 |
Correct |
620 ms |
52344 KB |
Output is correct |
3 |
Correct |
177 ms |
48632 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
262 ms |
51464 KB |
Output is correct |
2 |
Correct |
764 ms |
55000 KB |
Output is correct |
3 |
Correct |
679 ms |
55184 KB |
Output is correct |
4 |
Correct |
769 ms |
54800 KB |
Output is correct |
5 |
Correct |
815 ms |
55188 KB |
Output is correct |
6 |
Correct |
157 ms |
49572 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3284 ms |
84488 KB |
Output is correct |
2 |
Correct |
704 ms |
65180 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4986 ms |
95392 KB |
Output is correct |
2 |
Execution timed out |
5056 ms |
113112 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5079 ms |
104616 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |