#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define all(vr) vr.begin(),vr.end()
#define vi vector<int>
#define vll vector<ll>
#define ui unsigned int
const int N=1e6+10;
struct segment_tree
{
int it[N*4],lazy[N*4];
int n;
/*void down(int id)
{
int x=lazy[id];
lazy[id]=0;
it[id*2]+=x;
lazy[id*2]+=x;
it[id*2+1]+=x;
lazy[id*2+1]+=x;
}*/
void update(int id,int l,int r,int u,int v,int x)
{
if (l>v || r<u) return;
if (u<=l && r<=v)
{
it[id]+=x;
lazy[id]+=x;
return;
}
//down(id);
int mid=(l+r)/2;
update(id*2,l,mid,u,v,x);
update(id*2+1,mid+1,r,u,v,x);
it[id]=lazy[id]+min(it[id*2],it[id*2+1]);
}
void init(int x)
{
n=x;
memset(it,0,sizeof(it));
memset(lazy,0,sizeof(lazy));
}
void upd(int u,int v,int x) { update(1,1,n,u,v,x);}
ll get() { return it[1];}
} seg;
struct obs{int x1,x2,y1,y2,c;};
obs a[N];
int n,m,B,p;
struct event{int l,r,x;};
vector<event> vt[N];
bool check(int l)
{
for (int i=1;i<=m;i++) vt[i].clear();
for (int i=1;i<=p;i++)
{
int x1=max(a[i].x1-l+1,1);
int y1=max(a[i].y1-l+1,1);
int x2=min(a[i].x2,m-l+1);
int y2=min(a[i].y2,n-l+1);
if (x1>x2 || y1>y2) continue;
int c=a[i].c;
vt[x1].pb({y1,y2,c});
vt[x2+1].pb({y1,y2,-c});
}
seg.init(n-l+1);
for (int i=1;i<=m-l+1;i++)
{
for (event e : vt[i]) seg.upd(e.l,e.r,e.x);
if (seg.get()<=B) return true;
}
return false;
}
int main()
{
//freopen("ss.inp","r",stdin);
ios::sync_with_stdio(false);
cin.tie(0);
cin>>m>>n>>B>>p;
for (int i=1;i<=p;i++) cin>>a[i].x1>>a[i].y1>>a[i].x2>>a[i].y2>>a[i].c,a[i].c=min(a[i].c,B+1);
int l=1,r=min(m,n),ans=0;
while (l<=r)
{
int mid=(l+r)/2;
if (check(mid)) ans=mid,l=mid+1;
else r=mid-1;
}
cout<<ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
46 ms |
55056 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
44 ms |
55116 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
66 ms |
55116 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
89 ms |
55236 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
109 ms |
55488 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
161 ms |
55564 KB |
Output is correct |
2 |
Correct |
241 ms |
55644 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
251 ms |
55836 KB |
Output is correct |
2 |
Correct |
172 ms |
55504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
86 ms |
56316 KB |
Output is correct |
2 |
Correct |
122 ms |
55824 KB |
Output is correct |
3 |
Correct |
115 ms |
55940 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
237 ms |
58684 KB |
Output is correct |
2 |
Correct |
402 ms |
58440 KB |
Output is correct |
3 |
Correct |
339 ms |
58896 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
373 ms |
62976 KB |
Output is correct |
2 |
Correct |
132 ms |
60048 KB |
Output is correct |
3 |
Correct |
202 ms |
57752 KB |
Output is correct |
4 |
Correct |
639 ms |
65136 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
599 ms |
65592 KB |
Output is correct |
2 |
Correct |
1120 ms |
66940 KB |
Output is correct |
3 |
Correct |
255 ms |
63016 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
462 ms |
65712 KB |
Output is correct |
2 |
Correct |
1435 ms |
69528 KB |
Output is correct |
3 |
Correct |
1325 ms |
68968 KB |
Output is correct |
4 |
Correct |
1452 ms |
69744 KB |
Output is correct |
5 |
Correct |
1499 ms |
69460 KB |
Output is correct |
6 |
Correct |
201 ms |
63836 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5069 ms |
94244 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5064 ms |
101328 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5060 ms |
104544 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |