QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#416920 | #8711. Tiles | vme50# | 29 | 49ms | 21432kb | C++17 | 3.6kb | 2024-05-22 11:08:35 | 2024-05-22 11:08:36 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mid ((l+r)/2)
#define db double
const int N=1e6+5,INF=1e9;
int n,m,tp,ans,cnt[4],x[N],y[N],ds[N];struct Event {int tim,l,r;}a[N];
int rt,cntS;struct Seg {int vl,ch[2];bool tg;}sg[N*4];
struct Node {int tim,l,r,vl,vl1;};
bool operator < (Node x,Node y) {return x.r<y.r;};set<Node> z;
void fail() {printf("%d\n",ans);exit(0);}
int f(int x,int y) {if(x==-1) return y;if(y==-1) return x;if(x!=y) fail();return x;}
void pu(int p) {sg[p].vl=sg[sg[p].ch[0]].vl+sg[sg[p].ch[1]].vl;}
void mdf(int p,int l,int r) {sg[p].vl=ds[r+1]-ds[l]-sg[p].vl+1;sg[p].tg^=1;}
void pd(int p,int l,int r)
{
if(!sg[p].ch[0]) sg[p].ch[0]=++cntS;if(!sg[p].ch[1]) sg[p].ch[1]=++cntS;
if(sg[p].tg) mdf(sg[p].ch[0],l,mid),mdf(sg[p].ch[1],mid+1,r),sg[p].tg=0;
}
void upd(int &p,int l,int r,int qL,int qR)
{
if(ds[l]>qR || ds[r+1]<=qL) return; if(!p) p=++cntS;
if(ds[l]>=qL && ds[r+1]<qR) {mdf(p,l,r);return;}pd(p,l,r);
upd(sg[p].ch[0],l,mid,qL,qR);upd(sg[p].ch[1],mid+1,r,qL,qR);pu(p);
}
int qry(int p,int l,int r,int qL,int qR)
{
if(ds[l]>qR || ds[r+1]<qL || !p) return 0;
if(ds[l]>=qL && ds[r+1]<qR) return sg[p].vl;pd(p,l,r);
return qry(sg[p].ch[0],l,mid,qL,qR)+qry(sg[p].ch[1],mid+1,r,qL,qR);
}
void upd1(Node &x,int vl)
{
if(x.vl1==-1)
{
if(x.r-x.l&1) x.vl1=3;else if(x.vl==-1) x.vl1=x.tim&1;
else if((x.l^x.vl)&1) x.vl1=3;
else if(qry(rt,1,tp,x.l,x.r-1)==x.r-x.l) x.vl1=(x.tim&1)^1;
else x.vl1=2;
}cnt[x.vl1]+=vl;
}
void upd2(int tim,Node &x)
{
if(tim-x.tim&1) upd(rt,1,tp,x.l,x.r-1);
if(x.vl==-1) x.vl=x.l&1;if(!qry(rt,1,tp,x.l,x.r-1)) x.vl=-1;
}
void ins(int tim,int l,int r)
{
// printf("ins %d %d %d\n",tim,l,r);
Node t=(Node) {tim,l,r,-1,-1};auto it=z.lower_bound(t);
if(it!=z.end() && l>=it->l && r<=it->r)
{
Node t1=*it;upd1(t1,-1);upd2(tim,t1);z.erase(it);
if(qry(rt,1,tp,l,r-1)) fail();
t.l=t1.l;t.r=l;t.vl=t1.vl;t.vl1=-1;
if(t.l<t.r) {if(!qry(rt,1,tp,t.l,t.r-1)) t.vl=-1;upd1(t,1);z.insert(t);}
t.l=r;t.r=t1.r;t.vl=t1.vl;t.vl1=-1;
if(t.l<t.r) {if(!qry(rt,1,tp,t.l,t.r-1)) t.vl=-1;upd1(t,1);z.insert(t);}
return;
}
if(it!=z.end() && r==it->l)
{
Node t1=*it;upd1(t1,-1);upd2(tim,t1);z.erase(it);
t.r=t1.r;t.vl=f(t.vl,t1.vl);
}
it=z.lower_bound(t);
if(it!=z.begin() && l==(it=prev(it))->r)
{
Node t1=*it;upd1(t1,-1);upd2(tim,t1);z.erase(it);
t.l=t1.l;t.vl=f(t.vl,t1.vl);
}if(t.l<t.r) upd1(t,1),z.insert(t);
}
int main()
{
scanf("%d %*d",&n);for(int i=1;i<=n;++i) scanf("%d %d",&x[i],&y[i]);
x[n+1]=x[1];y[n+1]=y[1];
for(int i=1;i<=n;++i) if(x[i]==x[i+1])
a[++m]=(Event) {x[i],min(y[i],y[i+1]),max(y[i],y[i+1])};
for(int i=1;i<=m;++i) ds[++tp]=a[i].l,ds[++tp]=a[i].r;
sort(ds+1,ds+tp+1);tp=unique(ds+1,ds+tp+1)-ds-1;ds[tp+1]=INF+1;
sort(a+1,a+m+1,[](Event x,Event y) {return x.tim<y.tim;});
for(int i=1;i<m;++i)
{
ins(a[i].tim,a[i].l,a[i].r);
// printf("z=");
// for(auto j:z) printf("(%d %d %d %d)",j.tim,j.l,j.r,j.vl);putchar('\n');
if(a[i].tim!=a[i+1].tim)
{
// printf("cnt=%d %d %d %d\n",cnt[0],cnt[1],cnt[2],cnt[3]);
if(cnt[3]) fail();
if(!cnt[2])
{
if(!cnt[0]) ans=max(ans,a[i+1].tim-(!(a[i+1].tim&1)));
if(!cnt[1]) ans=max(ans,a[i+1].tim-(a[i+1].tim&1));
}
}
}fail();return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 4
Accepted
Test #1:
score: 4
Accepted
time: 2ms
memory: 12172kb
input:
4 3 0 0 0 3 3 3 3 0
output:
0
result:
ok single line: '0'
Test #2:
score: 0
Accepted
time: 2ms
memory: 12040kb
input:
4 999999999 999999999 0 999999999 1000000000 0 1000000000 0 0
output:
999999998
result:
ok single line: '999999998'
Test #3:
score: 0
Accepted
time: 0ms
memory: 12136kb
input:
4 875 875 0 0 0 0 284 875 284
output:
874
result:
ok single line: '874'
Test #4:
score: 0
Accepted
time: 0ms
memory: 12048kb
input:
4 317 317 0 317 920 0 920 0 0
output:
316
result:
ok single line: '316'
Test #5:
score: 0
Accepted
time: 2ms
memory: 12124kb
input:
4 912 912 814 912 0 0 0 0 814
output:
912
result:
ok single line: '912'
Test #6:
score: 0
Accepted
time: 0ms
memory: 12132kb
input:
4 2 0 0 0 1 2 1 2 0
output:
0
result:
ok single line: '0'
Test #7:
score: 0
Accepted
time: 0ms
memory: 12088kb
input:
4 1 0 0 0 1 1 1 1 0
output:
0
result:
ok single line: '0'
Test #8:
score: 0
Accepted
time: 2ms
memory: 11996kb
input:
4 412 412 998 0 998 0 17 412 17
output:
0
result:
ok single line: '0'
Test #9:
score: 0
Accepted
time: 2ms
memory: 12180kb
input:
4 87523458 87523458 42385699 0 42385699 0 23498231 87523458 23498231
output:
87523458
result:
ok single line: '87523458'
Test #10:
score: 0
Accepted
time: 0ms
memory: 12168kb
input:
4 1 0 0 0 1000000000 1 1000000000 1 0
output:
0
result:
ok single line: '0'
Test #11:
score: 0
Accepted
time: 0ms
memory: 12168kb
input:
4 1000000000 1000000000 0 1000000000 1000000000 0 1000000000 0 0
output:
1000000000
result:
ok single line: '1000000000'
Subtask #2:
score: 0
Memory Limit Exceeded
Dependency #1:
100%
Accepted
Test #12:
score: 9
Accepted
time: 2ms
memory: 12048kb
input:
5 29034873 29034873 13721 0 13721 0 99198237 29034870 99198237 29034873 99198237
output:
29034872
result:
ok single line: '29034872'
Test #13:
score: 0
Accepted
time: 2ms
memory: 12132kb
input:
6 999999993 2934870 21349 2934870 3423847 0 3423847 0 91827393 999999993 91827393 999999993 21349
output:
999999992
result:
ok single line: '999999992'
Test #14:
score: -9
Memory Limit Exceeded
input:
6 401 153 409 153 751 0 751 0 909 401 909 401 409
output:
result:
Subtask #3:
score: 0
Memory Limit Exceeded
Test #32:
score: 0
Memory Limit Exceeded
input:
1551 1000 0 988 2 988 3 988 6 988 6 985 6 982 6 981 6 979 6 978 6 977 6 976 6 975 6 974 6 972 6 970 6 969 6 968 6 966 6 965 6 964 7 964 8 964 8 963 8 961 8 960 10 960 11 960 13 960 16 960 16 959 16 958 16 957 16 954 16 953 16 951 16 950 17 950 18 950 18 948 18 946 18 945 18 944 18 942 18 941 18 939 ...
output:
result:
Subtask #4:
score: 0
Memory Limit Exceeded
Test #45:
score: 19
Accepted
time: 2ms
memory: 12036kb
input:
14 6 0 1 0 3 2 3 2 4 0 4 0 6 3 6 3 7 4 7 6 7 6 5 3 5 3 2 3 1
output:
2
result:
ok single line: '2'
Test #46:
score: -19
Memory Limit Exceeded
input:
18 9 0 2 2 2 2 1 4 1 4 0 9 0 9 2 4 2 4 4 7 4 7 3 9 3 9 6 4 6 4 5 2 5 2 4 0 4
output:
result:
Subtask #5:
score: 0
Runtime Error
Test #89:
score: 0
Runtime Error
input:
199996 198506138 31225688 248200160 31225688 248291950 28995282 248291950 28995282 248200160 26764876 248200160 26764876 248291950 24534470 248291950 24534470 248200160 22304064 248200160 22304064 248291950 20073658 248291950 20073658 248200160 17843252 248200160 17843252 248291950 15612846 24829195...
output:
result:
Subtask #6:
score: 25
Accepted
Test #118:
score: 25
Accepted
time: 35ms
memory: 14176kb
input:
200000 1000000000 1000000000 0 999990876 0 999990876 38 999972524 38 999972524 1510 999969180 1510 999969180 3734 999964780 3734 999964780 4138 999960464 4138 999960464 11052 999953728 11052 999953728 24478 999914972 24478 999914972 25892 999909864 25892 999909864 28102 999902920 28102 999902920 301...
output:
40502
result:
ok single line: '40502'
Test #119:
score: 0
Accepted
time: 47ms
memory: 19252kb
input:
200000 778696306 22822858 87970191 330038016 87970191 330038016 87957657 259262362 87957657 259262362 87923225 316313936 87923225 316313936 87896643 155653960 87896643 155653960 87890367 184851800 87890367 184851800 87877609 93595576 87877609 93595576 87838069 384366344 87838069 384366344 87822439 3...
output:
298364980
result:
ok single line: '298364980'
Test #120:
score: 0
Accepted
time: 39ms
memory: 14176kb
input:
199996 939450484 183372590 726043385 183372590 947636904 183351398 947636904 183351398 585647776 183326398 585647776 183326398 815654133 183324414 815654133 183324414 681316487 183304068 681316487 183304068 993350372 183281288 993350372 183281288 748476649 183258832 748476649 183258832 772289334 183...
output:
158652
result:
ok single line: '158652'
Test #121:
score: 0
Accepted
time: 26ms
memory: 14212kb
input:
200000 1000000000 851050592 949600024 851052652 949600024 851052652 949609374 851074804 949609374 851074804 949619690 851079480 949619690 851079480 949621292 851099180 949621292 851099180 949623446 851108076 949623446 851108076 949624656 851108300 949624656 851108300 949626322 851114392 949626322 85...
output:
0
result:
ok single line: '0'
Test #122:
score: 0
Accepted
time: 16ms
memory: 14040kb
input:
200000 1000000000 563456704 374947039 563456704 374927074 563408574 374927074 563408574 374916426 563395120 374916426 563395120 374901323 563377364 374901323 563377364 374886390 563372770 374886390 563372770 374876185 563370378 374876185 563370378 374859944 563361728 374859944 563361728 374858704 56...
output:
317583084
result:
ok single line: '317583084'
Test #123:
score: 0
Accepted
time: 38ms
memory: 16284kb
input:
199999 96699482 32621512 407805930 31456458 407805930 31456458 407659920 30291404 407659920 30291404 408097950 31456458 408097950 31456458 407951940 32621512 407951940 32621512 408097950 33786566 408097950 33786566 407951940 34951620 407951940 34951620 408097950 36116674 408097950 36116674 407951940...
output:
96699482
result:
ok single line: '96699482'
Test #124:
score: 0
Accepted
time: 46ms
memory: 14280kb
input:
199991 628378890 454249800 18408156 461820630 18408156 461820630 18371848 469391460 18371848 469391460 18408156 476962290 18408156 476962290 18371848 484533120 18371848 484533120 18408156 492103950 18408156 492103950 18371848 499674780 18371848 499674780 18408156 507245610 18408156 507245610 1837184...
output:
597872006
result:
ok single line: '597872006'
Test #125:
score: 0
Accepted
time: 42ms
memory: 18268kb
input:
199991 411269100 304822980 10387669 304822980 10334399 309661440 10334399 309661440 10387669 314499900 10387669 314499900 10334399 319338360 10334399 319338360 10387669 324176820 10387669 324176820 10334399 329015280 10334399 329015280 10387669 333853740 10387669 333853740 10334399 338692200 1033439...
output:
409773014
result:
ok single line: '409773014'
Test #126:
score: 0
Accepted
time: 49ms
memory: 21432kb
input:
200000 1000000000 0 0 2 0 2 7506 999900202 7506 999900202 7508 99800 7508 99800 8994 999900204 8994 999900204 8996 99798 8996 99798 16558 999900206 16558 999900206 16560 99796 16560 99796 32318 999900208 32318 999900208 32320 99794 32320 99794 35116 999900210 35116 999900210 35118 99792 35118 99792 ...
output:
999966026
result:
ok single line: '999966026'
Test #127:
score: 0
Accepted
time: 44ms
memory: 21388kb
input:
200000 1000000000 0 0 2 0 2 15124 999900202 15124 999900202 15126 99800 15126 99800 28330 999900204 28330 999900204 28332 99798 28332 99798 33696 999900206 33696 999900206 33698 99796 33698 99796 43952 999900208 43952 999900208 43954 99794 43954 99794 46390 999900210 46390 999900210 46392 99792 4639...
output:
999961970
result:
ok single line: '999961970'
Test #128:
score: 0
Accepted
time: 40ms
memory: 19380kb
input:
200000 1000000000 0 0 2 0 2 17910 999900202 17910 999900202 17912 99800 17912 99800 29854 999900204 29854 999900204 29856 99798 29856 99798 32692 999900206 32692 999900206 32694 99796 32694 99796 41542 999900208 41542 999900208 41544 99794 41544 99794 45142 999900210 45142 999900210 45144 99792 4514...
output:
999966092
result:
ok single line: '999966092'
Test #129:
score: 0
Accepted
time: 12ms
memory: 12132kb
input:
100624 506028352 0 8751 9104 8751 9104 32159 12966 32159 12966 45070 50526 45070 50526 58152 64694 58152 64694 99309 66288 99309 66288 142125 91496 142125 91496 147329 96042 147329 96042 149406 130818 149406 130818 174885 163952 174885 163952 187058 167450 187058 167450 207028 208448 207028 208448 2...
output:
506028352
result:
ok single line: '506028352'
Test #130:
score: 0
Accepted
time: 0ms
memory: 12128kb
input:
12 238947238 8922 63488 8922 123 92348756 123 92348756 63488 238947238 63488 238947238 3474740 92348756 3474740 92348756 845673459 8922 845673459 8922 3474740 0 3474740 0 63488
output:
238947238
result:
ok single line: '238947238'
Test #131:
score: 0
Accepted
time: 22ms
memory: 14116kb
input:
100532 502940770 0 15447 122642 15447 122642 30295 176092 30295 176092 37938 214052 37938 214052 42195 239082 42195 239082 42698 242510 42698 242510 52373 258142 52373 258142 56745 260132 56745 260132 85113 280290 85113 280290 141795 303652 141795 303652 155321 327606 155321 327606 158599 333920 158...
output:
502940770
result:
ok single line: '502940770'
Subtask #7:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%