#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>
const int N=1e6+10;
struct segment_tree
{
ll it[N*4],lazy[N*4];
int n;
ll combine(ll x,ll y) {return min(x,y);}
void build(int id,int l,int r)
{
if (l==r)
{
it[id]=lazy[id]=0;
return;
}
int mid=(l+r)/2;
build(id*2,l,mid);
build(id*2+1,mid+1,r);
it[id]=combine(it[id*2],it[id*2+1]);
lazy[id]=0;
}
void down(int id)
{
ll 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,ll 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]=combine(it[id*2],it[id*2+1]);
}
void init(int x)
{
n=x;
build(1,1,n);
}
void upd(int u,int v,ll 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;
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;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
23756 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
23816 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
23904 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
24528 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
57 ms |
28308 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
128 ms |
40664 KB |
Output is correct |
2 |
Correct |
347 ms |
57228 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
347 ms |
57244 KB |
Output is correct |
2 |
Correct |
160 ms |
40592 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
25468 KB |
Output is correct |
2 |
Correct |
69 ms |
25156 KB |
Output is correct |
3 |
Correct |
67 ms |
25224 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
195 ms |
31848 KB |
Output is correct |
2 |
Correct |
432 ms |
31848 KB |
Output is correct |
3 |
Correct |
319 ms |
32128 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
422 ms |
48540 KB |
Output is correct |
2 |
Correct |
100 ms |
29128 KB |
Output is correct |
3 |
Correct |
299 ms |
59728 KB |
Output is correct |
4 |
Correct |
866 ms |
67224 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
775 ms |
67916 KB |
Output is correct |
2 |
Correct |
1520 ms |
69228 KB |
Output is correct |
3 |
Correct |
249 ms |
48952 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
505 ms |
51748 KB |
Output is correct |
2 |
Correct |
1946 ms |
71852 KB |
Output is correct |
3 |
Correct |
1838 ms |
71476 KB |
Output is correct |
4 |
Correct |
2055 ms |
71920 KB |
Output is correct |
5 |
Correct |
1979 ms |
71828 KB |
Output is correct |
6 |
Correct |
152 ms |
49964 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5070 ms |
98112 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5055 ms |
104488 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5099 ms |
113224 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |