QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#621448 | #9449. New School Term | XY_Eleven | WA | 512ms | 203004kb | C++23 | 6.1kb | 2024-10-08 14:38:05 | 2024-10-08 14:38:25 |
Judging History
answer
#include <bits/stdc++.h>
// #include <windows.h>
// #include <bits/extc++.h>
// using namespace __gnu_pbds;
using namespace std;
//#pragma GCC optimize(3)
#define DB double
#define LL long long
#define ULL unsigned long long
#define in128 __int128
#define cint const int
#define cLL const LL
#define For(z,e1,e2) for(int z=(e1);z<=(e2);z++)
#define Rof(z,e1,e2) for(int z=(e2);z>=(e1);z--)
#define For_(z,e1,e2) for(int z=(e1);z<(e2);z++)
#define Rof_(z,e1,e2) for(int z=(e2);z>(e1);z--)
#define inint(e) scanf("%d",&e)
#define inll(e) scanf("%lld",&e)
#define inpr(e1,e2) scanf("%d%d",&e1,&e2)
#define in3(e1,e2,e3) scanf("%d%d%d",&e1,&e2,&e3)
#define outint(e) printf("%d\n",e)
#define outint_(e) printf("%d%c",e," \n"[i==n])
#define outint2_(e,e1,e2) printf("%d%c",e," \n"[(e1)==(e2)])
#define outll(e) printf("%lld\n",e)
#define outll_(e) printf("%lld%c",e," \n"[i==n])
#define outll2_(e,e1,e2) printf("%lld%c",e," \n"[(e1)==(e2)])
#define exc(e) if(e) continue
#define stop(e) if(e) break
#define ret(e) if(e) return
#define ll(e) (1ll*(e))
#define pb push_back
#define ft first
#define sc second
#define pii pair<int,int>
#define pli pair<LL,int>
#define vct vector
#define clean(e) while(!e.empty()) e.pop()
#define all(ev) ev.begin(),ev.end()
#define sz(ev) ((int)ev.size())
#define debug(x) printf("%s=%d\n",#x,x)
#define x0 __xx00__
#define y1 __yy11__
#define ffo fflush(stdout)
// cLL mod=998244353,G=404;
cLL mod=188888888861ll;
// cLL mod[2]={1686688681ll,1666888681ll},base[2]={166686661ll,188868881ll};
template <typename Type> void get_min(Type &w1,const Type w2) { if(w2<w1) w1=w2; } template <typename Type> void get_max(Type &w1,const Type w2) { if(w2>w1) w1=w2; }
template <typename Type> Type up_div(Type w1,Type w2) { return (w1/w2+(w1%w2?1:0)); }
template <typename Type> Type gcd(Type X_,Type Y_) { Type R_=X_%Y_; while(R_) { X_=Y_; Y_=R_; R_=X_%Y_; } return Y_; } template <typename Type> Type lcm(Type X_,Type Y_) { return (X_/gcd(X_,Y_)*Y_); }
template <typename Type> Type md(Type w1,const Type w2=mod) { w1%=w2; if(w1<0) w1+=w2; return w1; } template <typename Type> Type md_(Type w1,const Type w2=mod) { w1%=w2; if(w1<=0) w1+=w2; return w1; }
void ex_gcd(LL &X_,LL &Y_,LL A_,LL B_) { if(!B_) { X_=1ll; Y_=0ll; return ; } ex_gcd(Y_,X_,B_,A_%B_); X_=md(X_,B_); Y_=(1ll-X_*A_)/B_; } LL inv(LL A_,LL B_=mod) { LL X_=0ll,Y_=0ll; ex_gcd(X_,Y_,A_,B_); return X_; }
template <typename Type> void add(Type &w1,const Type w2,const Type M_=mod) { w1=md(w1+w2,M_); } void mul(LL &w1,cLL w2,cLL M_=mod) { w1=md(w1*md(w2,M_),M_); } template <typename Type> Type pw(Type X_,Type Y_,Type M_=mod) { Type S_=1; while(Y_) { if(Y_&1) mul(S_,X_,M_); Y_>>=1; mul(X_,X_,M_); } return S_; }
template <typename Type> Type bk(vector <Type> &V_) { auto T_=V_.back(); V_.pop_back(); return T_; } template <typename Type> Type tp(stack <Type> &V_) { auto T_=V_.top(); V_.pop(); return T_; } template <typename Type> Type frt(queue <Type> &V_) { auto T_=V_.front(); V_.pop(); return T_; }
template <typename Type> Type bg(set <Type> &V_) { auto T_=*V_.begin(); V_.erase(V_.begin()); return T_; } template <typename Type> Type bk(set <Type> &V_) { auto T_=*prev(V_.end()); V_.erase(*prev(V_.end())); return T_; }
mt19937 gen(time(NULL)); int rd() { return abs((int)gen()); }
int rnd(int l,int r) { return rd()%(r-l+1)+l; }
void main_init()
{
}
cint N=5010,Q_=1.02e6;
int n,Q;
int uf[N<<1],siz1[N<<1],siz2[N<<1];
bool ck[N<<1];
array <int,2> q[Q_];
pair<int,bool> fin(int w)
{
if(uf[w]==w) return {w,false};
auto [w2,f]=fin(uf[w]);
return {uf[w]=w2,ck[w]^=f};
}
void mer(int w1,int w2,bool f)
{
// printf("merge %d %d (%d)\n",w1,w2,f);
w1=fin(w1).ft,w2=fin(w2).ft;
ret(w1==w2);
if(w1>w2) swap(w1,w2);
if(f) siz1[w1]+=siz2[w2],siz2[w1]+=siz1[w2];
else siz1[w1]+=siz1[w2],siz2[w1]+=siz2[w2];
// printf("%d->%d\n",w2,w1);
uf[w2]=w1,ck[w2]=f;
}
LL dp[N<<1];
int m;
void ins(int x,int y)
{
m+=min(x,y);
int t=abs(x-y);
ret(!t);
Rof(i,t,n<<1)
{
dp[i]+=dp[i-t];
if(dp[i]>=mod) dp[i]-=mod;
}
}
void ers(int x,int y)
{
m-=min(x,y);
int t=abs(x-y);
ret(!t);
For(i,t,n<<1)
{
dp[i]-=dp[i-t];
if(dp[i]<0ll) dp[i]+=mod;
}
}
bool gt()
{
// printf("get %d:%lld\n",m,dp[n-m]);
return (dp[n-m]!=0ll);
}
bool check(int i,int j,bool f)
{
int x1=siz1[i],y1=siz2[i];
int x2=siz1[j],y2=siz2[j];
if(f) swap(x2,y2);
// printf("%d,%d & %d,%d\n",x1,y1,x2,y2);
ers(x1,y1),ers(x2,y2);
ins(x1+x2,y1+y2);
if(gt())
{
mer(i,j,f);
return true;
}
ers(x1+x2,y1+y2);
ins(x1,y1),ins(x2,y2);
// printf("> m=%d\n",m);
return false;
}
int b[N<<1][N];
bool ans[N<<1];
void main_solve()
{
inpr(n,Q);
For(i,1,Q) inpr(q[i][0],q[i][1]);
reverse(q+1,q+Q+1);
dp[0]=1ll; m=0;
For(i,1,n<<1) uf[i]=i,siz1[i]=1,siz2[i]=0,ck[i]=false;
For(i,1,n<<1) ins(1,0);
For(qid,1,Q)
{
auto [x,y]=q[qid];
exc(fin(x).ft==fin(y).ft);
// printf("%d(%d),%d(%d)\n",x,fin(x).ft,y,fin(y).ft);
bool f=!(ck[x]^ck[y]); x=fin(x).ft,y=fin(y).ft;
if(!check(x,y,f)) assert(check(x,y,!f));
// printf("m=%d\n",m);
// For(i,0,n<<1) printf("%lld ",dp[i]); printf("\n");
assert(gt());
}
For(i,1,n<<1) fin(i);
b[0][0]=-1;
int tot=0;
For(i,1,n<<1)
{
exc(fin(i).ft!=i);
int t=abs(siz1[i]-siz2[i]);
For(j,0,t) if(b[tot][j]) b[tot+1][j]=j+1;
For(j,t,n) if(b[tot][j-t]) b[tot+1][j]=j-t+1;
tot++;
}
int k=n-m;
Rof(i,1,n<<1)
{
exc(fin(i).ft!=i);
// printf("k=%d\n",k);
ans[i]=(b[tot][k]==k+1); k=b[tot--][k]-1;
}
For(i,1,n<<1) printf("%d",ck[i]^ans[fin(i).ft]); printf("\n");
}
int main()
{
// ios::sync_with_stdio(0); cin.tie(0);
// freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
// srand(time(NULL));
main_init();
// int _; inint(_); For(__,1,_) // T>1 ?
// printf("\n------------\n\n"),
main_solve();
return 0;
}
/*
*/
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 8104kb
input:
2 4 1 3 2 4 1 4 1 2
output:
1010
result:
ok Output is valid. OK
Test #2:
score: 0
Accepted
time: 1ms
memory: 6120kb
input:
3 7 2 5 1 3 4 6 2 6 4 5 2 4 5 6
output:
110010
result:
ok Output is valid. OK
Test #3:
score: 0
Accepted
time: 1ms
memory: 6064kb
input:
1 0
output:
10
result:
ok Output is valid. OK
Test #4:
score: 0
Accepted
time: 1ms
memory: 8148kb
input:
1 1 1 2
output:
10
result:
ok Output is valid. OK
Test #5:
score: 0
Accepted
time: 1ms
memory: 6012kb
input:
2 3 2 4 3 4 1 2
output:
1001
result:
ok Output is valid. OK
Test #6:
score: 0
Accepted
time: 1ms
memory: 6116kb
input:
3 8 4 6 3 5 1 4 2 4 1 6 1 2 3 4 4 5
output:
101010
result:
ok Output is valid. OK
Test #7:
score: 0
Accepted
time: 1ms
memory: 5932kb
input:
4 9 4 7 3 8 1 5 2 7 2 8 6 8 7 8 1 4 1 6
output:
10101001
result:
ok Output is valid. OK
Test #8:
score: 0
Accepted
time: 1ms
memory: 6060kb
input:
5 16 3 6 9 10 2 7 1 10 1 5 2 10 3 5 5 6 3 4 2 5 4 5 3 8 4 7 6 8 1 6 7 10
output:
1101000101
result:
ok Output is valid. OK
Test #9:
score: 0
Accepted
time: 1ms
memory: 6120kb
input:
6 13 4 5 2 9 3 8 4 8 4 11 10 12 3 4 3 9 5 11 2 8 5 10 5 8 1 11
output:
110110001001
result:
ok Output is valid. OK
Test #10:
score: 0
Accepted
time: 1ms
memory: 6072kb
input:
12 153 1 24 16 18 7 14 1 16 20 21 9 14 21 22 4 5 17 24 4 12 5 17 13 24 14 15 12 23 12 16 8 11 14 24 9 16 2 5 6 19 11 17 4 22 4 7 6 16 7 20 8 15 5 24 2 10 10 21 21 24 1 12 11 19 18 21 18 24 12 17 13 22 7 9 13 23 4 9 11 13 15 21 5 7 2 4 15 16 17 19 11 16 11 20 7 8 4 15 13 14 6 18 2 19 9 13 23 24 4 21 ...
output:
111100011001101110000001
result:
ok Output is valid. OK
Test #11:
score: 0
Accepted
time: 5ms
memory: 6084kb
input:
259 33757 472 500 65 336 138 469 307 442 427 458 43 239 17 508 460 466 108 393 79 92 250 483 44 277 17 132 35 57 155 499 184 474 246 272 274 418 457 458 338 372 196 514 31 208 117 187 90 229 153 284 189 355 16 337 146 456 269 271 279 412 305 336 303 441 399 472 85 286 91 97 157 437 137 379 71 360 27...
output:
111000110010111001101110000111000000011111100010101100100010001110101101111110000111000101111100010110101110111100011010101100111010010011101010011010011010011101100111001011110001100111000010101011100110110001001010010010101010010110011001100001010110000100001110101110000010110001010010000110110011...
result:
ok Output is valid. OK
Test #12:
score: 0
Accepted
time: 41ms
memory: 8144kb
input:
811 265557 217 1153 383 1609 165 177 612 1602 1057 1428 37 436 135 1200 368 684 448 722 145 1583 325 1052 246 480 74 148 122 1111 1256 1327 304 1070 1285 1542 802 813 454 1563 265 1193 94 848 432 1156 429 1194 427 1230 1152 1406 1329 1355 702 845 591 1232 877 1288 1257 1549 340 659 1080 1333 910 137...
output:
110111111101000111011111111101011110100101000101001000000001111000101111010100100101110100110101000111110100111100100110111110100101110101111100011110101010011001101010100110010011011111011011110101111111011000001100001101110111111110100010011100011110111111010001011111110110011111100001010011011101...
result:
ok Output is valid. OK
Test #13:
score: 0
Accepted
time: 97ms
memory: 10216kb
input:
1691 323743 1246 2397 1445 2647 2010 2806 2001 2896 802 2258 2679 2976 2203 2875 2445 2698 137 3004 536 1800 2316 2520 594 1517 279 1558 1934 2871 57 1358 357 976 1764 2672 869 2137 1694 2201 491 1906 1177 1414 1304 1377 2454 2653 626 2637 1425 1677 620 876 1326 2085 404 874 626 1565 136 597 2885 31...
output:
111010001000000110110000100100010011101101011001011100101110000011100010001111000001000010100101111010111000111000110011100100110000110001001101110010110111110110110010100101010101000100100010111001011011111110010011000011110101000111011010010110101011011001001110100100110001100101111100111011101010...
result:
ok Output is valid. OK
Test #14:
score: 0
Accepted
time: 218ms
memory: 10180kb
input:
2891 285302 2273 3206 2376 4737 1075 5673 2493 5453 548 1902 603 1376 1948 2985 108 4730 2172 2948 947 1758 762 1558 2813 5701 2287 3502 297 1501 568 4247 4569 5071 832 3005 412 4226 1813 4519 726 3017 1658 3990 1771 3230 1705 2149 765 4782 5420 5652 3089 4727 4362 5054 1578 3729 1111 5740 2234 5691...
output:
110001001000000110011000111101001110110111100101011110101001010100100000100100000111010001100111111110000101010101101110111000010001001011000100110000000111001101010111111001011100000001001110101111110101010111000111000000000101011000110101011110001011100001000000000101011001001110001100001000110001...
result:
ok Output is valid. OK
Test #15:
score: 0
Accepted
time: 512ms
memory: 12324kb
input:
4413 717147 1990 3721 2169 8724 2894 5350 4689 5732 274 3456 3149 5664 463 6517 3482 7460 1820 5440 2995 6364 5476 7590 5989 8692 4286 7015 7520 8630 524 7821 3335 7017 1491 4477 6238 8230 6339 8087 565 8666 6188 6930 4280 7015 4393 8825 3686 6189 3711 6905 888 1997 2488 8544 9 3914 5135 5322 2778 6...
output:
101101100111010000110001100011010100101110101111100111111001010100010110110001010001100100001010011100001001011011100110011000000101000011111100011001101011101100001010111001111101110001011100001011101001101000011100110101011100101110110010100010111111110011011011010101001000000111100101110110001111...
result:
ok Output is valid. OK
Test #16:
score: 0
Accepted
time: 103ms
memory: 13068kb
input:
707 998991 16 83 733 1195 318 945 9 385 764 1338 396 833 408 1331 541 1405 167 1351 572 838 16 334 36 1071 765 873 445 930 48 168 857 1306 1066 1408 270 720 116 698 737 1136 460 1074 585 1195 492 690 1103 1122 698 1239 623 1355 30 140 952 1088 776 1138 71 525 690 1194 357 1062 366 632 46 744 312 520...
output:
110110010110010001001101110000000111110101010001100010101010010001101011001110011110101101100100001101010001001101000011010101001101001010110010101101001110111001000000010111010100000100011011011010101101110101111000100001101000000000001001111111000010110011110000100111010110110110000000010011101100...
result:
ok Output is valid. OK
Test #17:
score: 0
Accepted
time: 86ms
memory: 203004kb
input:
5000 0
output:
111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...
result:
ok Output is valid. OK
Test #18:
score: 0
Accepted
time: 68ms
memory: 201048kb
input:
5000 1 5104 7449
output:
111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...
result:
ok Output is valid. OK
Test #19:
score: 0
Accepted
time: 75ms
memory: 200944kb
input:
5000 13 8215 9259 4067 7015 4171 6513 1958 9790 5814 6551 711 3995 4392 8567 224 285 4618 4637 2864 8137 1910 2618 1881 5086 5503 9167
output:
111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110111111111111111...
result:
ok Output is valid. OK
Test #20:
score: -100
Wrong Answer
time: 92ms
memory: 200716kb
input:
5000 55 7866 9685 3869 9188 3142 5921 1328 5189 1186 4841 2865 4732 5504 5634 983 5412 6630 7625 6123 9142 2937 5558 1344 5103 5443 9618 3579 6083 1044 3407 1028 6125 2895 5649 2986 3484 3659 6044 5673 7508 276 5982 694 4033 1089 6272 2661 2831 6962 9163 2717 8822 4363 5916 249 8966 9331 9920 1551 2...
output:
111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...
result:
wrong answer The number of 0s must be equal to that of 1s.