QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#622985 | #9449. New School Term | Displace_ | WA | 316ms | 13180kb | C++14 | 3.1kb | 2024-10-09 09:19:55 | 2024-10-09 09:19:56 |
Judging History
answer
#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double dou;
typedef pair<int,int> pii;
#define fi first
#define se second
#define mapa make_pair
typedef long double ld;
typedef unsigned long long ull;
template <typename T>inline void read(T &x){
x=0;char c=getchar();bool f=0;
for(;c<'0'||c>'9';c=getchar()) f|=(c=='-');
for(;c>='0'&&c<='9';c=getchar())
x=(x<<1)+(x<<3)+(c^48);
x=(f?-x:x);
}
const int mod=998244353;
inline int plu(int x, int y){x+=y; return x>=mod?x-mod:x;}
inline int sub(int x, int y){x-=y; return x<0?x+mod:x;}
const int N=40005, M=1e6+5;
int n, m;
int fx[M], fy[M], fa[N], s1[N], s2[N];
inline int get(int x){
if(x==fa[x]) return x;
return fa[x]=get(fa[x]);
}
vector<int> bin[N];
int col[N];
int f[N];
int tag;
inline void add(int x, int y){
tag+=min(x, y);
if(x==y) return ;
int dt=abs(x-y);
for(int i=n-dt; i>=0; --i) f[i+dt]=plu(f[i+dt], f[i]);
}
inline void del(int x, int y){
tag-=min(x, y);
if(x==y) return ;
int dt=abs(x-y);
for(int i=0; i<=n-dt; ++i) f[i+dt]=sub(f[i+dt], f[i]);
}
int main(){
read(n); read(m);
for(int i=1; i<=m; ++i){
read(fx[i]); read(fy[i]);
}
n<<=1;
for(int i=1; i<=n; ++i){
fa[i]=i; s1[i]=1; bin[i].emplace_back(i);
}
f[0]=1;
for(int i=1; i<=n; ++i){
for(int j=i; j>=1; --j) f[j]=plu(f[j], f[j-1]);
}
for(int i=m; i>=1; --i){
int x=get(fx[i]), y=get(fy[i]);
int a=fx[i], b=fy[i];
if(x==y) continue;
if(bin[x].size()<bin[y].size()) swap(x, y), swap(a, b);
if(col[a]!=col[b]){
del(s1[x], s2[x]);
del(s1[y], s2[y]);
add(s1[x]+s1[y], s2[x]+s2[y]);
if(!f[n/2-tag]){
del(s1[x]+s1[y], s2[x]+s2[y]);
for(auto t:bin[y]) col[t]^=1;
add(s1[x]+s2[y], s2[x]+s1[y]);
s1[x]+=s2[y]; s2[x]+=s1[y];
}
else{
s1[x]+=s1[y]; s2[x]+=s2[y];
}
}
else{
del(s1[x], s2[x]);
del(s1[y], s2[y]);
add(s1[x]+s2[y], s2[x]+s1[y]);
if(!f[n/2-tag]){
del(s1[x]+s2[y], s2[x]+s1[y]);
add(s1[x]+s1[y], s2[x]+s2[y]);
s1[x]+=s1[y]; s2[x]+=s2[y];
}
else{
for(auto t:bin[y]) col[t]^=1;
s1[x]+=s2[y]; s2[x]+=s1[y];
}
}
fa[y]=x;
for(auto t:bin[y]) bin[x].emplace_back(t);
bin[y].clear();
}
for(int i=n; i>=2; --i){
int x=get(1), y=get(i);
int a=1, b=i;
if(x==y) continue;
if(bin[x].size()<bin[y].size()) swap(x, y), swap(a, b);
if(col[a]!=col[b]){
del(s1[x], s2[x]);
del(s1[y], s2[y]);
add(s1[x]+s1[y], s2[x]+s2[y]);
if(!f[n/2-tag]){
del(s1[x]+s1[y], s2[x]+s2[y]);
for(auto t:bin[y]) col[t]^=1;
s1[x]+=s2[y]; s2[x]+=s1[y];
add(s1[x]+s2[y], s2[x]+s1[y]);
}
else{
s1[x]+=s1[y]; s2[x]+=s2[y];
}
}
else{
del(s1[x], s2[x]);
del(s1[y], s2[y]);
add(s1[x]+s2[y], s2[x]+s1[y]);
if(!f[n/2-tag]){
del(s1[x]+s2[y], s2[x]+s1[y]);
s1[x]+=s1[y]; s2[x]+=s2[y];
add(s1[x]+s1[y], s2[x]+s2[y]);
}
else{
for(auto t:bin[y]) col[t]^=1;
s1[x]+=s2[y]; s2[x]+=s1[y];
}
}
fa[y]=x;
for(auto t:bin[y]) bin[x].emplace_back(t);
bin[y].clear();
}
for(int i=1; i<=n; ++i) putchar(col[i]+'0');
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 8624kb
input:
2 4 1 3 2 4 1 4 1 2
output:
0101
result:
ok Output is valid. OK
Test #2:
score: 0
Accepted
time: 1ms
memory: 8020kb
input:
3 7 2 5 1 3 4 6 2 6 4 5 2 4 5 6
output:
001101
result:
ok Output is valid. OK
Test #3:
score: 0
Accepted
time: 1ms
memory: 5980kb
input:
1 0
output:
01
result:
ok Output is valid. OK
Test #4:
score: 0
Accepted
time: 0ms
memory: 8752kb
input:
1 1 1 2
output:
01
result:
ok Output is valid. OK
Test #5:
score: 0
Accepted
time: 0ms
memory: 8628kb
input:
2 3 2 4 3 4 1 2
output:
0110
result:
ok Output is valid. OK
Test #6:
score: 0
Accepted
time: 1ms
memory: 8408kb
input:
3 8 4 6 3 5 1 4 2 4 1 6 1 2 3 4 4 5
output:
010101
result:
ok Output is valid. OK
Test #7:
score: 0
Accepted
time: 1ms
memory: 8624kb
input:
4 9 4 7 3 8 1 5 2 7 2 8 6 8 7 8 1 4 1 6
output:
01010110
result:
ok Output is valid. OK
Test #8:
score: 0
Accepted
time: 1ms
memory: 8332kb
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: 8668kb
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:
001001110110
result:
ok Output is valid. OK
Test #10:
score: 0
Accepted
time: 1ms
memory: 8040kb
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:
000011100110010001111110
result:
ok Output is valid. OK
Test #11:
score: 0
Accepted
time: 3ms
memory: 8012kb
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:
000111001101000110010001111000111111100000011101010011011101110001010010000001111000111010000011101001010001000011100101010011000101101100010101100101100101100010011000110100001110011000111101010100011001001110110101101101010101101001100110011110101001111011110001010001111101001110101101111001001100...
result:
ok Output is valid. OK
Test #12:
score: 0
Accepted
time: 18ms
memory: 11844kb
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:
001000000010111000100000000010100001011010111010110111111110000111010000101011011010001011001010111000001011000011011001000001011010001010000011100001010101100110010101011001101100100000100100001010000000100111110011110010001000000001011101100011100001000000101110100000001001100000011110101100100010...
result:
ok Output is valid. OK
Test #13:
score: 0
Accepted
time: 53ms
memory: 10540kb
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:
000101110111111001001111011011101100010010100110100011010001111100011101110000111110111101011010000101000111000111001100011011001111001110110010001101001000001001001101011010101010111011011101000110100100000001101100111100001010111000100101101001010100100110110001011011001110011010000011000100010101...
result:
ok Output is valid. OK
Test #14:
score: 0
Accepted
time: 139ms
memory: 8860kb
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: 316ms
memory: 12360kb
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:
010010011000101111001110011100101011010001010000011000000110101011101001001110101110011011110101100011110110100100011001100111111010111100000011100110010100010011110101000110000010001110100011110100010110010111100011001010100011010001001101011101000000001100100100101010110111111000011010001001110000...
result:
ok Output is valid. OK
Test #16:
score: 0
Accepted
time: 43ms
memory: 13180kb
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: -100
Wrong Answer
time: 315ms
memory: 6468kb
input:
5000 0
output:
011111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...
result:
wrong answer The number of 0s must be equal to that of 1s.