結果

問題 No.2616 中央番目の中央値
ユーザー tailstails
提出日時 2024-01-29 10:30:25
言語 C90
(gcc 11.4.0)
結果
AC  
実行時間 31 ms / 2,000 ms
コード長 1,395 bytes
コンパイル時間 715 ms
コンパイル使用メモリ 25,728 KB
実行使用メモリ 7,792 KB
最終ジャッジ日時 2024-01-29 10:30:28
合計ジャッジ時間 3,117 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
6,676 KB
testcase_01 AC 5 ms
6,676 KB
testcase_02 AC 4 ms
6,676 KB
testcase_03 AC 4 ms
6,676 KB
testcase_04 AC 5 ms
6,676 KB
testcase_05 AC 5 ms
6,676 KB
testcase_06 AC 4 ms
6,676 KB
testcase_07 AC 4 ms
6,676 KB
testcase_08 AC 5 ms
6,676 KB
testcase_09 AC 4 ms
6,676 KB
testcase_10 AC 5 ms
6,676 KB
testcase_11 AC 5 ms
6,676 KB
testcase_12 AC 4 ms
6,676 KB
testcase_13 AC 4 ms
6,676 KB
testcase_14 AC 4 ms
6,676 KB
testcase_15 AC 5 ms
6,676 KB
testcase_16 AC 6 ms
6,676 KB
testcase_17 AC 6 ms
6,676 KB
testcase_18 AC 8 ms
6,676 KB
testcase_19 AC 11 ms
6,676 KB
testcase_20 AC 11 ms
6,676 KB
testcase_21 AC 19 ms
6,676 KB
testcase_22 AC 29 ms
7,792 KB
testcase_23 AC 30 ms
6,676 KB
testcase_24 AC 19 ms
7,792 KB
testcase_25 AC 18 ms
6,676 KB
testcase_26 AC 31 ms
6,676 KB
testcase_27 AC 31 ms
6,676 KB
testcase_28 AC 30 ms
6,676 KB
testcase_29 AC 30 ms
7,792 KB
testcase_30 AC 31 ms
7,792 KB
testcase_31 AC 31 ms
6,676 KB
testcase_32 AC 30 ms
7,792 KB
testcase_33 AC 30 ms
7,792 KB
testcase_34 AC 31 ms
6,676 KB
testcase_35 AC 30 ms
6,676 KB
testcase_36 AC 30 ms
7,792 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘main’:
main.c:7:59: warning: implicit declaration of function ‘write’ [-Wimplicit-function-declaration]
    7 | #define wt1(v) ({char wbuf[64],*wp=wbuf+sizeof wbuf;wt(v);write(1,wp,wbuf+sizeof wbuf-wp);})
      |                                                           ^~~~~
main.c:90:9: note: in expansion of macro ‘wt1’
   90 |         wt1(z);
      |         ^~~
main.c:91:9: warning: implicit declaration of function ‘_exit’ [-Wimplicit-function-declaration]
   91 |         _exit(0);
      |         ^~~~~
main.c:91:9: warning: incompatible implicit declaration of built-in function ‘_exit’ [-Wbuiltin-declaration-mismatch]

ソースコード

diff #

#pragma GCC optimize("Ofast")
#pragma GCC target("avx2")

#define rd_init() char*rp=({char*mmap();mmap(0l,1l<<25,1,2,0,0ll);})
#define rd() ({int _v=0,_c;while(_c=*rp++-48,_c>=0)_v=_v*10+_c;_v;})
#define wt(v) ({unsigned _z=v;do*--wp=_z%10+48;while(_z/=10);})
#define wt1(v) ({char wbuf[64],*wp=wbuf+sizeof wbuf;wt(v);write(1,wp,wbuf+sizeof wbuf-wp);})
#define rep(v,e) for(typeof(e) v=0;v<e;++v)
#define MD 998244353

typedef unsigned long ulong;

// fenwick

#define FWSIZE (1<<20)
int fw[FWSIZE];

static inline
void fw_add(int a,int v){
	if(a==0){
		fw[0]+=v;
	}else{
		while(fw[a]+=v,a+=a&-a,a<FWSIZE);
	}
}

static inline
int fw_get(int a){
	int z=0;
	while(z+=fw[a],a)a-=a&-a;
	return z;
}

// fac table

#define M 300001
unsigned fac[M],ifac[M];

int inverse(int a){
	int b=MD;
	int u=1;
	int v=0;
	int s,t;
	while(b){
		t=a/b;
		s=b; b=a-t*b; a=s;
		s=v; v=u-t*v; u=s;
	}
	if(u<0){
		u+=MD;
	}
	return u;
}

void mkfac(){
	ulong x=1;
	fac[0]=x;
	for(long i=1;i<M;i++){
		x=x*i%MD;
		fac[i]=x;
	}
	x=inverse(x);
	for(long i=M;i--;){
		ifac[i]=x;
		x=x*i%MD;
	}
}

static inline
ulong binom(int a,int b){
	return (ulong)fac[a+b]*ifac[a]%MD*ifac[b]%MD;
}

// main

int main(){
	mkfac();
	rd_init();
	ulong z=0;
	int n=rd();
	rep(i,n){
		int p=rd()-1;
		int a=fw_get(p);
		int b=i-a;
		int c=p-a;
		int d=n-1-a-b-c;
		z=(z+binom(a,d)*binom(b,c))%MD;
		fw_add(p,1);
	}
	wt1(z);
	_exit(0);
}
0