This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int N=1000001;
ll t[2000002];
ll d[1000001];
int h;
void apply(int p,ll val)
{
t[p]+=val;
if(p<N) d[p]+=val;
}
void build(int p)
{
while(p>1){p/=2; t[p]=min(t[2*p],t[2*p+1])+d[p];}
}
void push(int p)
{
for(int s=h;s>0;s--)
{
int i=(p>>s);
if(d[i]!=0)
{
apply(2*i,d[i]);
apply(2*i+1,d[i]);
d[i]=0;
}
}
}
void update(int l,int r,ll val)
{
l+=N; r+=(N+1);
int l0=l,r0=r;
for(;l<r;l/=2,r/=2)
{
if(l&1) apply(l++,val);
if(r&1) apply(--r,val);
}
build(l0);
build(r0-1);
}
ll query(int l,int r)
{
l+=N; r+=(N+1);
push(l);
push(r-1);
ll res=(1ll<<32);
for(;l<r;l/=2,r/=2)
{
if(l&1) res=min(res,t[l++]);
if(r&1) res=min(res,t[--r]);
}
return res;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int n,m;
cin >> m >> n;
int b,p;
cin >> b >> p;
vector<array<int,5>> obstacles(p);
for(auto &[x1,y1,x2,y2,c]:obstacles) cin >> x1 >> y1 >> x2 >> y2 >> c;
int l=0,r=min(n,m)+1;
vector<array<int,3>> v[m+2];
while(l<r-1)
{
int len=(l+r)/2;
bool ok=0;
int limm=m-len+1;
int limn=n-len+1;
N=limn;
h=32-__builtin_clz(N);
auto add=[&](int x1,int y1,int x2,int y2,int c)
{
v[x1].push_back({y1,y2,c});
v[x2+1].push_back({y1,y2,-c});
};
for(auto [x1,y1,x2,y2,c]:obstacles) add(max(1,x1-len+1),max(1,y1-len+1),min(x2,limm),min(y2,limn),c);
for(int x=1;x<=limm+1;x++)
{
for(auto [y1,y2,c]:v[x]) update(y1,y2,c);
if(x<=limm) ok|=(query(1,limn)<=b);
v[x].clear();
}
if(ok) l=len;
else r=len;
}
cout << l << "\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |