#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+5;
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[2*N],lz[2*N];
void init(int _n){
n=_n;
log=32-__builtin_clz(n);
}
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;
inline bool check(int k){
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);
bool res=false;
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)res=true;
}
for(int i=m-k+1;i<=m;i++)for(auto [l,r,v]:del[i])seg.update(max(l,k),min(r+k-1,n),-v);
seg.update(1,k-1,-INF);
return res;
}
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 |
25 ms |
47196 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
47196 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
47452 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
30 ms |
47452 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
49 ms |
48988 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
124 ms |
54092 KB |
Output is correct |
2 |
Correct |
112 ms |
62800 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
123 ms |
62036 KB |
Output is correct |
2 |
Correct |
110 ms |
54784 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
43 ms |
47708 KB |
Output is correct |
2 |
Correct |
52 ms |
47836 KB |
Output is correct |
3 |
Correct |
48 ms |
47700 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
146 ms |
49900 KB |
Output is correct |
2 |
Correct |
166 ms |
50260 KB |
Output is correct |
3 |
Correct |
150 ms |
50004 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
347 ms |
57148 KB |
Output is correct |
2 |
Correct |
74 ms |
48988 KB |
Output is correct |
3 |
Correct |
108 ms |
64088 KB |
Output is correct |
4 |
Correct |
436 ms |
63856 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
474 ms |
61264 KB |
Output is correct |
2 |
Correct |
466 ms |
65104 KB |
Output is correct |
3 |
Correct |
345 ms |
57664 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
421 ms |
57940 KB |
Output is correct |
2 |
Correct |
602 ms |
65484 KB |
Output is correct |
3 |
Correct |
633 ms |
65616 KB |
Output is correct |
4 |
Correct |
629 ms |
65552 KB |
Output is correct |
5 |
Correct |
580 ms |
65472 KB |
Output is correct |
6 |
Correct |
332 ms |
57940 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3099 ms |
79652 KB |
Output is correct |
2 |
Correct |
1103 ms |
59652 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4568 ms |
87360 KB |
Output is correct |
2 |
Correct |
4123 ms |
84160 KB |
Output is correct |
3 |
Correct |
2530 ms |
77856 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5031 ms |
94912 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |