結果

問題 No.2616 中央番目の中央値
ユーザー inksamuraiinksamurai
提出日時 2024-01-26 22:23:23
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 210 ms / 2,000 ms
コード長 2,371 bytes
コンパイル時間 4,642 ms
コンパイル使用メモリ 267,164 KB
実行使用メモリ 19,176 KB
最終ジャッジ日時 2024-01-26 22:23:33
合計ジャッジ時間 9,672 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
8,380 KB
testcase_01 AC 7 ms
8,380 KB
testcase_02 AC 7 ms
8,380 KB
testcase_03 AC 7 ms
8,380 KB
testcase_04 AC 7 ms
8,380 KB
testcase_05 AC 6 ms
8,380 KB
testcase_06 AC 7 ms
8,380 KB
testcase_07 AC 6 ms
8,380 KB
testcase_08 AC 7 ms
8,380 KB
testcase_09 AC 7 ms
8,380 KB
testcase_10 AC 8 ms
8,380 KB
testcase_11 AC 7 ms
8,380 KB
testcase_12 AC 7 ms
8,380 KB
testcase_13 AC 8 ms
8,380 KB
testcase_14 AC 9 ms
8,508 KB
testcase_15 AC 12 ms
8,636 KB
testcase_16 AC 17 ms
8,836 KB
testcase_17 AC 22 ms
8,992 KB
testcase_18 AC 34 ms
9,816 KB
testcase_19 AC 63 ms
11,496 KB
testcase_20 AC 65 ms
11,496 KB
testcase_21 AC 135 ms
14,856 KB
testcase_22 AC 209 ms
19,164 KB
testcase_23 AC 209 ms
19,176 KB
testcase_24 AC 150 ms
19,176 KB
testcase_25 AC 150 ms
19,176 KB
testcase_26 AC 204 ms
19,176 KB
testcase_27 AC 199 ms
19,176 KB
testcase_28 AC 205 ms
19,176 KB
testcase_29 AC 207 ms
19,176 KB
testcase_30 AC 208 ms
19,176 KB
testcase_31 AC 210 ms
19,176 KB
testcase_32 AC 207 ms
19,176 KB
testcase_33 AC 205 ms
19,176 KB
testcase_34 AC 208 ms
19,176 KB
testcase_35 AC 208 ms
19,176 KB
testcase_36 AC 204 ms
19,176 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define rng(i,c,n) for(int i=c;i<n;i++)
#define fi first
#define se second
#define pb push_back
#define all(a) a.begin(), a.end()
#define sz(a) ((int) a.size())
#define vec(...) vector<__VA_ARGS__>
#define _3PawRSC ios::sync_with_stdio(0),cin.tie(0)
typedef long long ll;
using vi=vector<int>;
using pii=pair<int,int>;
void print(){cout<<'\n';}
template<class h,class...t>
void print(const h&v,const t&...u){cout<<v<<' ',print(u...);}

// snuke's mod int
template <ll mod>
struct modint{
	ll x;
	modint(ll x=0):x((x%mod+mod)%mod){}
	modint operator-()const{return modint(-x);}
	modint& operator+=(const modint a){if((x+=a.x)>=mod) x-=mod; return *this;}
	modint& operator-=(const modint a){if((x+=mod-a.x)>=mod) x-=mod; return *this;}
	modint& operator*=(const modint a){(x*=a.x)%=mod; return *this;}
	modint operator+(const modint a)const{modint res(*this); return res+=a;}
	modint operator-(const modint a)const{modint res(*this); return res-=a;}
	modint operator*(const modint a)const{modint res(*this); return res*=a;}
	modint pow(ll n)const{
		modint res=1,x(*this);
		while(n){
			if(n&1)res*=x;
			x*=x;
			n>>=1;
		}
		return res;
	}
	modint inv()const{return pow(mod-2);}
};

using mint=modint<998244353>;

const int _n=3e5;

mint fact[_n],invfact[_n];

void initfact(){
	fact[0]=1;
	rng(i,1,_n){
		fact[i]=fact[i-1]*mint(i);
	}
	invfact[_n-1]=fact[_n-1].inv();
	per(i,_n-1){
		invfact[i]=invfact[i+1]*mint(i+1);
	}
}

mint cnk(ll k,ll n){
	return k>n?0:fact[n]*invfact[k]*invfact[n-k];
}

int op(int l,int r){
	return l+r;
}

int e(){
	return 0;
}

void slv(){
	int n;
	cin>>n;
	vi a(n);
	rep(i,n){
		cin>>a[i];
	}
	rep(i,n){
		a[i]-=1;
	}
	vec(vi) cl(2,vi(n));
	{
		atcoder::segtree<int,op,e> seg(n);
		rep(i,n){
			int x=a[i];
			cl[0][i]=seg.prod(0,x);
			cl[1][i]=seg.prod(x,n);
			seg.set(x,1);
		}
	}
	vec(vi) cr(2,vi(n));
	{
		atcoder::segtree<int,op,e> seg(n);
		per(i,n){
			int x=a[i];
			cr[0][i]=seg.prod(0,x);
			cr[1][i]=seg.prod(x,n);
			seg.set(x,1);
		}	
	}
	mint ans=0;
	rep(i,n){
		int x=min(cl[1][i],cr[0][i]);
		mint wys=cnk(x,cl[1][i]+cr[0][i]);
		int y=min(cl[0][i],cr[1][i]);
		wys*=cnk(y,cl[0][i]+cr[1][i]);
		ans+=wys;
	}
	print(ans.x);
}

signed main(){
_3PawRSC;
	initfact();
	slv();
}
0