#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 t[N*2],d[N*2],n;
void build(int p) {
while (p > 1) p >>= 1, t[p] = min(t[p<<1], t[p<<1|1]) + d[p];
}
void upd(int l, int r, int value) {
l += n - 1, r += n;
int l0 = l, r0 = r;
for (; l < r; l >>= 1, r >>= 1) {
if (l&1) {
t[l] += value;
d[l--] += value;
}
if (r&1) {
t[--r] += value;
d[r] += value;
}
}
build(l0);
build(r0 - 1);
}
int get() { return t[1];}
void init(int x)
{
n=x;
memset(t,0,sizeof(t));
memset(d,0,sizeof(d));
}
} 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;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
30 ms |
39372 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
31 ms |
39472 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
42 ms |
39524 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
51 ms |
39668 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
71 ms |
39808 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
125 ms |
39940 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
160 ms |
40088 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
58 ms |
40612 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
184 ms |
42956 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
496 ms |
48356 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
739 ms |
51004 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
520 ms |
51664 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5062 ms |
79908 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5094 ms |
86056 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5064 ms |
91728 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |