QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#601797 | #9421. Sheriruth | Crysfly | AC ✓ | 722ms | 114076kb | C++14 | 2.4kb | 2024-09-30 13:30:09 | 2024-09-30 13:30:09 |
Judging History
answer
#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 int long long
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 fi first
#define se second
#define pb push_back
#define mkp make_pair
typedef pair<int,int>pii;
typedef vector<int>vi;
#define maxn 500005
#define inf 0x3f3f3f3f
int n,m,Q,mod,d[maxn];
vi rg[maxn],e[maxn],g[maxn];
int val[maxn];
int tot,col[maxn],cv[maxn],ce[maxn];
void dfs1(int u,int c){
col[u]=c;
++cv[c],ce[c]+=d[u],d[u]=0;
for(int v:e[u]) if(d[v]) dfs1(v,c);
}
int col2[maxn],top[maxn];
int dfn[maxn],out[maxn],idx;
void dfs2(int u,int tp,int c){
col2[u]=c;
top[u]=tp;
dfn[u]=++idx;
for(int v:rg[u]) dfs2(v,tp,c);
out[u]=idx;
}
bool chkg(int u,int v){
auto it=lower_bound(g[u].begin(),g[u].end(),v);
return it!=g[u].end() && (*it)==v;
}
signed main()
{
// freopen("sheriruth.in","r",stdin);
// freopen("sheriruth.out","w",stdout);
n=read(),m=read(),Q=read(),mod=read();
For(i,1,n)val[i]=(1ll*val[i-1]*(i-1)+1)%mod;
For(i,1,m){
int u=read()+1,v=read()+1;
e[u].pb(v),e[v].pb(u);
g[u].pb(v),rg[v].pb(u);
++d[v];
}
For(i,1,n)sort(g[i].begin(),g[i].end());
queue<int>q;
For(i,1,n)if(!d[i])q.push(i);
while(q.size()){
int u=q.front();q.pop();
if(g[u].size()==0)continue;
for(int x:g[u]) e[x].pb(g[u][0]),e[g[u][0]].pb(x);
if(g[u].size()==1){
int v=g[u][0];
--d[v];
if(!d[v])q.push(v);
}
}
For(i,1,n)
if(d[i]){
++tot;
dfs1(i,tot);
}
For(i,1,n)
if(!col[i]){
if(!g[i].size()) dfs2(i,0,0);
else {
int tmp=0;
for(int v:g[i]) tmp|=col[v];
if(tmp) dfs2(i,i,tmp);
}
}
For(_,1,Q){
int u=read()+1,v=read()+1,res=0;
if(!col[u]){
if(!col[v]){
res=(dfn[v]<=dfn[u] && dfn[u]<=out[v]);
}else{
int id=col[v];
if(col2[u]!=id)res=0;
else if(cv[id]==ce[id])res=g[top[u]].size();
else{
bool hav=chkg(top[u],v);
res=g[top[u]].size()-hav;
res=1ll*res*val[cv[id]-1]%mod;
res=res+hav;
res%=mod;
}
}
}else{
if(col[u]!=col[v]){
res=0;
}else{
int id=col[u];
if(u==v||cv[id]==ce[id])res=1;
else res=val[cv[id]-1];
}
}
res%=mod;
printf("%d\n",res);
}
return 0;
}
这程序好像有点Bug,我给组数据试试?
詳細信息
Test #1:
score: 100
Accepted
time: 5ms
memory: 53124kb
input:
11 9 30 998244353 0 1 0 2 3 4 5 4 6 5 7 8 8 9 9 8 10 9 0 1 0 2 1 0 1 2 2 0 2 1 3 4 3 5 3 6 4 3 4 5 4 6 5 3 5 4 5 6 6 3 6 4 6 5 7 8 7 9 7 10 8 7 8 9 8 10 9 7 9 8 9 10 10 7 10 8 10 9
output:
2 2 0 1 0 1 1 0 0 0 0 0 0 1 0 0 1 1 1 1 0 0 1 0 0 1 0 0 1 1
result:
ok 30 numbers
Test #2:
score: 0
Accepted
time: 720ms
memory: 111192kb
input:
490330 975088 999910 1 348838 147909 295660 265201 357515 214814 100870 359366 408255 86356 60134 169442 409736 191593 231830 141232 197635 250005 4728 186530 38142 185732 95910 109149 239818 295107 421484 92342 121513 336128 101868 288271 59786 95719 139655 36705 360745 150735 256350 279669 262586 ...
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 999910 numbers
Test #3:
score: 0
Accepted
time: 0ms
memory: 54988kb
input:
10 10 100 763034674 7 0 0 2 3 8 6 0 1 3 9 2 6 9 5 6 9 5 3 4 8 1 0 7 8 4 3 8 3 8 3 8 2 5 7 9 3 4 7 5 2 0 4 8 7 9 8 8 0 7 9 5 2 5 9 0 0 7 8 4 8 4 8 4 5 5 5 5 0 0 9 9 5 6 0 9 3 4 4 8 9 9 6 6 8 4 4 4 4 8 2 6 4 8 5 0 8 8 8 4 0 0 0 6 4 4 8 8 4 8 5 0 4 8 6 0 0 2 6 2 2 0 8 4 6 2 9 6 7 5 2 0 4 8 2 6 0 7 4 8 ...
output:
0 0 1 2 2 2 16 16 2 16 16 1 16 1 0 16 16 16 0 1 1 1 1 1 1 1 16 16 2 1 1 1 1 1 1 16 1 16 1 1 1 16 1 1 1 16 1 16 16 16 16 1 16 16 16 16 1 16 0 1 1 0 0 16 0 1 16 16 1 2 1 16 16 16 16 16 16 16 1 1 1 16 1 0 1 16 0 0 1 2 16 1 16 1 16 16 1 1 1 16
result:
ok 100 numbers
Test #4:
score: 0
Accepted
time: 7ms
memory: 53152kb
input:
50 10 100 1070103429 28 3 8 26 19 38 8 40 20 16 43 21 38 45 10 38 9 19 6 20 24 19 27 15 31 19 46 24 10 13 16 16 34 6 38 10 18 11 3 10 12 29 1 8 11 10 26 26 8 40 24 24 48 16 14 14 1 1 26 8 32 11 20 41 47 11 38 15 40 40 26 26 48 48 32 47 17 5 5 17 47 15 25 3 42 4 7 33 26 40 2 28 8 8 19 43 35 35 3 28 2...
output:
0 0 0 0 0 1 0 0 0 0 0 0 0 1 2 1 0 1 1 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 1 0 1 0 1 0 1 0 0 0 1 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 1 1 0 0 1 0 0 1 0 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 1 0 0 0 1 0
result:
ok 100 numbers
Test #5:
score: 0
Accepted
time: 66ms
memory: 62588kb
input:
99623 99623 100 980056881 50757 25203 99537 20492 33371 48876 52806 45345 61275 47516 65451 17847 65373 46852 78376 33830 15634 28406 36474 5662 91602 42311 90137 24445 33553 21087 59721 93957 36579 74850 54390 19053 69864 7358 78013 64007 14171 43359 57967 60175 92077 85491 7703 69112 43990 24704 7...
output:
0 1 1 1 1 1 1 1 0 0 1 1 1 1 0 1 0 0 1 1 0 1 1 0 1 0 0 1 0 0 1 0 0 1 0 1 0 1 0 1 1 0 0 0 1 1 0 0 1 0 0 0 1 0 1 1 1 1 0 1 1 0 1 0 1 1 1 1 1 1 0 1 1 1 0 0 1 1 0 1 0 0 1 1 1 1 1 1 1 1 0 1 1 1 0 1 0 0 1 1
result:
ok 100 numbers
Test #6:
score: 0
Accepted
time: 57ms
memory: 62944kb
input:
99918 99918 99998 1022622503 96115 4311 29079 39829 20182 38885 37901 97478 86725 29612 11613 64460 42977 40665 40871 91372 47278 98928 58637 90652 5876 906 93188 99769 93389 85948 82898 6955 50967 30929 28835 31296 97643 231 32832 27254 1524 64074 99349 86599 29210 75922 36883 12162 72002 43881 337...
output:
1 1 1 1 1 0 1 0 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 0 0 1 0 1 0 1 0 1 1 0 0 1 1 1 1 1 1 0 1 0 1 1 1 0 0 0 0 0 1 0 1 1 1 0 0 1 0 0 1 0 1 0 1 0 1 1 1 1 1 1 0 1 1 0 1 1 0 1 1 1 1 1 0 1 1 1 1 0 0 1 1 1 0 0 0 1 0 1 1 1 1 1 0 0 1 0 1 1 1 1 1 1 1 1 1 0 0 0 1 1 0 0 0 1 1 0 0 1 0 1 1 1 1 1 1 0 1 0 1 0 1 1 0 1 1 ...
result:
ok 99998 numbers
Test #7:
score: 0
Accepted
time: 59ms
memory: 64504kb
input:
99400 99058 100 899083628 39194 29750 54542 38986 59905 14414 15149 97934 34222 83755 57222 15382 72075 71746 90174 46964 79135 84263 92426 7282 91385 2634 24502 61087 25413 52486 62136 41629 7136 39660 81877 38747 3061 24370 90906 16423 207 19272 87998 60759 18593 96794 80669 81733 75533 16976 485 ...
output:
0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 1 0 1 0 0 0 1 0 0 1 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 1 0 0 1
result:
ok 100 numbers
Test #8:
score: 0
Accepted
time: 63ms
memory: 62352kb
input:
99807 99447 99956 941649250 42782 17404 35582 96091 72688 43027 21150 28696 44587 19242 10867 78364 57479 62174 45656 61379 43003 45141 38184 12324 30085 1034 21751 4852 95368 97879 81655 55976 16200 89877 14629 28416 38024 84785 25925 5010 83369 71309 1344 39538 41803 6442 93767 98088 22791 57130 8...
output:
0 1 0 1 0 1 0 1 0 0 1 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 1 0 0 0 0 1 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 1 1 0 0 0 1 0 0 0 0 0 0 0 0 1 1 1 0 1 0 0 0 0 0 1 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 0 0 0 1 0 0 1 0 0 1 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0 ...
result:
ok 99956 numbers
Test #9:
score: 0
Accepted
time: 8ms
memory: 53460kb
input:
992 9880 1000 70378016 984 617 323 892 290 802 696 738 804 155 917 96 973 838 312 821 34 424 163 886 240 177 323 874 450 301 576 426 817 534 125 566 888 942 287 379 20 94 925 276 328 169 942 186 57 316 516 276 904 100 410 443 138 802 281 575 333 750 110 671 12 496 320 147 823 316 599 422 176 377 814...
output:
40082542 40082542 40082542 40082542 40082542 40082542 40082542 0 40082542 40082542 40082542 40082542 40082542 40082542 9787068 40082542 40082542 9787068 40082542 40082542 40082542 0 40082542 40082542 40082542 40082542 40082542 40082542 9787068 40082542 9787068 9787068 0 40082542 40082542 9787068 400...
result:
ok 1000 numbers
Test #10:
score: 0
Accepted
time: 211ms
memory: 82876kb
input:
99676 908027 99980 1000000007 92287 84609 40789 2997 11339 38071 79348 89212 42723 18039 25086 14630 15002 48454 74156 31809 81099 672 58820 34204 42380 54992 72471 67280 22513 68145 97886 53222 67440 52761 67792 40482 24643 63912 59981 33502 20889 28561 12601 33295 33170 80694 25860 75071 26068 133...
output:
0 342735715 685471430 342735715 342735715 342735715 342735715 342735715 342735715 342735715 342735715 342735715 342735715 342735715 342735715 685471430 342735715 342735715 342735715 342735715 342735715 342735715 342735715 685471430 342735715 685471430 0 342735715 342735715 342735715 342735715 685471...
result:
ok 99980 numbers
Test #11:
score: 0
Accepted
time: 204ms
memory: 84688kb
input:
99789 898898 99973 32768 42078 85396 15054 67134 89810 91885 87478 52236 21048 73176 34479 45280 93216 34925 88837 19731 76320 26821 91959 35476 16308 59346 8908 46903 35281 14813 4235 92734 72386 27559 50218 41931 63955 27911 20524 27576 40858 6747 74421 31142 61926 35049 211 18147 64263 69457 1571...
output:
11082 5541 11082 5541 5541 5541 5541 11082 5541 5541 5541 5541 5541 5541 5541 5541 5541 5541 0 5541 5541 5541 5541 5541 5541 5541 11082 5541 5541 5541 5541 5541 5541 5541 5541 5541 11082 5541 5541 5541 0 11082 5541 5541 5541 5541 5541 5541 5541 5541 5541 5541 5541 5541 0 5541 5541 5541 5541 5541 554...
result:
ok 99973 numbers
Test #12:
score: 0
Accepted
time: 197ms
memory: 84612kb
input:
99664 898556 99986 860675994 85253 55130 3111 14635 18732 59278 60532 11464 48288 99546 71199 30046 14561 63310 15653 3752 3912 97856 3705 50910 42674 10971 88351 92992 19700 42674 17139 21949 16140 64530 79106 26601 9790 57294 76311 59462 87545 68991 3756 52301 47331 77521 8284 6947 80386 33961 261...
output:
576248876 576248876 576248876 576248876 576248876 576248876 576248876 576248876 0 576248876 576248876 576248876 576248876 576248876 576248876 576248876 576248876 576248876 576248876 576248876 291821758 0 291821758 576248876 291821758 0 576248876 576248876 576248876 576248876 0 576248876 576248876 57...
result:
ok 99986 numbers
Test #13:
score: 0
Accepted
time: 7ms
memory: 53452kb
input:
1000 9987 1000 1063146582 213 864 870 590 759 470 277 590 940 972 117 115 133 385 561 277 333 253 539 805 720 220 193 818 794 225 851 136 333 87 488 829 31 481 768 73 739 529 905 794 124 195 174 805 529 595 81 431 81 233 713 999 652 768 385 485 636 812 475 758 81 529 799 195 759 535 744 975 209 394 ...
output:
446156645 89231329 89231329 446156645 89231329 907572022 89231329 446156645 1 0 1 0 89231329 0 89231329 89231329 1 89231329 1 1 907572022 0 89231329 1 0 1 89231329 89231329 1 0 89231329 89231329 89231329 1 446156645 0 1 446156645 1 1 89231329 89231329 1 0 446156645 89231329 89231329 1 0 0 0 0 892313...
result:
ok 1000 numbers
Test #14:
score: 0
Accepted
time: 140ms
memory: 81832kb
input:
99961 815966 99991 19683 28582 16563 15302 50712 61184 5163 22446 21775 78337 12895 43968 16679 87757 140 15367 29739 84067 16016 62557 65137 38670 80599 9548 34969 96285 55127 61588 1732 29351 13191 39945 16016 40103 15748 96767 48885 62341 79520 47488 23205 91177 18442 69914 6305 15023 42307 43039...
output:
12060 2829 0 0 16085 0 18924 18502 2830 0 2830 0 0 2035 0 10502 0 0 0 0 0 5247 12060 0 0 0 0 16085 13256 16930 0 2035 18924 5669 0 0 0 16085 0 16085 18924 0 0 0 0 0 18924 12060 16085 0 14060 16085 12060 0 0 18924 0 0 0 0 16085 0 0 12060 0 0 0 14080 16085 0 16085 0 0 16085 0 16930 0 0 0 0 16085 0 0 1...
result:
ok 99991 numbers
Test #15:
score: 0
Accepted
time: 163ms
memory: 82156kb
input:
99462 813007 99992 779702741 37081 12978 57353 64379 85797 164 1520 86507 84134 10450 81061 4901 91664 12347 28028 97732 13558 1222 96104 90535 73047 58083 84350 58856 57411 70765 12160 59380 34674 55254 81566 18238 76503 47810 44994 87776 84294 1664 2142 74766 58209 16327 25833 95289 43553 14681 63...
output:
504392388 311179206 713599917 306961279 0 713599917 0 0 0 0 1 0 0 0 0 343707493 713599917 0 0 480131069 282699960 0 335440525 0 0 0 0 335440525 0 0 755441423 317860336 311179206 317860336 311179206 0 0 311179206 0 0 0 311179206 0 317860336 0 317860336 311179206 306961279 311179206 0 0 282699960 1 0 ...
result:
ok 99992 numbers
Test #16:
score: 0
Accepted
time: 92ms
memory: 68736kb
input:
9890 771347 100000 10007 1807 8193 7832 7478 8096 4467 8382 6002 9571 4866 2460 7389 8922 3733 2965 14 3122 2206 5592 1550 8015 589 8015 8284 9570 6326 5207 3284 7986 2291 3388 1677 7252 6891 8551 890 8328 8284 6327 5277 3251 2335 5276 5622 618 9398 5660 9661 9676 7551 5456 9523 1073 4454 4200 2785 ...
output:
0 4049 1602 4049 1370 1602 5933 7965 1370 1602 1370 3395 6897 0 435 5933 4049 1370 0 9400 3395 1602 8812 1602 4049 8812 9400 4049 0 4049 0 0 1370 0 3138 4049 0 0 6897 4049 6607 2922 6607 6607 1602 9400 1112 0 3138 1602 1370 9400 9400 5530 1602 1602 0 9400 0 2922 5530 0 0 7982 3395 9400 6607 6897 0 0...
result:
ok 100000 numbers
Test #17:
score: 0
Accepted
time: 147ms
memory: 74028kb
input:
99811 699197 99991 15625 86625 59478 20812 76888 55859 93386 17571 93823 20330 56315 41644 68214 64293 51049 49283 7151 16866 65744 7510 4546 13611 52692 86190 30703 12972 62703 54411 67707 74890 78525 16683 47000 9696 53982 49693 26011 30180 49236 44952 96435 41946 96670 99398 8212 1457 18086 50058...
output:
0 6865 2501 0 3870 9835 2765 9835 13695 0 0 13655 0 0 13695 13695 0 11465 0 194 1830 11080 0 1245 4621 12851 0 0 9338 890 0 0 0 3940 1 0 0 11346 11346 0 0 13695 0 0 2765 13570 13860 0 0 2377 5030 0 0 0 0 0 0 194 1 0 0 890 9835 6865 0 0 6831 1103 13695 7415 3391 1842 0 0 0 5030 4621 0 14920 0 0 0 0 0...
result:
ok 99991 numbers
Test #18:
score: 0
Accepted
time: 652ms
memory: 110060kb
input:
497874 982381 999937 1000000009 213037 19051 434410 167830 97789 439284 118053 294932 445258 186947 42988 89834 445703 168088 359863 390501 147993 224527 61303 136397 134286 301377 306820 226022 305074 461583 394818 410890 479262 256077 212167 410479 121597 331240 407580 342240 118032 435057 402915 ...
output:
354442583 0 0 0 0 1 935377062 49487291 0 354442583 0 0 999239563 999239563 354442583 0 0 0 0 0 0 0 0 399512194 0 0 714160876 496968815 231209613 213172207 0 0 0 0 0 0 1 0 846168135 0 154118383 0 0 0 904720298 744498487 655421219 324180828 0 744498487 0 27777530 744498487 0 201687494 0 231209613 8407...
result:
ok 999937 numbers
Test #19:
score: 0
Accepted
time: 722ms
memory: 114076kb
input:
494830 885706 999958 2401 124692 425460 122070 362854 210240 452328 240245 279078 376495 397976 77586 253505 280732 186356 149244 146584 462101 422526 268812 365792 400507 140426 10445 358775 194169 492348 325454 33248 252000 79290 51412 36781 387850 452871 481401 348596 11068 203053 91484 287059 16...
output:
0 111 51 757 0 0 0 0 22 0 0 63 379 1878 0 0 1 0 1 0 1878 0 1850 1 2329 102 1657 1 0 1142 0 0 0 380 0 1332 1 0 0 0 0 0 0 0 325 0 0 1 1 757 757 2350 0 0 577 0 0 0 0 1575 0 0 0 1850 1 11 0 0 0 1290 0 760 1 0 1 0 1663 0 0 1 1896 11 1 0 0 0 757 0 0 189 505 1012 1682 0 0 63 757 0 1 1 1012 954 0 0 2329 0 6...
result:
ok 999958 numbers
Test #20:
score: 0
Accepted
time: 70ms
memory: 46804kb
input:
70 0 999815 736939200 28 15 12 40 66 66 68 60 59 16 41 41 52 1 31 31 40 19 13 51 31 14 58 42 61 34 56 25 63 63 50 11 36 67 12 12 58 55 0 19 21 55 46 46 67 8 28 25 25 50 9 69 55 42 51 46 7 7 7 59 66 14 60 60 40 65 13 34 52 52 23 39 38 43 67 10 35 52 66 47 25 25 14 50 44 23 21 21 19 19 45 1 32 35 64 6...
output:
0 0 1 0 0 1 0 1 0 0 0 0 0 0 1 0 0 1 0 0 0 1 0 0 0 0 0 0 1 0 0 1 0 0 1 0 0 0 0 0 1 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 1 1 0 1 1 1 0 0 0 1 0 0 1 1 1 1 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 1 0 0 0 0 0 1 0 1 0 1 0 0 1 0 0 0 0 0 1 0 0 1 1 0 0 0 1 1 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 1 0 ...
result:
ok 999815 numbers
Extra Test:
score: 0
Extra Test Passed