提交记录 5168


用户 题目 状态 得分 用时 内存 语言 代码长度
noi18std noi18b. 【NOI2018】冒泡排序 Accepted 100 86.803 ms 14108 KB C++11 867 B
提交时间 评测时间
2018-08-08 21:56:34 2020-08-01 00:12:54
#include<bits/stdc++.h>
using namespace std;

const int N=1200005,M=998244353;
int n,a[N],v[N],fc[N],fi[N];
int C(int x,int y){
	if(x<0||y<0||x<y)return 0;
	return 1ll*fc[x]*fi[y]%M*fi[x-y]%M;
}
int fexp(int x,int t){
	if(!t)return 1;
	int tmp=fexp(x,t>>1);tmp=1ll*tmp*tmp%M;
	return (t&1)?1ll*tmp*x%M:tmp;
}
void Main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	for(int i=1;i<=n;i++)v[i]=0;
	int mx=0,l=1;
	long long ans=0;
	for(int i=1;i<=n;i++){
		mx=max(a[i],mx);int t=2*n-mx-i,s=n-i+1;
		ans=(ans+C(t,s)-C(t,s+1)+M)%M;
		if(l>a[i])ans=(ans+C(t,s-1)-C(t,s)+M)%M;
		if(a[i]!=mx&&a[i]!=l)break;
		for(v[a[i]]=1;v[l];l++);
	}
	printf("%d\n",ans);
}
int main(){
	fc[0]=1;
	for(int i=1;i<N;i++)fc[i]=1ll*fc[i-1]*i%M;
	fi[N-1]=fexp(fc[N-1],M-2);
	for(int i=N-2;i>=0;i--)fi[i]=1ll*fi[i+1]*(i+1)%M;
	int T;scanf("%d",&T);
	while(T--)Main();
	return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #111.118 ms9 MB + 204 KBAcceptedScore: 4

Testcase #211.127 ms9 MB + 204 KBAcceptedScore: 4

Testcase #311.127 ms9 MB + 204 KBAcceptedScore: 4

Testcase #411.121 ms9 MB + 204 KBAcceptedScore: 4

Testcase #511.119 ms9 MB + 204 KBAcceptedScore: 4

Testcase #611.12 ms9 MB + 204 KBAcceptedScore: 4

Testcase #711.119 ms9 MB + 204 KBAcceptedScore: 4

Testcase #811.118 ms9 MB + 204 KBAcceptedScore: 4

Testcase #911.118 ms9 MB + 204 KBAcceptedScore: 4

Testcase #1011.117 ms9 MB + 204 KBAcceptedScore: 4

Testcase #1111.119 ms9 MB + 204 KBAcceptedScore: 4

Testcase #1211.135 ms9 MB + 208 KBAcceptedScore: 4

Testcase #1311.138 ms9 MB + 208 KBAcceptedScore: 4

Testcase #1411.137 ms9 MB + 208 KBAcceptedScore: 4

Testcase #1511.138 ms9 MB + 208 KBAcceptedScore: 4

Testcase #1611.141 ms9 MB + 208 KBAcceptedScore: 4

Testcase #1711.235 ms9 MB + 208 KBAcceptedScore: 4

Testcase #1811.239 ms9 MB + 208 KBAcceptedScore: 4

Testcase #1911.239 ms9 MB + 208 KBAcceptedScore: 4

Testcase #2011.245 ms9 MB + 212 KBAcceptedScore: 4

Testcase #2158.013 ms11 MB + 240 KBAcceptedScore: 4

Testcase #2270.253 ms11 MB + 760 KBAcceptedScore: 4

Testcase #2384.5 ms12 MB + 604 KBAcceptedScore: 4

Testcase #2486.803 ms13 MB + 448 KBAcceptedScore: 4

Testcase #2585.657 ms13 MB + 796 KBAcceptedScore: 4


Judge Duck Online | 评测鸭在线
Server Time: 2024-12-05 09:59:59 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠