QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#133670 | #4934. Forbidden Card | SolitaryDream# | WA | 21ms | 10444kb | C++20 | 2.1kb | 2023-08-02 12:44:49 | 2023-08-02 12:44:52 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
const int M = 1e6 + 10;
int n, m, a[N], b[N];
int vis[M];
int ans[N];
int fa[N];
inline int Ask(int x) {
return fa[x] >= 0 ? fa[x] = Ask(fa[x]) : x;
}
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; ++i) {
scanf("%d%d", &a[i], &b[i]);
}
vector<int> seq;
int loser = 1;
memset(vis, -1, sizeof vis);
for (int round = 0; round < 2; ++round) {
for (int i = 1; i <= n; ++i) {
if (vis[a[i]] == -1) { vis[a[i]] = seq.size(); seq.push_back(i << 1 | 0); }
else if (vis[b[i]] == -1) { vis[b[i]] = seq.size(); seq.push_back(i << 1 | 1); }
else { loser = i; break; }
}
if (seq.size() != n) break;
}
// printf("loser: %d\n", loser);
// for (auto x : seq) printf("%d %d\n", x >> 1, x & 1);
// puts("");
for (int i = 0; i < seq.size(); ++i) fa[i] = -1;
for (int i = 0; i < (int)seq.size(); ++i) {
int who = seq[i] >> 1, card = seq[i] & 1;
if (card == 0) {
if (vis[b[who]] == -1) fa[i] = -loser;
else {
int oth = seq[vis[b[who]]] >> 1, oth_card = seq[vis[b[who]]] & 1;
if (oth_card == 1) {
// printf("Link0 %d %d\n", i, -oth);
fa[i] = -oth;
} else if (vis[b[who]] < i) {
// printf("Link1 %d %d\n", i, -i);
fa[i] = -who;
} else {
// printf("Link %d %d\n", i, vis[b[who]]);
fa[i] = vis[b[who]];
}
}
}
}
// for (int i = 0; i < (int)seq.size(); ++i) printf("%d ", fa[i]);
// puts("");
for (int i = 1; i <= m; ++i) {
if (vis[i] == -1) {
++ans[loser];
} else {
int who = seq[vis[i]] >> 1, card = seq[vis[i]] & 1;
if (card == 1) ++ans[who];
else {
++ans[-fa[Ask(vis[i])]];
}
}
}
for (int i = 1; i <= n; ++i) printf("%d\n", ans[i]);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 8100kb
input:
3 6 1 2 2 4 4 2
output:
3 0 3
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 0ms
memory: 7744kb
input:
4 10 1 5 2 6 3 7 4 8
output:
4 2 2 2
result:
ok 4 lines
Test #3:
score: 0
Accepted
time: 1ms
memory: 9956kb
input:
1 2 1 2
output:
2
result:
ok single line: '2'
Test #4:
score: 0
Accepted
time: 8ms
memory: 10220kb
input:
69332 250102 51362 228823 206751 31351 181790 44202 186695 92215 172072 173179 86663 76959 42382 25827 204750 30001 42502 11959 201030 71886 227497 216114 164282 235028 178967 181951 125356 20611 169528 174071 50985 175562 63676 208400 189134 229462 49746 131529 180236 247427 29278 229589 30381 4412...
output:
197458 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
result:
ok 69332 lines
Test #5:
score: 0
Accepted
time: 18ms
memory: 10356kb
input:
80145 426253 421996 34366 346502 239646 343011 88629 67397 242186 299496 244930 21243 104718 387596 328535 219758 313693 75331 382300 313805 77098 42577 148653 337458 118115 214642 386869 250381 179903 371620 42703 175776 57872 382478 385425 67153 363632 137021 301439 54496 28984 416540 87624 180610...
output:
2 2 387645 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
result:
ok 80145 lines
Test #6:
score: 0
Accepted
time: 12ms
memory: 10392kb
input:
100000 1000000 123135 548518 73705 792839 425849 331898 823140 91484 612409 674530 215766 587078 145133 904035 435464 107690 291461 358251 156778 270843 378425 339959 353997 687100 373365 903063 948343 203641 349073 91866 329756 348161 731516 202789 767371 938875 3496 388919 998073 384450 73693 8551...
output:
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 956616 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
result:
ok 100000 lines
Test #7:
score: 0
Accepted
time: 17ms
memory: 9308kb
input:
89069 799019 589538 728126 669934 721110 689804 767765 57113 349607 788143 621300 449778 648433 451910 356399 484000 586091 699836 387252 618498 221963 42563 549795 774972 697895 765784 478517 626296 213965 174994 617652 788312 418305 509601 717678 663049 769953 167726 375932 38772 144093 140904 564...
output:
2 783305 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
result:
ok 89069 lines
Test #8:
score: 0
Accepted
time: 17ms
memory: 8956kb
input:
69694 877503 863663 582574 192540 50718 545855 600725 106914 337076 95953 472303 337876 352481 617099 663754 658298 249330 575057 97722 522140 520920 811913 519974 533217 425142 590101 532180 684733 355462 783334 274412 25380 75797 853682 128592 457036 274558 184076 7863 688088 614343 733047 768004 ...
output:
2 2 829210 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
result:
ok 69694 lines
Test #9:
score: 0
Accepted
time: 8ms
memory: 8868kb
input:
68561 994844 934673 839086 678230 902049 609695 838139 172142 165310 166125 382300 733287 681492 31687 156593 743676 484561 301345 936945 511237 258689 936301 315735 750745 500110 650444 288851 407665 485171 316258 272455 868401 430224 348328 582450 368182 44256 934873 895495 466439 780819 543373 68...
output:
2 2 2 2 985873 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
result:
ok 68561 lines
Test #10:
score: 0
Accepted
time: 19ms
memory: 10444kb
input:
100000 1000000 750844 577520 750988 551898 71182 495851 781670 620811 429538 655630 949020 91780 352634 583957 278999 299878 401107 296003 310998 796093 134490 713012 571847 466126 97048 513189 701512 397675 328784 597378 600866 775036 123964 779641 783762 95052 581923 521272 174622 578127 940629 92...
output:
958024 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
result:
ok 100000 lines
Test #11:
score: 0
Accepted
time: 14ms
memory: 10340kb
input:
97613 571574 473117 229386 423786 319808 400816 515877 51984 283789 129404 223355 36594 363548 378401 286262 173741 481783 33072 245586 443684 222118 84885 277987 521174 139691 557463 541830 447714 163559 414047 64274 366005 384713 149976 525494 497204 378402 548917 82952 184725 168981 445716 501317...
output:
542823 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
result:
ok 97613 lines
Test #12:
score: 0
Accepted
time: 5ms
memory: 9084kb
input:
69396 864127 464385 526906 787104 491768 38269 47670 86820 517464 353813 728363 679809 387823 517990 116740 848791 410216 587334 99062 778991 733391 832499 522941 19242 176014 751019 345373 268829 384678 55782 16440 127010 333800 535423 588225 109371 645414 145244 552479 597799 552396 600038 235109 ...
output:
2 2 2 2 2 2 2 805120 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
result:
ok 69396 lines
Test #13:
score: 0
Accepted
time: 16ms
memory: 10360kb
input:
86470 288956 81959 261040 206019 205310 130325 15327 223490 45996 254263 134493 132914 146198 271808 230093 192789 239059 257256 18045 87950 183011 19344 266027 280038 28560 139522 285325 26554 267570 4553 143311 21451 61963 242467 238366 274767 216559 165157 8502 185945 180806 271515 104078 98160 2...
output:
239234 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
result:
ok 86470 lines
Test #14:
score: 0
Accepted
time: 0ms
memory: 7988kb
input:
2 2 2 1 1 2
output:
0 2
result:
ok 2 lines
Test #15:
score: 0
Accepted
time: 21ms
memory: 10368kb
input:
100000 1000000 642133 546926 123679 867209 617137 454611 472705 627306 94896 603782 523279 31451 263895 276501 142151 455942 525514 977824 263586 220101 93152 998514 117325 54406 75166 160431 174093 514041 409869 356920 751904 244516 844806 816952 904840 872203 896272 387803 522151 434957 154934 531...
output:
2 3 2 2 2 2 3 2 2 908975 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
result:
ok 100000 lines
Test #16:
score: 0
Accepted
time: 11ms
memory: 10272kb
input:
96191 790771 239246 406927 608723 39453 647021 455246 449613 325203 500412 246565 496412 527678 775691 306215 15686 145589 789951 122377 126343 302706 704644 254834 538536 278628 68976 439516 650659 690292 496323 588418 710462 6367 227229 387492 313599 215876 281669 237302 117764 311686 70133 388917...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
ok 96191 lines
Test #17:
score: -100
Wrong Answer
time: 12ms
memory: 9380kb
input:
86551 543901 231809 430371 538308 434317 542712 120195 323781 89341 535653 25803 423038 172132 280771 313400 527228 456621 112353 356938 487630 393471 191751 52096 151594 392894 230381 83155 362583 11099 43970 409303 356820 251516 199568 326380 74743 182624 406748 384282 534629 72327 358298 533328 3...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
wrong answer 38835th lines differ - expected: '1', found: '3'