QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#420170#6346. Record Parityushg8877#WA 113ms19328kbC++14982b2024-05-24 15:03:242024-05-24 15:03:24

Judging History

你现在查看的是最新测评结果

  • [2024-05-24 15:03:24]
  • 评测
  • 测评结果:WA
  • 用时:113ms
  • 内存:19328kb
  • [2024-05-24 15:03:24]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MP make_pair
const int MAXN=1e6+5;
const int MOD=998244353;
int n,k,p[MAXN],p1[MAXN],ls[MAXN];
int st[MAXN],top;bool vis[MAXN];
ll fac[MAXN],inf[MAXN];
ll ksm(ll a,int b){ll r=1;while(b){if(b&1)r=r*a%MOD;a=a*a%MOD,b>>=1;}return r;}
ll C(int x,int y){return (x>y||x<0)?0:fac[y]*inf[x]%MOD*inf[y-x]%MOD;}
int main(){
	ios::sync_with_stdio(false);
	// freopen("Otomachi_Una.in","r",stdin);
	// freopen("Otomachi_Una.out","w",stdout);
	inf[0]=fac[0]=1;
	for(int i=1;i<MAXN;i++) inf[i]=ksm(fac[i]=fac[i-1]*i%MOD,MOD-2);
	cin>>n>>k;
	for(int i=1;i<=n;i++) cin>>p[i],p1[p[i]]=i;
	for(int i=1;i<=n;i++){
		while(top&&p[st[top]]>p[i]) top--;
		ls[st[top]]=i;
		st[++top]=i;
	}
	ll ans=0;
	for(int i=1;i<=n;i++){
		int u=p1[i],cnt=0;
		if(vis[u]) continue;
		while(u){
			vis[u]=true;cnt++;u=ls[u];
		}
		ans+=C(k,cnt);
	}
	ans=(k&1?-1:1)*ans;
	cout<<(ans%MOD+MOD)%MOD;
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 109ms
memory: 19248kb

input:

5 2
4 1 2 5 3

output:

3

result:

ok 1 number(s): "3"

Test #2:

score: 0
Accepted
time: 105ms
memory: 19328kb

input:

7 3
1 2 3 4 5 6 7

output:

998244318

result:

ok 1 number(s): "998244318"

Test #3:

score: 0
Accepted
time: 113ms
memory: 19192kb

input:

5 5
2 5 4 1 3

output:

0

result:

ok 1 number(s): "0"

Test #4:

score: -100
Wrong Answer
time: 113ms
memory: 19252kb

input:

10 3
9 7 3 6 10 4 8 2 5 1

output:

998244352

result:

wrong answer 1st numbers differ - expected: '0', found: '998244352'