QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#551105 | #3024. Zoning Houses | Phantom Threshold (Jiachen Tang, Changdong Li, Weinuo Li)# | AC ✓ | 271ms | 14192kb | C++20 | 2.7kb | 2024-09-07 15:28:46 | 2024-09-07 15:28:46 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
struct info
{
int mx[4];//xmax,xmin,ymax,ymin
int id[4];
info operator+(const info &k)const
{
info ret;
if(mx[0]<k.mx[0])
{
ret.mx[0]=k.mx[0];
ret.id[0]=k.id[0];
}
else
{
ret.mx[0]=mx[0];
ret.id[0]=id[0];
}
if(mx[1]>k.mx[1])
{
ret.mx[1]=k.mx[1];
ret.id[1]=k.id[1];
}
else
{
ret.mx[1]=mx[1];
ret.id[1]=id[1];
}
if(mx[2]<k.mx[2])
{
ret.mx[2]=k.mx[2];
ret.id[2]=k.id[2];
}
else
{
ret.mx[2]=mx[2];
ret.id[2]=id[2];
}
if(mx[3]>k.mx[3])
{
ret.mx[3]=k.mx[3];
ret.id[3]=k.id[3];
}
else
{
ret.mx[3]=mx[3];
ret.id[3]=id[3];
}
return ret;
}
};
const int N=233333;
const int inf=0x7f7f7f7f;
info seg[N+5];
int lson[N+5],rson[N+5];
int root,top;
int x[N+5],y[N+5];
int build(int l,int r)
{
int ret=++top;
if(l<r)
{
int mid=(l+r)/2;
ret[lson]=build(l,mid);
ret[rson]=build(mid+1,r);
ret[seg]=ret[lson][seg]+ret[rson][seg];
}
else
{
ret[seg].mx[0]=ret[seg].mx[1]=x[l];
ret[seg].mx[2]=ret[seg].mx[3]=y[l];
ret[seg].id[0]=ret[seg].id[1]=ret[seg].id[2]=ret[seg].id[3]=l;
}
return ret;
}
info query(int cur,int l,int r,int ql,int qr)
{
if(l==ql and r==qr)
{
return cur[seg];
}
int mid=(l+r)/2;
if(qr<=mid)return query(cur[lson],l,mid,ql,qr);
else if(ql>=mid+1)return query(cur[rson],mid+1,r,ql,qr);
else return query(cur[lson],l,mid,ql,mid)+query(cur[rson],mid+1,r,mid+1,qr);
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
int n,q;
cin>>n>>q;
for(int i=1;i<=n;i++)
{
cin>>x[i]>>y[i];
}
root=build(1,n);
for(int i=1;i<=q;i++)
{
int l,r;
cin>>l>>r;
int tans=inf;
auto u=query(root,1,n,l,r);
for(int j=0;j<4;j++)
{
int pos=u.id[j];
info ans;
ans.mx[0]=ans.mx[2]=-inf;
ans.mx[1]=ans.mx[3]=inf;
if(l<pos)
ans=ans+query(root,1,n,l,pos-1);
if(pos<r)
ans=ans+query(root,1,n,pos+1,r);
tans=min(tans,max(ans.mx[0]-ans.mx[1],ans.mx[2]-ans.mx[3]));
}
cout<<tans<<"\n";
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5712kb
input:
3 2 1 0 0 1 1000 1 1 3 2 3
output:
1 0
result:
ok 2 number(s): "1 0"
Test #2:
score: 0
Accepted
time: 1ms
memory: 5608kb
input:
4 2 0 0 1000 1000 300 300 1 1 1 3 2 4
output:
300 299
result:
ok 2 number(s): "300 299"
Test #3:
score: 0
Accepted
time: 1ms
memory: 5616kb
input:
4 6 0 1 1 3 2 0 3 2 1 3 2 3 2 4 1 2 3 4 1 4
output:
2 0 2 0 0 3
result:
ok 6 numbers
Test #4:
score: 0
Accepted
time: 1ms
memory: 7740kb
input:
8 28 0 1 0 2 3 1 3 2 1 0 2 0 1 3 2 3 4 8 1 2 3 5 2 4 1 5 3 8 2 8 3 4 5 7 7 8 2 5 4 5 2 6 4 6 1 8 1 7 2 7 1 3 6 7 3 7 1 4 4 7 3 6 1 6 6 8 2 3 5 8 5 6
output:
3 0 1 1 3 3 3 0 1 0 2 0 2 1 3 3 3 1 0 2 3 2 2 3 1 0 3 0
result:
ok 28 numbers
Test #5:
score: 0
Accepted
time: 1ms
memory: 7644kb
input:
6 15 100 20 50 30 49 0 0 20 0 10 100 10 1 3 1 4 3 6 3 4 2 6 3 5 1 6 2 3 5 6 4 6 4 5 2 5 2 4 1 2 1 5
output:
30 50 49 0 50 10 100 0 0 10 0 49 30 0 50
result:
ok 15 numbers
Test #6:
score: 0
Accepted
time: 1ms
memory: 5620kb
input:
6 15 20 100 30 50 0 49 20 0 10 0 10 100 3 6 1 4 1 3 5 6 4 5 3 4 3 5 1 5 2 3 2 4 1 6 4 6 2 6 2 5 1 2
output:
49 50 30 0 0 0 10 50 0 30 100 10 50 49 0
result:
ok 15 numbers
Test #7:
score: 0
Accepted
time: 0ms
memory: 3640kb
input:
6 15 100 80 0 0 100 0 0 80 10 10 30 10 3 6 2 6 1 3 2 4 1 5 1 4 4 5 3 4 1 6 4 6 2 3 1 2 3 5 5 6 2 5
output:
70 80 80 80 100 100 0 0 100 20 0 0 70 0 80
result:
ok 15 numbers
Test #8:
score: 0
Accepted
time: 1ms
memory: 7796kb
input:
6 15 80 100 0 0 0 100 80 0 10 10 10 30 2 3 5 6 2 5 1 3 1 5 1 4 4 5 4 6 3 4 1 2 3 5 2 6 3 6 2 4 1 6
output:
0 0 80 80 100 100 0 20 0 0 70 80 70 80 100
result:
ok 15 numbers
Test #9:
score: 0
Accepted
time: 83ms
memory: 5692kb
input:
400 79800 18 1 12 17 3 8 15 6 12 1 4 8 12 5 15 1 3 19 3 7 5 6 18 0 16 4 1 12 19 17 2 16 4 15 8 9 10 10 8 0 11 7 1 13 12 19 5 5 17 11 5 2 8 2 14 19 16 7 16 12 1 15 14 2 18 6 9 12 5 3 2 1 15 4 6 13 5 8 7 1 18 3 4 7 4 9 19 10 13 3 5 15 7 18 8 10 5 12 0 12 17 13 1 19 14 10 13 8 16 9 6 4 9 1 13 2 10 3 7 ...
output:
19 19 19 19 19 19 19 19 19 19 19 19 19 15 19 19 19 12 19 19 19 19 19 19 19 19 19 19 19 19 19 17 19 19 19 18 19 19 19 19 19 19 19 19 19 19 19 19 19 9 19 17 18 19 19 19 19 19 19 19 19 19 19 19 14 13 19 19 5 19 19 19 19 19 19 19 19 0 18 19 19 19 19 19 19 19 19 17 19 5 19 17 19 19 19 0 19 19 19 19 19 19...
result:
ok 79800 numbers
Test #10:
score: 0
Accepted
time: 191ms
memory: 14192kb
input:
100000 99996 0 0 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 8 0 9 0 10 0 11 0 12 0 13 0 14 0 15 0 16 0 17 0 18 0 19 0 20 0 21 0 22 0 23 0 24 0 25 0 26 0 27 0 28 0 29 0 30 0 31 0 32 0 33 0 34 0 35 0 36 0 37 0 38 0 39 0 40 0 41 0 42 0 43 0 44 0 45 0 46 0 47 0 48 0 49 0 50 0 51 0 52 0 53 0 54 0 55 0 56 0 57 0 58 0 ...
output:
999 999 999 999 999 999 999 999 999 999 999 999 999 999 999 999 999 999 999 999 999 999 999 999 999 999 999 999 999 999 999 999 999 999 998 999 999 999 999 999 999 999 999 999 999 999 999 999 378 998 999 999 999 999 999 999 999 999 999 999 999 999 998 998 999 999 999 999 998 998 999 999 999 999 999 ...
result:
ok 99996 numbers
Test #11:
score: 0
Accepted
time: 198ms
memory: 14188kb
input:
100000 99997 0 0 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 8 0 9 0 10 0 11 0 12 0 13 0 14 0 15 0 16 0 17 0 18 0 19 0 20 0 21 0 22 0 23 0 24 0 25 0 26 0 27 0 28 0 29 0 30 0 31 0 32 0 33 0 34 0 35 0 36 0 37 0 38 0 39 0 40 0 41 0 42 0 43 0 44 0 45 0 46 0 47 0 48 0 49 0 50 0 51 0 52 0 53 0 54 0 55 0 56 0 57 0 58 0 ...
output:
99 832 616 99 378 392 580 99 730 382 164 133 253 444 427 405 99 99 699 109 99 336 118 544 405 348 345 334 99 513 165 781 99 234 635 159 278 150 506 375 734 123 126 259 158 357 261 99 671 577 367 172 512 99 99 99 676 149 435 99 99 99 490 320 190 215 108 174 225 241 973 281 150 504 205 256 378 277 751...
result:
ok 99997 numbers
Test #12:
score: 0
Accepted
time: 271ms
memory: 12996kb
input:
100000 99995 -560503114 775639741 -414293351 -547361889 -89816875 416783478 354863777 639273005 742857133 735843002 735048967 731105561 -260694369 -89407316 -4536805 206228327 -651840538 142687735 341872164 155276150 -534562261 184488125 -61124016 402135121 709610603 652212586 499499561 778614734 -6...
output:
1999953414 1999941292 1999947469 1999947469 1999915835 1999915835 1999941292 1999829499 1999915835 1999945194 1999829499 1999923357 1999923357 1999947237 1999953414 1999930063 1994894974 1999755742 1999941292 1999820444 1999941292 1999947469 1999524085 1999930063 1999915835 1999814416 1999526826 199...
result:
ok 99995 numbers
Test #13:
score: 0
Accepted
time: 222ms
memory: 14096kb
input:
100000 99997 1 1 1 0 0 1 0 0 0 3 0 2 1 3 1 2 1 5 0 4 0 5 1 4 0 7 1 6 0 6 1 7 0 9 1 8 1 9 0 8 1 10 1 11 0 11 0 10 1 13 0 13 0 12 1 12 1 15 1 14 0 14 0 15 1 16 1 17 0 17 0 16 1 19 0 18 0 19 1 18 1 20 0 21 0 20 1 21 0 22 0 23 1 23 1 22 1 25 1 24 0 24 0 25 1 27 0 27 1 26 0 26 0 29 0 28 1 29 1 28 1 30 1 ...
output:
499 499 499 499 499 499 499 499 499 499 499 499 499 499 499 499 499 499 499 499 499 499 499 499 499 499 499 499 499 499 499 499 389 499 499 499 499 499 499 499 499 499 499 499 499 499 499 499 499 499 499 499 499 499 499 499 499 499 499 499 499 499 499 499 499 499 499 499 499 499 499 499 499 499 499 ...
result:
ok 99997 numbers