提交记录 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;
}
Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
Testcase #1 | 132.596 ms | 22 MB + 928 KB | Accepted | Score: 4 | 显示更多 |
Testcase #2 | 132.602 ms | 22 MB + 928 KB | Accepted | Score: 4 | 显示更多 |
Testcase #3 | 132.603 ms | 22 MB + 928 KB | Accepted | Score: 4 | 显示更多 |
Testcase #4 | 132.598 ms | 22 MB + 928 KB | Accepted | Score: 4 | 显示更多 |
Testcase #5 | 132.597 ms | 22 MB + 928 KB | Accepted | Score: 4 | 显示更多 |
Testcase #6 | 132.6 ms | 22 MB + 928 KB | Accepted | Score: 4 | 显示更多 |
Testcase #7 | 132.598 ms | 22 MB + 928 KB | Accepted | Score: 4 | 显示更多 |
Testcase #8 | 132.597 ms | 22 MB + 928 KB | Accepted | Score: 4 | 显示更多 |
Testcase #9 | 132.598 ms | 22 MB + 928 KB | Accepted | Score: 4 | 显示更多 |
Testcase #10 | 132.601 ms | 22 MB + 928 KB | Accepted | Score: 4 | 显示更多 |
Testcase #11 | 132.6 ms | 22 MB + 928 KB | Accepted | Score: 4 | 显示更多 |
Testcase #12 | 132.614 ms | 22 MB + 928 KB | Accepted | Score: 4 | 显示更多 |
Testcase #13 | 132.618 ms | 22 MB + 928 KB | Accepted | Score: 4 | 显示更多 |
Testcase #14 | 132.617 ms | 22 MB + 928 KB | Accepted | Score: 4 | 显示更多 |
Testcase #15 | 132.618 ms | 22 MB + 928 KB | Accepted | Score: 4 | 显示更多 |
Testcase #16 | 132.622 ms | 22 MB + 928 KB | Accepted | Score: 4 | 显示更多 |
Testcase #17 | 132.712 ms | 22 MB + 932 KB | Accepted | Score: 4 | 显示更多 |
Testcase #18 | 132.722 ms | 22 MB + 932 KB | Accepted | Score: 4 | 显示更多 |
Testcase #19 | 132.722 ms | 22 MB + 932 KB | Accepted | Score: 4 | 显示更多 |
Testcase #20 | 132.73 ms | 22 MB + 932 KB | Accepted | Score: 4 | 显示更多 |
Testcase #21 | 195.539 ms | 23 MB + 948 KB | Accepted | Score: 4 | 显示更多 |
Testcase #22 | 210.548 ms | 24 MB + 184 KB | Accepted | Score: 4 | 显示更多 |
Testcase #23 | 232.389 ms | 24 MB + 616 KB | Accepted | Score: 4 | 显示更多 |
Testcase #24 | 252.911 ms | 25 MB + 28 KB | Accepted | Score: 4 | 显示更多 |
Testcase #25 | 256.255 ms | 25 MB + 196 KB | Accepted | Score: 4 | 显示更多 |
Judge Duck Online | 评测鸭在线
Server Time: 2024-12-05 09:58:58 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠