QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#395404 | #3090. Inverse Problem | Graphcity | AC ✓ | 15ms | 17988kb | C++20 | 1.3kb | 2024-04-21 14:15:09 | 2024-04-21 14:15:10 |
Judging History
answer
#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rof(i,a,b) for(int i=(a);i>=(b);--i)
using namespace std;
const int Maxn=1e6,Mod=998244353,i2=(Mod+1)/2;
inline int read()
{
int x=0,f=1;
char ch=getchar();
while(ch<'0' || ch>'9')
{
if(ch=='-') f=-1;
ch=getchar();
}
while(ch>='0' && ch<='9')
{
x=x*10+ch-'0';
ch=getchar();
}
return x*f;
}
inline int Pow(int x,int y)
{
int res=1;
while(y)
{
if(y&1) res=1ll*res*x%Mod;
x=1ll*x*x%Mod,y>>=1;
}
return res;
}
int n,m,ans,a[Maxn+5],fac[Maxn+5],inv[Maxn+5],vis[Maxn+5];
inline int C(int x,int y) {return 1ll*fac[x]*inv[x-y]%Mod*inv[y]%Mod;}
int main()
{
// freopen("1.in","r",stdin);
n=read(),m=read(); fac[0]=inv[0]=1;
For(i,1,Maxn) fac[i]=1ll*fac[i-1]*i%Mod;
inv[Maxn]=Pow(fac[Maxn],Mod-2);
Rof(i,Maxn-1,1) inv[i]=1ll*inv[i+1]*(i+1)%Mod;
For(i,1,m) a[i]=read(),vis[a[i]]=1;
int p=m; For(i,1,m-1) if(a[i]>a[i+1]) {p=i; break;}
For(i,p+1,m) vis[a[i]]=2;
int ans=1,cnt=0,cur=0;
For(i,1,n)
{
if(vis[i])
{
cur+=(vis[i]==1);
if(i==a[p]) cur++;
continue;
}
ans=1ll*ans*(cnt+cur)%Mod,cnt++;
} cout<<ans<<endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 7ms
memory: 13952kb
input:
7 2 2 1
output:
720
result:
ok single line: '720'
Test #2:
score: 0
Accepted
time: 10ms
memory: 13832kb
input:
8 5 2 3 4 5 8
output:
0
result:
ok single line: '0'
Test #3:
score: 0
Accepted
time: 6ms
memory: 13952kb
input:
498 121 20 35 40 72 79 92 113 117 154 231 243 244 264 268 304 337 362 378 463 477 56 494 495 1 342 395 183 423 291 475 82 422 96 265 83 283 242 34 187 75 74 47 208 380 400 17 202 50 418 73 233 307 181 344 48 149 107 435 365 459 280 55 375 391 403 241 64 374 10 386 322 308 186 136 277 497 332 262 165...
output:
0
result:
ok single line: '0'
Test #4:
score: 0
Accepted
time: 10ms
memory: 13964kb
input:
499 396 2 3 6 8 11 13 14 15 16 19 22 23 24 32 36 37 40 41 44 51 53 56 57 58 61 62 66 68 74 75 76 79 80 85 86 87 89 90 91 92 96 98 101 102 109 110 111 113 114 115 117 119 122 123 127 129 130 135 140 141 145 149 150 160 163 166 167 171 173 176 177 183 185 195 197 200 204 207 210 216 217 229 230 235 23...
output:
824443602
result:
ok single line: '824443602'
Test #5:
score: 0
Accepted
time: 6ms
memory: 13832kb
input:
500 484 2 3 6 9 11 14 16 17 19 22 23 24 25 26 28 30 31 34 36 37 41 51 52 53 57 60 62 63 64 67 69 73 74 79 81 83 85 87 88 92 101 103 105 108 113 119 120 122 123 125 126 127 128 129 130 131 134 136 137 140 142 146 149 151 152 156 157 158 159 160 162 163 165 169 170 172 175 178 183 184 185 187 194 197 ...
output:
571655683
result:
ok single line: '571655683'
Test #6:
score: 0
Accepted
time: 5ms
memory: 13960kb
input:
500 25 6 16 62 1 91 97 112 158 186 300 327 362 364 367 401 412 180 297 254 372 302 131 38 346 321
output:
0
result:
ok single line: '0'
Test #7:
score: 0
Accepted
time: 10ms
memory: 14884kb
input:
249999 198363 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 31 32 33 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 76 77 78 83 86 87 88 90 94 95 96 98 99 100 101 105 106 107 108 109 110 111 112 113...
output:
190813000
result:
ok single line: '190813000'
Test #8:
score: 0
Accepted
time: 9ms
memory: 16136kb
input:
250000 112504 1 4 5 6 9 10 12 15 16 20 21 24 25 27 29 32 33 35 49 57 58 59 60 61 62 63 65 66 67 70 72 73 75 76 78 83 84 86 88 92 94 95 96 98 103 104 107 109 110 111 112 120 124 125 129 130 132 135 137 138 139 140 152 153 154 156 158 161 163 164 167 168 171 172 174 177 179 181 182 184 185 188 193 194...
output:
276915868
result:
ok single line: '276915868'
Test #9:
score: 0
Accepted
time: 4ms
memory: 16544kb
input:
250000 13727 1 18 25 28 30 35 56 66 106 138 205 247 305 322 376 387 408 425 427 476 478 508 517 559 562 565 586 619 642 650 672 676 687 718 747 748 789 796 820 830 844 852 854 875 879 916 923 982 1050 1064 1119 1122 1134 1158 1163 1167 1197 1200 1211 1302 1303 1330 1376 1400 1406 1411 1427 1450 1452...
output:
453743268
result:
ok single line: '453743268'
Test #10:
score: 0
Accepted
time: 13ms
memory: 14868kb
input:
250000 111448 1 5 6 10 11 13 16 19 21 24 25 26 29 33 37 38 40 42 46 47 51 52 54 55 58 59 61 63 67 68 70 71 72 73 74 75 77 82 84 85 87 88 89 90 91 95 96 98 104 105 107 110 111 115 116 118 119 120 123 124 126 127 129 130 133 137 138 139 140 143 144 147 150 151 155 161 162 164 167 168 169 170 171 175 1...
output:
447677020
result:
ok single line: '447677020'
Test #11:
score: 0
Accepted
time: 14ms
memory: 14872kb
input:
249999 106534 8 1 65 66 102 115 150 183 188 189 200 205 229 231 262 292 305 343 400 429 471 507 520 529 530 627 693 699 829 840 897 960 972 1110 1179 1202 1217 1225 1263 1264 1301 1325 1334 1423 1434 1452 1543 1579 1585 1598 1660 1667 1687 1689 1705 1707 1792 1800 1861 1885 2027 2137 2173 2205 2209 ...
output:
0
result:
ok single line: '0'
Test #12:
score: 0
Accepted
time: 11ms
memory: 17988kb
input:
250000 215199 2 1 3 4 6 8 9 10 11 13 14 16 20 21 22 23 26 29 30 32 36 37 38 41 46 47 50 51 53 62 67 69 70 71 72 73 75 77 84 87 88 90 95 97 98 99 101 102 106 109 111 112 115 117 118 120 123 126 127 130 131 134 136 138 139 140 142 145 147 149 151 152 154 155 157 159 161 162 163 164 165 167 172 173 174...
output:
840500544
result:
ok single line: '840500544'
Test #13:
score: 0
Accepted
time: 14ms
memory: 16268kb
input:
250000 128016 4 1 9 10 14 18 19 20 28 34 35 40 43 44 45 47 48 49 60 67 71 79 80 82 84 85 88 89 92 94 102 104 109 111 112 115 117 123 125 126 129 140 147 149 151 155 159 162 164 166 172 177 180 184 187 189 193 197 198 200 201 210 212 214 216 222 223 225 226 227 229 234 237 243 248 251 253 255 256 258...
output:
548846886
result:
ok single line: '548846886'
Test #14:
score: 0
Accepted
time: 12ms
memory: 12876kb
input:
250000 86285 35 1 225 325 457 589 619 747 756 1252 1310 1388 1505 1709 1794 1808 1936 1951 2144 2165 2250 2354 2443 2482 2577 2622 2638 2707 2909 2965 3048 3081 3198 3408 3428 3438 3541 3548 3634 3722 3741 4080 4193 4228 4235 4237 4244 4264 4641 4658 4707 4768 4965 5021 5049 5144 5203 5230 5284 5287...
output:
0
result:
ok single line: '0'
Test #15:
score: 0
Accepted
time: 14ms
memory: 16916kb
input:
249999 161229 5 9 10 18 19 20 21 29 30 34 40 47 48 49 50 52 54 55 56 58 62 69 76 80 81 85 88 92 103 105 113 123 127 129 131 138 146 147 152 155 157 163 164 170 172 175 176 177 180 181 184 188 189 192 194 196 199 211 213 214 221 222 225 227 228 234 235 241 242 243 246 247 249 252 254 255 269 271 275 ...
output:
0
result:
ok single line: '0'
Test #16:
score: 0
Accepted
time: 7ms
memory: 12824kb
input:
250000 10338 109 114 151 176 267 294 334 393 466 485 554 660 675 680 739 913 925 959 1042 1073 1083 1122 1125 1218 1280 1294 1389 1420 1486 1787 1912 1934 1937 1974 2068 2094 2186 2355 2397 2491 2544 2671 2761 2766 2855 2971 3230 3290 3445 3485 3497 3736 3840 3963 3992 3994 4064 4195 4255 4321 4487 ...
output:
0
result:
ok single line: '0'
Test #17:
score: 0
Accepted
time: 15ms
memory: 16980kb
input:
250000 250000 2 5 6 7 8 10 11 12 13 14 17 31 32 33 38 40 42 44 47 48 51 54 55 56 59 61 62 64 66 70 71 73 81 82 84 85 86 88 89 93 96 97 100 101 105 108 109 110 111 118 119 120 123 124 125 126 131 132 133 135 136 137 138 140 141 144 145 146 147 149 150 151 152 153 155 156 163 165 168 169 170 171 172 1...
output:
1
result:
ok single line: '1'
Test #18:
score: 0
Accepted
time: 15ms
memory: 16784kb
input:
250000 198427 1 2 5 7 11 13 14 18 22 24 25 28 31 32 35 36 39 41 42 45 47 48 49 50 51 54 58 61 67 68 70 76 78 80 81 82 86 87 91 92 93 94 97 98 99 100 102 104 111 113 115 117 118 119 122 123 126 132 134 135 136 137 139 140 143 146 148 149 151 152 155 156 159 161 162 164 166 169 170 171 173 174 177 178...
output:
250004123
result:
ok single line: '250004123'
Test #19:
score: 0
Accepted
time: 14ms
memory: 16920kb
input:
250000 131590 1 3 4 9 12 14 15 17 20 25 26 28 29 33 34 38 39 45 46 47 50 51 53 54 56 59 60 67 69 72 74 76 79 85 86 87 88 91 92 97 100 101 102 103 106 110 114 116 117 122 123 126 129 133 135 136 137 139 146 147 151 152 153 154 156 163 166 167 170 171 172 173 174 176 177 182 185 187 190 191 192 195 20...
output:
120108800
result:
ok single line: '120108800'
Test #20:
score: 0
Accepted
time: 8ms
memory: 12756kb
input:
250000 47772 2 13 16 60 109 166 172 208 235 254 335 383 392 393 401 405 413 548 559 572 573 588 656 674 710 726 814 828 880 921 940 1029 1034 1048 1075 1093 1109 1170 1228 1246 1285 1302 1342 1356 1406 1419 1494 1508 1559 1576 1583 1606 1618 1690 1700 1710 1724 1757 1766 1772 1805 1807 1872 1877 189...
output:
82858423
result:
ok single line: '82858423'