QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#642172 | #6346. Record Parity | ship2077 | RE | 21ms | 11612kb | C++23 | 886b | 2024-10-15 11:26:17 | 2024-10-15 11:26:17 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
constexpr int M=5e5+5,mod=998244353;
int n,k,tp,ans,a[M],stk[M],fac[M],ifac[M];
int read(){
int x=0;char ch=getchar();
while (!isdigit(ch)) ch=getchar();
while (isdigit(ch)) x=x*10+ch-48,ch=getchar();
return x;
}
int qpow(int x,int n){
int s=1; while (n){
if (n&1) s=1ll*s*x%mod;
x=1ll*x*x%mod; n>>=1;
} return s;
}
void init(int n){
for (int i=fac[0]=1;i<=n;i++) fac[i]=1ll*fac[i-1]*i%mod;
ifac[n]=qpow(fac[n],mod-2);
for (int i=n;i;i--) ifac[i-1]=1ll*ifac[i]*i%mod;
}
int main(){
n=read();k=read();init(n);
for (int i=1;i<=n;i++){
a[i]=read();
while (tp&&a[stk[tp]]>a[i]) tp--;
stk[++tp]=i;
}
ans=tp>=k?1ll*fac[tp]*ifac[k]%mod*ifac[tp-k]%mod:0;
if (k&1&&ans) ans=mod-ans;
printf("%d\n",ans);
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 9932kb
input:
5 2 4 1 2 5 3
output:
3
result:
ok 1 number(s): "3"
Test #2:
score: 0
Accepted
time: 0ms
memory: 9896kb
input:
7 3 1 2 3 4 5 6 7
output:
998244318
result:
ok 1 number(s): "998244318"
Test #3:
score: 0
Accepted
time: 1ms
memory: 9888kb
input:
5 5 2 5 4 1 3
output:
0
result:
ok 1 number(s): "0"
Test #4:
score: 0
Accepted
time: 1ms
memory: 7824kb
input:
10 3 9 7 3 6 10 4 8 2 5 1
output:
0
result:
ok 1 number(s): "0"
Test #5:
score: 0
Accepted
time: 1ms
memory: 7912kb
input:
100 76 40 30 48 76 60 22 52 75 31 23 63 86 94 3 45 93 73 37 88 96 77 67 84 85 97 79 25 69 49 47 51 91 58 28 41 53 78 5 46 65 42 56 26 50 64 61 83 29 71 59 9 66 39 32 44 6 8 55 2 54 35 38 72 33 43 99 16 12 62 80 89 98 90 74 87 100 57 11 15 24 7 68 21 27 36 10 92 82 14 95 13 81 20 1 19 17 34 70 18 4
output:
0
result:
ok 1 number(s): "0"
Test #6:
score: 0
Accepted
time: 21ms
memory: 11612kb
input:
999999 39332 451414 609108 131036 847161 253700 55582 818258 222276 337577 950477 824707 809617 551654 567203 661380 421234 351861 954465 73542 956874 530136 870993 631237 988010 133954 853588 558656 321266 299916 335021 347302 275968 582468 281193 693266 634308 744833 497969 394896 778896 710277 42...
output:
0
result:
ok 1 number(s): "0"
Test #7:
score: -100
Runtime Error
input:
1000000 46282 375837 94088 104451 696764 777873 787329 97811 343419 440438 65609 4790 470282 363111 811237 253643 28392 882823 98152 156690 823537 77896 380936 675851 402343 705542 543953 781400 8146 338069 98261 262758 527678 637070 226497 825938 85884 654134 676334 743404 799028 584462 219375 2467...