#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=2e6+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)
{
//cout << id<<' '<<v<<'\n';
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 cnt1[maxN],cnt2[maxN];
bool check(ll mid)
{
for(int i=1;i<=m+1;i++) in[i].clear(),out[i].clear();
for(int i=1;i<=p;i++)
{
cnt1[max(x1[i]-mid+1,mid)]++;
cnt2[min(x2[i]+mid,m-mid+1)]++;
//cout <<max(x1[i]-mid+1,mid)<<' '<<min(x2[i]+mid,m-mid+1)<<'\n';
}
for(int i=mid;i<=m-mid+1;i++)
{
in[i].resize(cnt1[i]);
out[i].resize(cnt2[i]);
}
for(int i=1;i<=p;i++)
{
in[max(x1[i]-mid+1,mid)][--cnt1[max(x1[i]-mid+1,mid)]]=i;
out[min(x2[i]+mid,m-mid+1)][--cnt2[min(x2[i]+mid,m-mid+1)]]=i;
}
fill(st,st+4*maxN,0);
fill(lazy,lazy+4*maxN,0);
for(int i=mid;i<=m-mid;i++)
{
for(auto id:in[i])
{
ll l,r;
l=max(y1[id]-mid+1,mid);
r=min(y2[id]+mid-1,n-mid);
update(l,r,c[id],1,mid,n-mid);
}
for(auto id:out[i])
{
ll l,r;
l=max(y1[id]-mid+1,mid);
r=min(y2[id]+mid-1,n-mid);
update(l,r,-c[id],1,mid,n-mid);
}
if(st[1]<=b) return true;
}
return false;
}
void solve()
{
cin >> m >> n;
m*=2;
n*=2;
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]--;
x1[i]*=2;
y1[i]*=2;
x2[i]*=2;
y2[i]*=2;
}
ll low=1,high=min(m/2,n/2);
while(low<=high)
{
ll mid=low+high>>1;
if(check(mid)) low=mid+1;
else high=mid-1;
}
cout << high;
//cout << check(4);
}
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:34:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
34 | ll mid=l+r>>1;
| ~^~
pyramid_base.cpp: In function 'void solve()':
pyramid_base.cpp:108:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
108 | ll mid=low+high>>1;
| ~~~^~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
114 ms |
219532 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
115 ms |
219620 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
160 ms |
219592 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
208 ms |
220108 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
249 ms |
221848 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
438 ms |
224036 KB |
Output is correct |
2 |
Correct |
621 ms |
234736 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
637 ms |
234760 KB |
Output is correct |
2 |
Correct |
450 ms |
225184 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
203 ms |
220432 KB |
Output is correct |
2 |
Correct |
237 ms |
220784 KB |
Output is correct |
3 |
Correct |
226 ms |
220896 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
389 ms |
227632 KB |
Output is correct |
2 |
Correct |
552 ms |
229084 KB |
Output is correct |
3 |
Correct |
462 ms |
228632 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
657 ms |
238584 KB |
Output is correct |
2 |
Correct |
261 ms |
243648 KB |
Output is correct |
3 |
Correct |
272 ms |
220980 KB |
Output is correct |
4 |
Correct |
970 ms |
252324 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
882 ms |
248312 KB |
Output is correct |
2 |
Correct |
1430 ms |
255872 KB |
Output is correct |
3 |
Correct |
501 ms |
233728 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
739 ms |
241216 KB |
Output is correct |
2 |
Runtime error |
1628 ms |
262144 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1079 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
963 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
559 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |