結果
問題 | No.2616 中央番目の中央値 |
ユーザー | TairitsuMeow |
提出日時 | 2024-01-26 22:41:32 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 62 ms / 2,000 ms |
コード長 | 1,555 bytes |
コンパイル時間 | 1,602 ms |
コンパイル使用メモリ | 169,196 KB |
実行使用メモリ | 32,508 KB |
最終ジャッジ日時 | 2024-01-26 22:41:36 |
合計ジャッジ時間 | 4,224 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 7 ms
19,552 KB |
testcase_01 | AC | 6 ms
19,552 KB |
testcase_02 | AC | 7 ms
19,552 KB |
testcase_03 | AC | 6 ms
19,552 KB |
testcase_04 | AC | 7 ms
19,552 KB |
testcase_05 | AC | 7 ms
19,552 KB |
testcase_06 | AC | 7 ms
19,552 KB |
testcase_07 | AC | 7 ms
19,552 KB |
testcase_08 | AC | 7 ms
19,552 KB |
testcase_09 | AC | 6 ms
19,552 KB |
testcase_10 | AC | 7 ms
19,552 KB |
testcase_11 | AC | 7 ms
19,556 KB |
testcase_12 | AC | 6 ms
19,560 KB |
testcase_13 | AC | 7 ms
19,572 KB |
testcase_14 | AC | 8 ms
19,588 KB |
testcase_15 | AC | 8 ms
19,628 KB |
testcase_16 | AC | 9 ms
21,756 KB |
testcase_17 | AC | 10 ms
21,832 KB |
testcase_18 | AC | 13 ms
21,988 KB |
testcase_19 | AC | 21 ms
26,364 KB |
testcase_20 | AC | 21 ms
26,364 KB |
testcase_21 | AC | 41 ms
28,412 KB |
testcase_22 | AC | 59 ms
32,508 KB |
testcase_23 | AC | 59 ms
32,508 KB |
testcase_24 | AC | 38 ms
32,508 KB |
testcase_25 | AC | 39 ms
32,508 KB |
testcase_26 | AC | 59 ms
32,508 KB |
testcase_27 | AC | 59 ms
32,508 KB |
testcase_28 | AC | 60 ms
32,508 KB |
testcase_29 | AC | 58 ms
32,508 KB |
testcase_30 | AC | 62 ms
32,508 KB |
testcase_31 | AC | 58 ms
32,508 KB |
testcase_32 | AC | 57 ms
32,508 KB |
testcase_33 | AC | 57 ms
32,508 KB |
testcase_34 | AC | 59 ms
32,508 KB |
testcase_35 | AC | 62 ms
32,508 KB |
testcase_36 | AC | 59 ms
32,508 KB |
ソースコード
// Problem: No.2616 中央番目の中央値 // Contest: yukicoder // URL: https://yukicoder.me/problems/no/2616 // Memory Limit: 512 MB // Time Limit: 2000 ms #include<bits/stdc++.h> #define debug(x) cerr<<(#x)<<" "<<(x)<<endl typedef long long ll; typedef long double ld; typedef unsigned long long ull; #define pii pair<ll,ll> #define rep(i,a,b) for(ll i=(a);i<=(b);++i) #define per(i,a,b) for(ll i=(a);i>=(b);--i) using namespace std; bool Mbe; ll read(){ ll x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } void write(ll x){ if(x<0)putchar('-'),x=-x; if(x>9)write(x/10); putchar(x%10+'0'); } const ll N=1e6+9,Mod=998244353; ll n,a[N],pre[N],suf[N],bit[N],fac[N],ifac[N],ans; ll pw(ll x,ll p){ ll res=1; while(p){ if(p&1)res=res*x%Mod; x=x*x%Mod; p>>=1; } return res; } void Upd(ll x){ while(x<=n)bit[x]++,x+=(x&(-x)); } ll Query(ll x){ ll res=0; while(x)res+=bit[x],x-=(x&(-x)); return res; } ll C(ll x,ll y){ if(x<y||y<0)return 0; return fac[x]*ifac[y]%Mod*ifac[x-y]%Mod; } bool Med; int main(){ cerr<<fabs(&Med-&Mbe)/1048576.0<<"MB\n"; n=read(); rep(i,1,n)a[i]=read(); fac[0]=1; rep(i,1,n)fac[i]=fac[i-1]*i%Mod; ifac[n]=pw(fac[n],Mod-2); per(i,n-1,0)ifac[i]=ifac[i+1]*(i+1)%Mod; rep(i,1,n){ pre[i]=Query(a[i]); Upd(a[i]); } memset(bit,0,sizeof(bit)); per(i,n,1){ suf[i]=Query(a[i]); Upd(a[i]); } rep(i,1,n){ ll x=pre[i],y=suf[i]; ans=(ans+C(n-i-y+x,x)*C(i-1-x+y,y))%Mod; } write(ans); return 0; }