提交记录 4253


用户 题目 状态 得分 用时 内存 语言 代码长度
wxs666666 noi18b. 【NOI2018】冒泡排序 Accepted 100 256.255 ms 25796 KB C++ 1.37 KB
提交时间 评测时间
2018-07-19 11:12:05 2020-07-31 22:47:55
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;

#define lg long long
#define MN 1200005
#define lsk 998244353
#define lb(x) ((x)&(-(x)))

int n;
int a[MN>>1],c[MN>>1],D[MN>>1];

int read(){
	static int d;static char c;
	for(d=0,c=getchar();c<'0'||c>'9';c=getchar());
	for(;c>='0'&&c<='9';d=(d<<3)+(d<<1)+c-'0',c=getchar());
	return d;
}

void add(int x,int y){
	for(;x<=n;x+=lb(x))c[x]+=y;
}

int qry(int x){
	int res=0;
	for(;x;x-=lb(x))res+=c[x];
	return res;
}

lg fac[MN],ifac[MN];

lg Pow(lg A,lg B){
	lg res=1;
	for(;B;B>>=1,A=A*A%lsk)if(B&1)res=res*A%lsk;
	return res;
}

void init(){
	fac[0]=ifac[0]=1;
	for(int i=1;i<MN;++i){
		fac[i]=fac[i-1]*i%lsk;
		ifac[i]=Pow(fac[i],lsk-2);
	}
}

lg C(int A,int B){
	return fac[A]*ifac[B]%lsk*ifac[A-B]%lsk;
}

lg Q(int A,int B){
	return C(A,(A+B)/2);
}

lg T(int A,int B){
	if(B<0)return 0;
	return ((Q(A,B)-Q(A,B+2))%lsk+lsk)%lsk;
}

int main(){
	int TT;init();
	scanf("%d",&TT);
	while(TT--){
		memset(D,0,sizeof D);
		memset(c,0,sizeof c);
		scanf("%d",&n);lg res=0;
		for(int i=1;i<=n;++i)add(i,1);
		for(int i=1;i<=n;++i)a[i]=read();
		int mx=0,mn=1;
		for(int i=1;i<n;++i){
			int g=max(mx,a[i]);
			int f=qry(g)+1;
			int d=n*2-(i-1)*2-f;
			res=(res+T(d,f))%lsk;
			D[a[i]]=1;add(a[i],-1);
			if(a[i]>mx)mx=a[i];
			else{
			    if(a[i]!=mn)break;
			}
			while(D[mn])++mn;
		}
		printf("%lld\n",res);
	}
	return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #1132.596 ms22 MB + 928 KBAcceptedScore: 4

Testcase #2132.602 ms22 MB + 928 KBAcceptedScore: 4

Testcase #3132.603 ms22 MB + 928 KBAcceptedScore: 4

Testcase #4132.598 ms22 MB + 928 KBAcceptedScore: 4

Testcase #5132.597 ms22 MB + 928 KBAcceptedScore: 4

Testcase #6132.6 ms22 MB + 928 KBAcceptedScore: 4

Testcase #7132.598 ms22 MB + 928 KBAcceptedScore: 4

Testcase #8132.597 ms22 MB + 928 KBAcceptedScore: 4

Testcase #9132.598 ms22 MB + 928 KBAcceptedScore: 4

Testcase #10132.601 ms22 MB + 928 KBAcceptedScore: 4

Testcase #11132.6 ms22 MB + 928 KBAcceptedScore: 4

Testcase #12132.614 ms22 MB + 928 KBAcceptedScore: 4

Testcase #13132.618 ms22 MB + 928 KBAcceptedScore: 4

Testcase #14132.617 ms22 MB + 928 KBAcceptedScore: 4

Testcase #15132.618 ms22 MB + 928 KBAcceptedScore: 4

Testcase #16132.622 ms22 MB + 928 KBAcceptedScore: 4

Testcase #17132.712 ms22 MB + 932 KBAcceptedScore: 4

Testcase #18132.722 ms22 MB + 932 KBAcceptedScore: 4

Testcase #19132.722 ms22 MB + 932 KBAcceptedScore: 4

Testcase #20132.73 ms22 MB + 932 KBAcceptedScore: 4

Testcase #21195.539 ms23 MB + 948 KBAcceptedScore: 4

Testcase #22210.548 ms24 MB + 184 KBAcceptedScore: 4

Testcase #23232.389 ms24 MB + 616 KBAcceptedScore: 4

Testcase #24252.911 ms25 MB + 28 KBAcceptedScore: 4

Testcase #25256.255 ms25 MB + 196 KBAcceptedScore: 4


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