QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#240808#6348. Egor Has a Problem45645A#TL 0ms0kbC++171.1kb2023-11-05 19:29:432023-11-05 19:29:43

Judging History

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

  • [2023-11-05 19:29:43]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2023-11-05 19:29:43]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
inline int read()
{
	char ch;
	while((ch=getchar())<'0'||ch>'9');
	int res=ch-'0';
	while((ch=getchar())>='0'&&ch<='9') res=res*10+ch-'0';
	return res;
}
const int N=1000100;
const int mod=998244353;
int n,a[N],jc[N],ny[N];
int ksm(int x,int K)
{
	int res=1;
	while(K)
	{
		if(K&1) res=1ll*res*x%mod;
		K>>=1;
		x=1ll*x*x%mod;
	}
	return res;
}
int C(int n,int m)
{
	return 1ll*jc[n]*ny[n-m]%mod*ny[m]%mod;
}
int mn[N],b[N];
int main()
{
	n=read();int K=read();
	jc[0]=1;
	for(int i=1;i<=n;i++) a[i]=read(),jc[i]=1ll*jc[i-1]*i%mod;
	ny[n]=ksm(jc[n],mod-2);
	for(int i=n-1;i>=0;i--) ny[i]=1ll*ny[i+1]*(i+1)%mod;
	mn[n+1]=n+1;
	for(int i=n;i>=1;i--) mn[i]=min(mn[i+1],a[i]);
	int tmp=0,ans=0;
	for(int i=1;i<=n;i++)
	{
		int lst=0;
		if(!tmp||a[i]>b[tmp]) b[lst=++tmp]=a[i];
		else
		{
			int l=1,r=tmp;
			while(l<=r)
			{
				int mid=l+r>>1;
				if(b[mid]>a[i]) r=mid-1;
				else l=mid+1;
			}
			b[lst=l]=a[i];
		}
		if(lst>=K&&a[i]<mn[i+1]) (ans+=C(lst-1,K-1))%=mod;
	}
	if(K&1) printf("%d",(mod-ans)%mod);
	else printf("%d",ans);
	return 0;
}

詳細信息

Test #1:

score: 0
Time Limit Exceeded

input:

6
2 6 11 21 47 120

output:


result: