#pragma GCC optimize("O3,unroll-loops")
#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 n,log;
int t[K],lz[K];
void init(int _n){
n=_n;
for(log=0;(1<<log)<n;log++);
}
void apply(int i,int v){
t[i]+=v,lz[i]+=v;
}
void push(int i){
apply(i<<1,lz[i]);
apply(i<<1|1,lz[i]);
lz[i]=0;
}
void pull(int i){
t[i]=min(t[i<<1],t[i<<1|1]);
}
void build(){
for(int i=1;i<2*n;i++)t[i]=lz[i]=0;
}
void update(int l,int r,int v){
if(l>r)return;
l+=n-1,r+=n;
for(int i=log;i>=1;i--){
if(((l>>i)<<i)!=l)push(l>>i);
if(((r>>i)<<i)!=r)push((r-1)>>i);
}
for(int l2=l,r2=r;l2<r2;l2>>=1,r2>>=1){
if(l2&1)apply(l2++,v);
if(r2&1)apply(--r2,v);
}
for(int i=1;i<=log;i++){
if(((l>>i)<<i)!=l)pull(l>>i);
if(((r>>i)<<i)!=r)pull((r-1)>>i);
}
}
}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),min(r+k-1,n),v);
for(int i=k;i<=m;i++){
for(auto [l,r,v]:add[i])seg.update(max(l,k),min(r+k-1,n),v);
for(auto [l,r,v]:del[i-k])seg.update(max(l,k),min(r+k-1,n),-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);
}
seg.init(n);
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 |
22 ms |
47196 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
47196 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
47272 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
47440 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
34 ms |
48988 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
72 ms |
63068 KB |
Output is correct |
2 |
Correct |
110 ms |
63068 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
102 ms |
63056 KB |
Output is correct |
2 |
Correct |
78 ms |
63068 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
31 ms |
47704 KB |
Output is correct |
2 |
Correct |
45 ms |
47704 KB |
Output is correct |
3 |
Correct |
42 ms |
47708 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
93 ms |
49644 KB |
Output is correct |
2 |
Correct |
144 ms |
49756 KB |
Output is correct |
3 |
Correct |
129 ms |
49744 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
173 ms |
64092 KB |
Output is correct |
2 |
Correct |
45 ms |
48464 KB |
Output is correct |
3 |
Correct |
75 ms |
63868 KB |
Output is correct |
4 |
Correct |
227 ms |
64312 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
291 ms |
64612 KB |
Output is correct |
2 |
Correct |
411 ms |
64440 KB |
Output is correct |
3 |
Correct |
194 ms |
64516 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
271 ms |
64848 KB |
Output is correct |
2 |
Correct |
534 ms |
64600 KB |
Output is correct |
3 |
Correct |
473 ms |
64596 KB |
Output is correct |
4 |
Correct |
522 ms |
64596 KB |
Output is correct |
5 |
Correct |
534 ms |
64600 KB |
Output is correct |
6 |
Correct |
191 ms |
64848 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2001 ms |
74324 KB |
Output is correct |
2 |
Correct |
334 ms |
55004 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3058 ms |
79444 KB |
Output is correct |
2 |
Correct |
2988 ms |
76740 KB |
Output is correct |
3 |
Correct |
992 ms |
71568 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3424 ms |
84308 KB |
Output is correct |
2 |
Correct |
4808 ms |
82364 KB |
Output is correct |
3 |
Execution timed out |
5054 ms |
93380 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |