QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#416929 | #8711. Tiles | _set_# | 0 | 45ms | 51460kb | C++17 | 4.7kb | 2024-05-22 11:15:44 | 2024-05-22 11:15:47 |
Judging History
answer
// what is matter? never mind.
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,sse4,popcnt,abm,mmx,avx,avx2")
#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(int i=(a);i>=(b);--i)
#define ll long long
//#define int __int128
//#define ull unsigned long long
#define SZ(x) ((int)((x).size()))
#define ALL(x) (x).begin(),(x).end()
using namespace std;
inline int read()
{
char c=getchar();int x=0;bool f=0;
for(;!isdigit(c);c=getchar())f^=!(c^45);
for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
if(f)x=-x;return x;
}
#define mod 1000000007
struct modint{
int x;
modint(int o=0){x=o;}
modint &operator = (int o){return x=o,*this;}
modint &operator +=(modint o){return x=x+o.x>=mod?x+o.x-mod:x+o.x,*this;}
modint &operator -=(modint o){return x=x-o.x<0?x-o.x+mod:x-o.x,*this;}
modint &operator *=(modint o){return x=1ll*x*o.x%mod,*this;}
modint &operator ^=(int b){
modint a=*this,c=1;
for(;b;b>>=1,a*=a)if(b&1)c*=a;
return x=c.x,*this;
}
modint &operator /=(modint o){return *this *=o^=mod-2;}
friend modint operator +(modint a,modint b){return a+=b;}
friend modint operator -(modint a,modint b){return a-=b;}
friend modint operator *(modint a,modint b){return a*=b;}
friend modint operator /(modint a,modint b){return a/=b;}
friend modint operator ^(modint a,int b){return a^=b;}
friend bool operator ==(modint a,modint b){return a.x==b.x;}
friend bool operator !=(modint a,modint b){return a.x!=b.x;}
bool operator ! () {return !x;}
modint operator - () {return x?mod-x:0;}
bool operator <(const modint&b)const{return x<b.x;}
};
inline modint qpow(modint x,int y){return x^y;}
vector<modint> fac,ifac,iv;
inline void initC(int n)
{
if(iv.empty())fac=ifac=iv=vector<modint>(2,1);
int m=iv.size(); ++n;
if(m>=n)return;
iv.resize(n),fac.resize(n),ifac.resize(n);
For(i,m,n-1){
iv[i]=iv[mod%i]*(mod-mod/i);
fac[i]=fac[i-1]*i,ifac[i]=ifac[i-1]*iv[i];
}
}
inline modint C(int n,int m){
if(m<0||n<m)return 0;
return initC(n),fac[n]*ifac[m]*ifac[n-m];
}
inline modint sign(int n){return (n&1)?(mod-1):(1);}
#define fi first
#define se second
#define pb push_back
#define mkp make_pair
typedef pair<int,int>pii;
typedef vector<int>vi;
#define maxn 200005
#define inf 0x3f3f3f3f
int n,m;
int x[maxn],y[maxn],t[maxn],tx[maxn],lx;
vector<pii>buc[maxn];
struct info{
int l,r;
bool f[2][2];
info(){
l=r=-1;
memset(f,0,sizeof f);
}
};
//
info gen(int l,int r,int y){
info t;
if(!y){
For(i,0,1) t.f[i][i]=1;
t.l=-1;
t.r=-1;
}else{
t.l=l,t.r=r;
For(i,0,1) For(j,0,1) t.f[i][j]=((i==j)==((r-l+1)%2==0));
}
return t;
}
info merge(info a,info b){
if(a.l==-1) return b;
if(b.l==-1) return a;
info c;
c.l=a.l,c.r=b.r;
For(x,0,1)
For(y,0,1) if(a.f[x][y] && (!y||a.r+1==b.l))
For(z,0,1)
if(b.f[y][z]) c.f[x][z]=1;
return c;
}
struct segt{
info tr[maxn<<2][2];
bool rev[maxn<<2];
void up(int p){
For(i,0,1) tr[p][i]=merge(tr[p<<1][i],tr[p<<1|1][i]);
}
void pt(int p){
rev[p]^=1;
swap(tr[p][0],tr[p][1]);
}
void down(int p){
if(rev[p]){
pt(p<<1),pt(p<<1|1);
rev[p]=0;
}
}
void mdf(int p,int l,int r,int ql,int qr){
if(l>=ql&&r<=qr)return pt(p);
int mid=l+r>>1; down(p);
if(ql<=mid) mdf(p<<1,l,mid,ql,qr);
if(qr>mid) mdf(p<<1|1,mid+1,r,ql,qr);
up(p);
}
void build(int p,int l,int r){
// cout<<"build "<<p<<" "<<l<<" "<<r<<"\n";
if(l==r){
For(i,0,1) tr[p][i]=gen(t[l],t[l+1]-1,i);
return;
}
int mid=l+r>>1;
build(p<<1,l,mid);
build(p<<1|1,mid+1,r);
up(p);
}
bool chk(){
return tr[1][0].f[0][0];
}
bool chk0(){
return tr[1][0].l==-1;
}
}T[2];
signed main()
{
n=read(),m=read(); int mm=m;
For(i,1,n)x[i]=read(),y[i]=read(),t[++m]=y[i],tx[++lx]=x[i];
sort(t+1,t+m+1); sort(tx+1,tx+lx+1);
m=unique(t+1,t+m+1)-t-1,lx=unique(tx+1,tx+lx+1)-tx-1;
For(i,1,n){
x[i]=lower_bound(tx+1,tx+lx+1,x[i])-tx;
y[i]=lower_bound(t+1,t+m+1,y[i])-t;
}
For(i,1,n){
int j=i%n+1;
if(x[i]==x[j]) buc[x[i]].pb(mkp(min(y[i],y[j]),max(y[i],y[j])));
}
//cout<<"---\n";
T[0].build(1,1,m-1);
T[1]=T[0];
int o=0;
int res=t[0];
tx[lx+1]=2e9;
For(i,1,lx){
// cout<<"i: "<<i<<"\n";
for(auto [l,r]:buc[i]) T[o].mdf(1,1,m-1,l,r-1);
if(!T[o].chk()){
cout<<tx[i]/2*2;
exit(0);
}
int tt[2]={tx[i+1],tx[i+1]-1};
if((tt[0]-tx[i])%2) swap(tt[0],tt[1]);
if(T[o].chk0()) res=max(res,tt[1]);
if(T[!o].chk0()) res=max(res,tt[0]);
if((tx[i+1]-tx[i])%2){
o^=1;
}
}
res=min(res,mm);
cout<<res;
return 0;
}
/*
1
1 2 2 1
1 2 2 1
1 2 2 1
1 2 2 1
5 4
*/
/*
*/
详细
Subtask #1:
score: 0
Runtime Error
Test #1:
score: 4
Accepted
time: 3ms
memory: 48544kb
input:
4 3 0 0 0 3 3 3 3 0
output:
0
result:
ok single line: '0'
Test #2:
score: -4
Runtime Error
input:
4 999999999 999999999 0 999999999 1000000000 0 1000000000 0 0
output:
result:
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Runtime Error
Test #32:
score: 11
Accepted
time: 6ms
memory: 49176kb
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:
164
result:
ok single line: '164'
Test #33:
score: -11
Runtime Error
input:
36221 1000000000 0 996776952 43916 996776952 43916 996301596 102050 996301596 102050 995243908 173144 995243908 173144 992639626 184542 992639626 184542 987461238 192474 987461238 192474 982703402 406098 982703402 406098 980100986 525272 980100986 525272 978443232 532708 978443232 532708 977775310 6...
output:
result:
Subtask #4:
score: 0
Wrong Answer
Test #45:
score: 19
Accepted
time: 4ms
memory: 49112kb
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: 0
Accepted
time: 4ms
memory: 50484kb
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:
6
result:
ok single line: '6'
Test #47:
score: 0
Accepted
time: 42ms
memory: 51460kb
input:
199996 966 752 702 754 702 754 700 756 700 756 702 758 702 758 700 760 700 760 702 762 702 762 700 764 700 764 702 766 702 766 700 768 700 768 702 770 702 770 700 772 700 772 702 774 702 774 700 776 700 776 702 778 702 778 700 780 700 780 702 782 702 782 700 784 700 784 702 786 702 786 700 788 700 7...
output:
0
result:
ok single line: '0'
Test #48:
score: 0
Accepted
time: 45ms
memory: 51376kb
input:
199996 966 748 702 750 702 750 700 752 700 752 702 754 702 754 700 756 700 756 702 758 702 758 700 760 700 760 702 762 702 762 700 764 700 764 702 766 702 766 700 768 700 768 702 770 702 770 700 772 700 772 702 774 702 774 700 776 700 776 702 778 702 778 700 780 700 780 702 782 702 782 700 784 700 7...
output:
962
result:
ok single line: '962'
Test #49:
score: 0
Accepted
time: 0ms
memory: 50120kb
input:
500 916 560 975 560 526 544 526 544 708 538 708 538 585 534 585 534 879 530 879 530 612 514 612 514 907 512 907 512 571 504 571 504 976 494 976 494 746 486 746 486 922 478 922 478 667 476 667 476 913 472 913 472 623 456 623 456 890 450 890 450 609 446 609 446 905 436 905 436 705 428 705 428 816 418 ...
output:
900
result:
ok single line: '900'
Test #50:
score: -19
Wrong Answer
time: 13ms
memory: 49060kb
input:
500 980 421 481 453 481 453 479 32 479 32 477 453 477 453 461 353 461 353 451 403 451 403 441 176 441 176 435 314 435 314 429 128 429 128 417 129 417 129 413 31 413 31 401 136 401 136 399 130 399 130 398 130 391 217 391 217 383 6 383 6 369 105 369 105 365 84 365 84 353 178 353 178 345 0 345 0 343 26...
output:
768
result:
wrong answer 1st lines differ - expected: '0', found: '768'
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: 0
Runtime Error
Test #118:
score: 0
Runtime Error
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:
result:
Subtask #7:
score: 0
Skipped
Dependency #1:
0%