#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
namespace S1
{
const int N=1000005;
ll tree[4*N];
ll lazy[4*N];
void pull(int idx){tree[idx]=min(tree[2*idx],tree[2*idx+1]);}
void apply(int idx,ll x){tree[idx]+=x; lazy[idx]+=x;}
void push(int idx){for(int i=0;i<2;i++)apply(2*idx+i,lazy[idx]); lazy[idx]=0;}
void update(int idx,int l,int r,int ql,int qr,int x)
{
if(ql>qr) return;
if(l==ql&&r==qr) apply(idx,ll(x));
else
{
int m=(l+r)/2;
push(idx);
update(2*idx,l,m,ql,min(qr,m),x);
update(2*idx+1,m+1,r,max(ql,m+1),qr,x);
pull(idx);
}
}
}
namespace S2
{
const int N=1000005;
struct node
{
int sz;
int mn,len;
int lx,lc,rx,rc;
int lazy;
void ini(int s){sz=s; mn=lx=rx=0; len=lc=rc=s; lazy=0;}
friend node merge(node &a,node &b)
{
node c;
c.sz=a.sz+b.sz;
c.mn=min(a.mn,b.mn);
c.len=0;
if(a.mn==c.mn) c.len=max(c.len,a.len);
if(b.mn==c.mn) c.len=max(c.len,b.len);
if(a.rx==c.mn&&b.lx==c.mn) c.len=max(c.len,a.rc+b.lc);
c.lx=a.lx;
c.lc=(a.lc<a.sz?a.lc:a.lc+(a.lx==b.lx)*b.lc);
c.rx=b.rx;
c.rc=(b.rc<b.sz?b.rc:b.rc+(a.rx==b.rx)*a.rc);
c.lazy=0;
return c;
}
void apply(int x){mn+=x; lx+=x; rx+=x; lazy+=x;}
void push(node &a,node &b){a.apply(lazy); b.apply(lazy); lazy=0;}
};
vector<node> tree(4*N);
void build(int idx,int l,int r)
{
tree[idx].ini(r-l+1);
if(l<r)
{
int m=(l+r)/2;
build(2*idx,l,m);
build(2*idx+1,m+1,r);
}
}
void pull(int idx){tree[idx]=merge(tree[2*idx],tree[2*idx+1]);}
void apply(int idx,int x){tree[idx].apply(x);}
void push(int idx){tree[idx].push(tree[2*idx],tree[2*idx+1]);}
void update(int idx,int l,int r,int ql,int qr,int x)
{
if(ql>qr) return;
if(l==ql&&r==qr) apply(idx,x);
else
{
int m=(l+r)/2;
push(idx);
update(2*idx,l,m,ql,min(qr,m),x);
update(2*idx+1,m+1,r,max(ql,m+1),qr,x);
pull(idx);
}
}
}
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;
if(b>0)
{
using namespace S1;
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;
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(1,1,limn,y1,y2,c);
if(x<=limm) ok|=(tree[1]<=b);
v[x].clear();
}
if(ok) l=len;
else r=len;
}
cout << l << "\n";
}
else
{
using namespace S2;
int res=0;
build(1,1,n);
auto f=[&]()->int{return (tree[1].mn==0)*tree[1].len;};
vector<array<int,2>> l[m+1],r[m+1];
for(auto [x1,y1,x2,y2,c]:obstacles)
{
l[x1].push_back({y1,y2});
r[x2].push_back({y1,y2});
}
int g=0;
for(int i=1;i<=m;i++)
{
while(g+1<=m&&f()>=g-i+1)
{
res=max(res,g-i+1);
g++;
for(auto [y1,y2]:l[g]) update(1,1,n,y1,y2,1);
}
for(auto [y1,y2]:r[i]) update(1,1,n,y1,y2,-1);
}
cout << res << "\n";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
58 ms |
125516 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
60 ms |
125464 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
61 ms |
125652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
59 ms |
126088 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
78 ms |
130332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
101 ms |
172632 KB |
Output is correct |
2 |
Correct |
96 ms |
172608 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
105 ms |
172644 KB |
Output is correct |
2 |
Correct |
100 ms |
172580 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
75 ms |
127336 KB |
Output is correct |
2 |
Correct |
100 ms |
127128 KB |
Output is correct |
3 |
Correct |
95 ms |
127180 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
305 ms |
135980 KB |
Output is correct |
2 |
Correct |
367 ms |
135880 KB |
Output is correct |
3 |
Correct |
335 ms |
136136 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
402 ms |
173852 KB |
Output is correct |
2 |
Correct |
145 ms |
154396 KB |
Output is correct |
3 |
Correct |
327 ms |
161576 KB |
Output is correct |
4 |
Correct |
899 ms |
192488 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
710 ms |
193008 KB |
Output is correct |
2 |
Correct |
937 ms |
194660 KB |
Output is correct |
3 |
Correct |
205 ms |
174112 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
517 ms |
177044 KB |
Output is correct |
2 |
Correct |
1282 ms |
197044 KB |
Output is correct |
3 |
Correct |
1170 ms |
196784 KB |
Output is correct |
4 |
Correct |
1265 ms |
197140 KB |
Output is correct |
5 |
Correct |
1204 ms |
197076 KB |
Output is correct |
6 |
Correct |
140 ms |
175192 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
707 ms |
190576 KB |
Output is correct |
2 |
Correct |
394 ms |
187904 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
888 ms |
197824 KB |
Output is correct |
2 |
Correct |
889 ms |
199612 KB |
Output is correct |
3 |
Correct |
595 ms |
150600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1027 ms |
204352 KB |
Output is correct |
2 |
Correct |
1228 ms |
210228 KB |
Output is correct |
3 |
Incorrect |
1218 ms |
210088 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |