QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#859154 | #9677. 基础博弈练习题 | lgvc# | 50 | 459ms | 132784kb | C++23 | 3.2kb | 2025-01-17 15:55:36 | 2025-01-17 15:55:38 |
Judging History
answer
#include <bits/stdc++.h>
static char buf[1000000],*paa=buf,*pd=buf;
static char buf2[1000000],*pp=buf2;
#define getchar() paa==pd&&(pd=(paa=buf)+fread(buf,1,1000000,stdin),paa==pd)?EOF:*paa++
inline void pc(char ch){
if(pp-buf2==1000000) fwrite(buf2,1,1000000,stdout),pp=buf2;
*pp++=ch;
}
inline void pcc(){
fwrite(buf2,1,pp-buf2,stdout);
pp=buf2;
}
inline int read(void){
int w=1;
register int x(0);register char c(getchar());
while(c<'0'||c>'9'){if(c=='-') w=-1;c=getchar();}
while(c>='0'&&c<='9')x=(x<<1)+(x<<3)+(c^48),c=getchar();
return w*x;
}
int N,M,Q,a[1000009],hd[1000009],to[2200009],nxt[2200009],k,
as[1000009],c[1000009],vi[1000009],ans[1000009],la[1000009],sz[1000009];
int low[1000009],dfn[1000009],st[1000009],col[1000009],top,co,num;
std::vector<int> tp[1000009];
void tarjan(int x){
low[x]=dfn[x]=++num;st[++top]=x;
for(int i=hd[x];i;i=nxt[i])
if(!dfn[to[i]]){
tarjan(to[i]);
low[x]=std::min(low[x],low[to[i]]);
} else if(!col[to[i]]) low[x]=std::min(low[x],dfn[to[i]]);
if(low[x]==dfn[x]) {
col[x]=++co;
while(st[top]!=x) col[st[top--]]=co;
--top;
}
}
void rs(int x,int y) {
for(int i=hd[x];i;i=nxt[i]) {
if(as[to[i]]==-1) {
as[to[i]]=y;
rs(to[i],y);
}
}
}
void rs2(int x,int y) {
for(int i=hd[x];i;i=nxt[i]) {
if((as[to[i]]>=y-1)&&(la[to[i]]!=y+1)) {
la[to[i]]=y+1;
ans[to[i]]=y;
rs2(to[i],y);
} else {
ans[to[i]]=y;
la[to[i]]=y+1;
}
}
}
void l(int u,int v) {
to[++k]=v;nxt[k]=hd[u];hd[u]=k;
}
std::vector<int> t[1000009];
signed main(void) {
N=read();M=read();Q=read();
for(int i=1;i<=N;i++) {
a[i]=read();
t[a[i]].push_back(i);
as[i]=-1;ans[i]=-1;
}
for(int i=1;i<=Q;i++) {
c[i]=read();
}
for(int i=1;i<=M;i++) {
int u=read(),v=read();
l(v,u);
}
for(int i=1;i<=N;i++) {
if(!dfn[i]) {
tarjan(i);
}
}
for(int i=1;i<=N;i++) {
sz[col[i]]++;
for(int j=hd[i];j;j=nxt[j]) {
if(col[i]!=col[to[j]]) {
tp[col[i]].push_back(col[to[j]]);
}
}
}
memset(hd,0,sizeof(hd));k=0;
for(int i=1;i<=N;i++) {
for(int j=0;j<tp[i].size();j++) {
l(i,tp[i][j]);
}
}
for(int i=1;i<=Q;i++) {
for(int j=0;j<t[c[i]].size();j++) {
int x=t[c[i]][j];
x=col[x];
if(as[x]==-1) {
if(sz[x]>1) {
as[x]=i-1;
}
rs(x,i-1);
}
}
}
for(int i=Q;i>=1;i--) {
for(int j=0;j<t[c[i]].size();j++) {
int x=t[c[i]][j];
x=col[x];
if(la[x]!=i+1) {
if(sz[x]>1) {
la[x]=i;
ans[x]=i-1;
}
rs2(x,i-1);
}
}
}
for(int i=1;i<=N;i++) {
printf("%d ",ans[col[i]]);
}
}
详细
Subtask #1:
score: 10
Accepted
Test #1:
score: 10
Accepted
time: 0ms
memory: 23340kb
input:
83 93 13 8 9 10 7 7 7 6 3 1 10 6 2 5 7 1 3 4 2 1 10 7 4 8 9 2 2 1 9 2 5 1 7 8 6 1 9 9 10 4 1 2 9 2 3 4 2 9 10 8 1 4 1 8 4 1 4 4 7 4 8 2 9 2 5 2 2 3 3 8 5 2 9 3 10 8 8 1 6 6 1 6 7 10 7 5 10 3 2 2 7 4 8 7 6 6 5 56 36 33 41 32 62 37 7 6 53 41 13 9 36 44 77 38 62 76 16 72 5 40 13 55 60 5 78 72 45 13 44 ...
output:
0 -1 -1 -1 2 0 -1 7 0 -1 3 -1 0 0 1 -1 0 -1 0 0 -1 0 -1 2 -1 -1 -1 -1 -1 -1 0 0 0 -1 0 -1 3 0 0 0 0 0 -1 -1 -1 -1 0 0 0 -1 0 0 3 0 0 0 -1 -1 3 -1 0 0 0 0 0 8 -1 -1 1 -1 -1 0 3 4 -1 3 -1 3 -1 0 0 0 -1
result:
ok 83 numbers
Test #2:
score: 10
Accepted
time: 2ms
memory: 25008kb
input:
95 33 40 1 1 1 1 3 3 1 1 2 1 1 2 3 3 2 2 2 1 2 3 1 2 1 2 2 1 2 2 3 3 1 1 2 3 1 2 1 3 2 1 1 1 3 2 1 1 1 2 3 2 3 1 1 3 2 3 1 2 1 3 1 2 1 1 1 1 2 1 2 3 1 1 3 3 2 1 3 3 3 1 2 3 1 2 2 1 3 2 1 1 1 2 2 3 1 2 2 3 1 3 3 2 3 3 2 2 2 2 1 1 1 1 2 1 1 1 1 1 2 3 1 3 2 2 3 1 3 3 1 2 2 3 2 1 3 11 95 57 80 22 89 56 ...
output:
2 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 3 -1 -1 -1 -1 -1 -1 -1 3 -1 3 -1 -1 0 -1 3 3 -1 0 0 -1 2 -1 -1 0 -1 -1 -1 -1 -1 -1 3 -1 -1 -1 -1 -1 0 -1 -1 2 -1 -1 -1 3 3 -1 -1 -1 0 -1 -1 -1 -1 3 -1 0 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 3 -1 -1 -1 -1 -1 -1 3 0 -1 -1 -1 -1 2 -1 0 0
result:
ok 95 numbers
Test #3:
score: 10
Accepted
time: 1ms
memory: 24284kb
input:
94 34 89 20 7 5 8 18 12 5 15 19 1 15 7 5 6 14 19 9 19 11 11 16 20 17 5 12 8 14 2 10 19 10 1 1 6 19 18 9 14 19 16 1 6 8 10 18 8 1 17 3 9 17 9 1 16 9 15 1 15 20 10 6 14 11 9 5 18 14 20 13 18 13 18 8 1 1 8 10 5 14 5 8 16 1 14 9 7 3 20 9 20 18 17 11 18 14 2 20 16 9 12 9 4 15 4 9 20 16 18 20 7 18 19 15 5...
output:
-1 19 -1 -1 -1 -1 -1 13 -1 -1 17 -1 -1 -1 26 -1 -1 2 -1 13 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 33 2 -1 33 -1 -1 42 -1 -1 -1 -1 2 -1 -1 39 -1 -1 33 8 -1 -1 -1 -1 -1 -1 19 -1 -1 -1 4 15 1 -1 26 61 4 -1 -1 2 -1 -1 3 13 -1 13 -1 -1 -1 -1 -1 0 -1 -1 -1 8 -1 -1 61 -1 -1 2 -1 -1
result:
ok 94 numbers
Subtask #2:
score: 10
Accepted
Dependency #1:
100%
Accepted
Test #4:
score: 10
Accepted
time: 3ms
memory: 23364kb
input:
2498 1795 2498 63 29 161 58 131 5 165 91 155 175 6 60 113 130 5 114 127 138 143 161 1 53 6 168 21 7 120 88 141 2 126 117 128 156 140 3 138 66 102 77 23 58 1 53 167 64 84 9 65 4 39 162 155 140 137 139 159 140 150 149 69 85 22 102 2 35 87 89 171 162 18 93 151 22 96 98 98 101 51 108 10 98 59 87 65 94 7...
output:
-1 -1 1599 -1 -1 0 1599 -1 -1 -1 0 -1 -1 -1 0 -1 1200 -1 -1 -1 0 -1 -1 1599 -1 0 -1 -1 -1 -1 1199 -1 -1 -1 1299 0 1299 -1 -1 -1 200 499 0 499 -1 -1 -1 -1 -1 -1 -1 -1 -1 1299 1299 -1 -1 -1 -1 1400 599 -1 -1 -1 -1 300 -1 -1 -1 -1 -1 900 -1 -1 900 -1 899 -1 -1 999 0 -1 -1 -1 -1 -1 -1 899 -1 -1 -1 1699 ...
result:
ok 2498 numbers
Test #5:
score: 10
Accepted
time: 2ms
memory: 24336kb
input:
1961 1528 1335 104 130 189 185 82 97 103 4 48 66 45 152 92 199 141 190 62 54 54 19 160 131 14 133 76 70 104 140 53 98 127 20 36 144 130 110 14 177 69 49 162 139 99 91 163 2 178 79 38 55 157 196 162 81 97 134 124 154 132 86 176 92 129 168 34 73 140 74 108 160 98 184 11 176 48 185 106 195 78 87 172 16...
output:
13 -1 8 -1 71 5 -1 43 -1 31 -1 29 -1 532 27 47 42 -1 -1 -1 4 623 15 -1 -1 -1 71 463 -1 7 2 -1 7 83 -1 532 -1 -1 16 -1 143 107 -1 47 -1 -1 -1 6 16 -1 -1 67 1 -1 315 255 -1 -1 38 -1 67 -1 -1 58 -1 304 -1 -1 3 -1 58 152 -1 96 -1 -1 48 1 -1 351 -1 -1 7 -1 -1 -1 46 -1 49 31 -1 -1 -1 -1 -1 -1 -1 15 42 140...
result:
ok 1961 numbers
Subtask #3:
score: 30
Accepted
Test #6:
score: 30
Accepted
time: 28ms
memory: 43772kb
input:
100000 355071 10000 5 7 4 7 4 1 10 5 9 4 9 4 3 10 5 4 9 1 7 10 1 6 10 3 10 9 8 4 6 3 10 8 6 8 3 5 10 9 7 7 1 3 8 8 6 2 8 4 2 9 1 10 3 6 3 8 9 10 5 7 3 2 1 5 7 4 3 4 6 4 2 7 2 5 5 6 4 6 7 4 4 6 4 2 3 9 9 9 10 8 1 6 7 2 9 8 2 3 1 6 9 4 10 3 10 1 2 3 3 4 1 1 1 5 8 6 8 3 1 6 2 9 5 9 4 7 2 10 7 5 2 2 7 4...
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:
ok 100000 numbers
Test #7:
score: 30
Accepted
time: 28ms
memory: 41092kb
input:
100000 300561 10000 6 3 6 10 10 9 7 3 6 4 5 4 1 2 3 2 10 6 3 7 8 7 10 5 9 10 2 3 9 5 6 10 9 1 4 9 1 10 7 2 9 10 5 5 9 3 5 5 5 9 9 5 1 7 5 10 8 6 8 4 5 9 2 10 1 6 4 10 10 9 2 1 10 1 9 5 3 2 9 3 4 8 10 7 5 2 4 5 3 6 9 7 5 10 2 7 4 7 10 8 1 7 7 1 7 7 6 6 7 1 5 4 6 2 1 8 6 10 6 10 1 5 8 4 6 2 10 6 10 4 ...
output:
0 4 0 0 3 0 0 4 0 0 0 0 0 0 0 0 0 0 1 0 0 1 7 0 1 2 0 0 0 0 4 0 0 1 0 0 0 2 0 0 0 3 0 0 1 0 0 0 3 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 1 0 9 0 0 0 2 0 3 1 0 2 1 0 0 0 2 0 0 0 0 0 0 3 0 0 0 0 0 2 2 0 0 1 0 0 0 0 0 1 0 0 1 0 2 0 6 0 0 1 5 0 0 3 0 0 1 2 0 2 3 0 0 2 0 1 1 9 0 2 5 2 0 2 1 3 1 6 4 0 0 1 0 2 1 0 ...
result:
ok 100000 numbers
Test #8:
score: 30
Accepted
time: 156ms
memory: 90008kb
input:
500000 1770902 50000 4 7 2 3 6 10 8 2 2 6 2 3 3 7 3 1 5 2 1 10 2 6 3 4 2 8 10 6 6 10 9 3 3 2 9 10 4 5 3 9 7 10 4 3 6 6 4 9 4 4 4 1 9 5 6 10 3 7 5 8 10 1 6 5 1 7 9 10 2 4 6 9 6 2 2 8 4 7 9 1 9 4 6 4 6 3 9 2 2 1 1 1 8 3 10 10 2 2 5 15 20 18 17 15 12 11 11 11 11 12 13 19 18 20 15 11 11 20 10 14 13 14 1...
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 1 0 0 0 0 4 1 1 1 4 1 10 1 1 1 4 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 -1 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 1...
result:
ok 500000 numbers
Test #9:
score: 30
Accepted
time: 104ms
memory: 45916kb
input:
97492 1048555 7389 3662 9323 1040 3729 5469 2246 9668 8976 7059 3356 2928 638 8679 8067 7459 7820 7524 5287 9991 8218 1963 9730 4843 3911 8841 987 2108 5432 4594 7413 4805 9028 6812 8545 6618 2392 2003 2419 8568 9431 4910 3742 5678 1695 3643 1968 1937 4035 3765 6112 2186 1437 1768 5453 9988 1241 436...
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:
ok 97492 numbers
Test #10:
score: 30
Accepted
time: 69ms
memory: 55044kb
input:
278730 379825 208278 46 449 419 234 290 507 414 36 414 89 394 404 514 442 280 337 13 108 345 4 166 153 434 250 506 416 243 78 523 332 368 81 335 393 366 18 154 2 133 312 313 203 140 388 481 244 193 506 238 503 303 83 174 516 441 8 274 414 508 111 521 118 487 271 232 77 433 395 350 84 518 322 324 328...
output:
-1 454 -1 -1 -1 -1 -1 43 -1 -1 -1 -1 -1 -1 -1 341 -1 -1 418 9 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 304 -1 -1 470 397 -1 -1 -1 -1 -1 -1 -1 -1 -1 402 -1 -1 -1 -1 334 -1 -1 125 -1 -1 237 -1 -1 -1 -1 -1 363 325 -1 -1 -1 -1 -1 -1 -1 -1 91 -1 -1 -1 -1 -1 13 388 14 -1 -1 -1 -1 211 489 -...
result:
ok 278730 numbers
Test #11:
score: 30
Accepted
time: 74ms
memory: 58880kb
input:
342520 350951 72468 2854 2272 1901 7008 4269 7420 3024 4556 4543 2393 2485 3361 521 4015 2013 5423 6441 6009 6164 6835 4488 6277 5740 3206 3586 195 3964 6529 1540 914 3244 452 443 4278 4282 2131 4928 6052 2114 422 6680 6237 4688 6557 1515 6755 2257 664 2042 155 5154 6579 5787 5200 5712 1412 137 6432...
output:
-1 -1 -1 -1 -1 -1 6403 -1 -1 -1 -1 -1 4542 179 -1 5422 -1 -1 -1 -1 -1 5329 -1 4757 -1 -1 3965 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 5600 2114 -1 -1 -1 -1 10 -1 -1 -1 28 -1 -1 -1 6586 -1 -1 465 -1 136 -1 -1 -1 -1 -1 3270 -1 -1 -1 -1 -1 5652 2289 -1 945 -1 -1 4002 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 ...
result:
ok 342520 numbers
Subtask #4:
score: 0
Time Limit Exceeded
Dependency #3:
100%
Accepted
Test #12:
score: 25
Accepted
time: 372ms
memory: 109696kb
input:
870330 2060994 532990 11323 4959 13769 991 8623 5067 7946 7895 9068 10896 11853 6110 12738 242 9527 3290 8548 1823 11423 7291 6365 1331 13788 3557 11342 10901 12459 3346 9618 9474 11803 12573 10613 1126 4207 9059 7482 4666 5681 12028 488 4561 6622 6914 2092 496 13914 2722 12104 5906 8540 13295 654 6...
output:
1392 -1 -1 -1 -1 3363 566 -1 -1 -1 -1 -1 -1 -1 2807 -1 -1 -1 82 -1 -1 288 3748 3558 -1 10906 4465 -1 -1 -1 -1 6866 -1 690 -1 -1 -1 11931 791 12036 -1 -1 2421 -1 -1 -1 13920 2726 -1 -1 -1 -1 654 2924 -1 502 -1 7892 -1 -1 -1 3326 -1 -1 946 3908 -1 7997 67 -1 2834 13009 2425 4236 -1 -1 -1 485 -1 -1 202...
result:
ok 870330 numbers
Test #13:
score: 25
Accepted
time: 459ms
memory: 132784kb
input:
870330 1956977 532990 567991 12393 289749 575569 36051 159787 366266 101759 291866 508726 5601 118882 51060 276478 459815 279898 470674 225317 205543 456379 302525 19147 30212 38405 270446 38331 464221 249144 210642 15456 363477 303627 400735 82588 525861 331335 360248 126756 307541 297520 35856 440...
output:
462174 -1 -1 -1 -1 76078 49475 -1 -1 -1 -1 -1 -1 -1 353781 -1 -1 -1 211981 -1 -1 77005 59283 60889 -1 -1 22047 -1 -1 -1 -1 465752 -1 82591 -1 -1 -1 462713 12764 386717 -1 -1 35714 -1 -1 -1 25134 48777 -1 -1 -1 -1 424454 138004 -1 3452 -1 305570 -1 -1 -1 243125 -1 -1 10380 218621 -1 441596 262770 -1 ...
result:
ok 870330 numbers
Test #14:
score: 0
Time Limit Exceeded
input:
384204 780340 113841 9679 4728 7414 2977 4704 4784 8117 8549 8336 2540 8549 413 7588 1090 8730 1250 3372 7804 428 4754 2922 9590 833 9372 2329 1389 2901 667 4530 1898 4456 7149 4070 9043 4459 9405 9214 2839 8720 4194 1634 8228 374 1242 5556 5618 5466 2728 6803 460 7170 8385 1429 6301 7588 3249 3815 ...
output:
result:
Subtask #5:
score: 0
Skipped
Dependency #4:
0%