#include<iostream>
#define TASKNAME "codeforce"
#define pb push_back
#define pli pair<int,int>
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
using ll=long long;
const ll maxN=1e6+10;
const ll inf=1e18;
const ll mod=1e9+7;
ll st[4*maxN],lazy[4*maxN];
void down(ll id)
{
ll &x=lazy[id];
st[id*2]+=x;
st[id*2+1]+=x;
lazy[id*2+1]+=x;
lazy[id*2]+=x;
x=0;
}
#include<vector>
void update(ll i,ll j,ll v,ll id,ll l,ll r)
{
if(j<l||r<i) return;
if(i<=l&&r<=j)
{
st[id]+=v;
lazy[id]+=v;
return;
}
ll mid=l+r>>1;
down(id);
update(i,j,v,id*2,l,mid);
update(i,j,v,id*2+1,mid+1,r);
st[id]=min(st[id*2],st[id*2+1]);
}
ll n,m;
vector<int>in[maxN],out[maxN];
int p,x1[maxN],x2[maxN],y1[maxN],y2[maxN],c[maxN],b;
int cnt[maxN];
bool check(ll mid)
{
ll mid1=(mid+1)/2;
ll mid2=mid/2;
for(int i=1;i<=m+1;i++) in[i].clear(),out[i].clear();
for(int i=1;i<=p;i++)
{
cnt[max(x1[i]-mid1+1,mid2)]++;
}
for(int i=mid2;i<=m-mid1+1;i++)
{
in[i].resize(cnt[i]);
}
for(int i=1;i<=p;i++)
{
in[max(x1[i]-mid1+1,mid2)][--cnt[max(x1[i]-mid1+1,mid2)]]=i;
}
for(int i=1;i<=p;i++)
{
cnt[min(x2[i]+mid2,m-mid1+1)]++;
}
for(int i=mid2;i<=m-mid1+1;i++)
{
out[i].resize(cnt[i]);
}
for(int i=1;i<=p;i++)
{
out[min(x2[i]+mid2,m-mid1+1)][--cnt[min(x2[i]+mid2,m-mid1+1)]]=i;
}
fill(st,st+4*maxN,0);
fill(lazy,lazy+4*maxN,0);
for(int i=mid2;i<=m-mid1;i++)
{
for(auto id:in[i])
{
ll l,r;
l=max(y1[id]-mid1+1,mid2);
r=min(y2[id]+mid2-1,n-mid1);
update(l,r,c[id],1,mid2,n-mid1);
}
for(auto id:out[i])
{
ll l,r;
l=max(y1[id]-mid1+1,mid2);
r=min(y2[id]+mid2-1,n-mid1);
update(l,r,-c[id],1,mid2,n-mid1);
}
if(st[1]<=b) return true;
}
return false;
}
void solve()
{
cin >> m >> n;
cin >> b;
cin >> p;
for(int i=1;i<=p;i++)
{
cin >> x1[i] >> y1[i] >> x2[i] >> y2[i] >> c[i];
x1[i]--;
//x2[i]--;
y1[i]--;
//y2[i]--;
}
ll low=1,high=min(m,n);
while(low<=high)
{
ll mid=low+high>>1;
if(check(mid)) low=mid+1;
else high=mid-1;
}
cout << high;
}
int main()
{
fastio
//freopen(TASKNAME".INP","r",stdin);
//freopen(TASKNAME".OUT","w",stdout);
solve();
}
Compilation message
pyramid_base.cpp: In function 'void update(ll, ll, ll, ll, ll, ll)':
pyramid_base.cpp:33:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
33 | ll mid=l+r>>1;
| ~^~
pyramid_base.cpp: In function 'void solve()':
pyramid_base.cpp:111:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
111 | ll mid=low+high>>1;
| ~~~^~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
67 ms |
109892 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
61 ms |
109896 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
86 ms |
109912 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
113 ms |
110220 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
133 ms |
110964 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
220 ms |
112060 KB |
Output is correct |
2 |
Correct |
360 ms |
114696 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
371 ms |
114636 KB |
Output is correct |
2 |
Correct |
242 ms |
112116 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
106 ms |
110664 KB |
Output is correct |
2 |
Correct |
136 ms |
110660 KB |
Output is correct |
3 |
Correct |
136 ms |
110892 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
245 ms |
115012 KB |
Output is correct |
2 |
Correct |
383 ms |
115428 KB |
Output is correct |
3 |
Correct |
312 ms |
115896 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
406 ms |
121904 KB |
Output is correct |
2 |
Correct |
148 ms |
121628 KB |
Output is correct |
3 |
Correct |
174 ms |
111328 KB |
Output is correct |
4 |
Correct |
632 ms |
129656 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
568 ms |
127864 KB |
Output is correct |
2 |
Correct |
992 ms |
132784 KB |
Output is correct |
3 |
Correct |
294 ms |
118392 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
439 ms |
124104 KB |
Output is correct |
2 |
Correct |
1192 ms |
137492 KB |
Output is correct |
3 |
Correct |
1190 ms |
137036 KB |
Output is correct |
4 |
Correct |
1364 ms |
137132 KB |
Output is correct |
5 |
Correct |
1264 ms |
137628 KB |
Output is correct |
6 |
Correct |
238 ms |
117708 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4754 ms |
185568 KB |
Output is correct |
2 |
Correct |
830 ms |
171468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5028 ms |
192080 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5059 ms |
196712 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |