#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<int,int> pii;
typedef pair<int,pii> pip;
typedef pair<pii,int> ppi;
#define f first
#define s second
#define all(x) x.begin(),x.end()
#define unicorn(x) x.resize(unique(x.begin(),x.end())-x.begin())
#define pb(x) push_back(x);
#define pp() pop_back();
#define lc 2*id+0
#define rc 2*id+1
const int LC = 1e6+10, L = 4e5, inf = 1e9;
int n,m,p,b;
vector<int> ev;
struct obs{
int l,r,c;
obs(int a,int b,int pr){
l = a;
r = b;
c = pr;
}
};
vector<obs> add[LC],er[LC];
random_device device;
default_random_engine rng(device());
#define randt(a,b) uniform_int_distribution<int64_t>(a,b)(rng)
void pr(int* vv,int l,int r){for(int i=l;i<r;i++){cout<<vv[i]<<" ";}cout<<endl;}
void prv(vector<int> vv){for(auto i:vv){cout<<i<<" ";}cout<<endl;}
void prl(long long* vv,int l,int r){for(int i=l;i<r;i++){cout<<vv[i]<<" ";}cout<<endl;}
void prvl(vector<long long> vv){for(auto i:vv){cout<<i<<" ";}cout<<endl;}
void prp(pii* vv,int l,int r){for(int i=l;i<r;i++){cout<<i<<": "<<vv[i].f<<" , "<<vv[i].s<<" / ";}cout<<endl;}
struct sagi{
struct node{
int lazy, mn;
node(){
lazy = mn = 0;
}
}t[LC<<3];
void spread(int id){
t[lc].lazy += t[id].lazy;
t[rc].lazy += t[id].lazy;
t[id].mn += t[id].lazy;
t[id].lazy = 0;
}
void update(int id,int l,int r,int l2,int r2,int x){
spread(id);
if(l==l2 and r==r2){
t[id].lazy += x;
return;
}
int mid = (l2+r2)>>1;
if(l<mid)
update(lc,l,min(r,mid),l2,mid,x);
if(r>mid)
update(rc,max(l,mid),r,mid,r2,x);
spread(lc);
spread(rc);
t[id].mn = min(t[lc].mn, t[rc].mn);
}
int get(int id,int l,int r,int l2,int r2){
spread(id);
if(l==l2 and r==r2){
return t[id].mn;
}
int mid = (l2+r2)>>1;
int ans = inf;
if(l<mid)
ans = min(ans, get(lc,l,min(r,mid),l2,mid));
if(r>mid)
ans = min(ans, get(rc,max(l,mid),r,mid,r2));
return ans;
}
};
int main(){
//ofstream cout ("out.txt");
//ifstream cin ("in.txt");
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>n>>m>>b>>p;
for(int i=0;i<p;i++){
int x1,y1,x2,y2,pr;
cin>>x1>>y1>>x2>>y2>>pr;
obs x(y1,y2,pr);
ev.pb(x1);
ev.pb(x2);
add[x1].pb(x);
er[x2].pb(x);
}
sort(all(ev));
unicorn(ev);
int l=0,r=1e6+1;
while(r-l>1){
int mid = (l+r)>>1;
if(mid > n or mid > m){
r = mid;
continue;
}
//cout<<"mid: "<<mid<<endl;
sagi seg;
seg.update(1,1,mid,1,m+1,inf);
int ans = inf;
for(int i=1;i<=n;i++){
//cout<<"ev: "<<i<<endl;
if(i>mid){
ans = min(ans,seg.t[1].mn);
}
for(auto j:add[i]){
//cout<<" add: "<<j.l<<" "<<j.r<<" "<<j.c<<" / "<<max(j.l,mid)<<" "<<min(j.r+mid,m+1)<<endl;
seg.update(1,max(j.l,mid),min(j.r+mid,m+1),1,m+1,j.c);
}
for(auto j:er[max(i-mid,0)]){
//cout<<" ere: "<<j.l<<" "<<j.r<<" "<<j.c<<endl;
seg.update(1,max(j.l,mid),min(j.r+mid,m+1),1,m+1,-j.c);
}
if(i>mid){
ans = min(ans,seg.t[1].mn);
}
//cout<<" res: "<<seg.t[1].mn<<endl;
//cout<<"= = = = = = = = = = = "<<endl;
}
//cout<<"l,r: "<<l<<","<<r<<" / mid: "<<mid<<" / ans: "<<ans<<endl;
if(ans <= b)
l = mid;
else
r = mid;
//cout<<"---------------------"<<endl;
}
cout<<l<<endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
68 ms |
109900 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
74 ms |
110028 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
97 ms |
109904 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
106 ms |
109960 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
131 ms |
110096 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
189 ms |
109900 KB |
Output is correct |
2 |
Correct |
214 ms |
110032 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
233 ms |
110156 KB |
Output is correct |
2 |
Correct |
202 ms |
110132 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
101 ms |
110420 KB |
Output is correct |
2 |
Correct |
149 ms |
110444 KB |
Output is correct |
3 |
Correct |
147 ms |
110276 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
272 ms |
111384 KB |
Output is correct |
2 |
Correct |
354 ms |
111440 KB |
Output is correct |
3 |
Correct |
293 ms |
111324 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
439 ms |
111824 KB |
Output is correct |
2 |
Correct |
103 ms |
111720 KB |
Output is correct |
3 |
Incorrect |
138 ms |
111372 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
586 ms |
112588 KB |
Output is correct |
2 |
Correct |
777 ms |
112336 KB |
Output is correct |
3 |
Correct |
388 ms |
112568 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
513 ms |
112844 KB |
Output is correct |
2 |
Correct |
931 ms |
112888 KB |
Output is correct |
3 |
Correct |
942 ms |
112848 KB |
Output is correct |
4 |
Correct |
915 ms |
112844 KB |
Output is correct |
5 |
Correct |
932 ms |
112848 KB |
Output is correct |
6 |
Correct |
341 ms |
112844 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5058 ms |
128616 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5073 ms |
137436 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5065 ms |
145864 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |