結果
問題 | No.1193 Penguin Sequence |
ユーザー | yukudo |
提出日時 | 2020-09-05 23:12:03 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 269 ms / 2,000 ms |
コード長 | 4,056 bytes |
コンパイル時間 | 1,853 ms |
コンパイル使用メモリ | 183,616 KB |
実行使用メモリ | 41,728 KB |
最終ジャッジ日時 | 2024-05-06 20:22:00 |
合計ジャッジ時間 | 11,890 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 209 ms
41,600 KB |
testcase_01 | AC | 237 ms
41,728 KB |
testcase_02 | AC | 269 ms
41,660 KB |
testcase_03 | AC | 237 ms
41,600 KB |
testcase_04 | AC | 240 ms
41,728 KB |
testcase_05 | AC | 236 ms
41,600 KB |
testcase_06 | AC | 235 ms
41,728 KB |
testcase_07 | AC | 236 ms
41,600 KB |
testcase_08 | AC | 235 ms
41,600 KB |
testcase_09 | AC | 236 ms
41,616 KB |
testcase_10 | AC | 237 ms
41,728 KB |
testcase_11 | AC | 158 ms
38,656 KB |
testcase_12 | AC | 160 ms
38,528 KB |
testcase_13 | AC | 210 ms
40,576 KB |
testcase_14 | AC | 203 ms
40,192 KB |
testcase_15 | AC | 247 ms
41,088 KB |
testcase_16 | AC | 209 ms
41,600 KB |
testcase_17 | AC | 63 ms
34,944 KB |
testcase_18 | AC | 76 ms
35,284 KB |
testcase_19 | AC | 235 ms
41,472 KB |
testcase_20 | AC | 199 ms
40,064 KB |
testcase_21 | AC | 176 ms
39,040 KB |
testcase_22 | AC | 77 ms
35,200 KB |
testcase_23 | AC | 152 ms
38,272 KB |
testcase_24 | AC | 143 ms
37,760 KB |
testcase_25 | AC | 95 ms
35,968 KB |
testcase_26 | AC | 70 ms
35,164 KB |
testcase_27 | AC | 209 ms
40,560 KB |
testcase_28 | AC | 162 ms
38,656 KB |
testcase_29 | AC | 211 ms
40,576 KB |
testcase_30 | AC | 112 ms
36,608 KB |
testcase_31 | AC | 101 ms
36,224 KB |
testcase_32 | AC | 179 ms
39,424 KB |
testcase_33 | AC | 142 ms
37,888 KB |
testcase_34 | AC | 127 ms
37,392 KB |
testcase_35 | AC | 143 ms
37,888 KB |
testcase_36 | AC | 124 ms
37,120 KB |
testcase_37 | AC | 206 ms
40,464 KB |
testcase_38 | AC | 60 ms
34,836 KB |
testcase_39 | AC | 62 ms
34,816 KB |
testcase_40 | AC | 61 ms
34,828 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i) #define ALL(v) (v).begin(),(v).end() #define CLR(t,v) memset(t,(v),sizeof(t)) template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";} template<class T>void chmin(T&a,const T&b){if(a>b)a=b;} template<class T>void chmax(T&a,const T&b){if(a<b)a=b;} #ifdef LOCAL template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cerr<<(*i)<<" ";cerr<<endl;} #else template<class T>void pv(T a,T b){} #endif ll nextLong() { ll x; scanf("%lld", &x); return x;} const ll MOD = 998244353; struct mint { ll x; mint(ll x=0):x((x%MOD+MOD)%MOD){} mint& operator+=(const mint a) {if ((x += a.x) >= MOD) x -= MOD;return *this;} mint& operator-=(const mint a) {if ((x += MOD-a.x) >= MOD) x -= MOD;return *this;} mint& operator*=(const mint a) {(x *= a.x) %= MOD;return *this;} mint operator+(const mint a) const {mint res(*this);return res+=a;} mint operator-(const mint a) const {mint res(*this);return res-=a;} mint operator*(const mint a) const {mint res(*this);return res*=a;} mint pow(ll b) const { mint res(1), a(*this); while (b) { if (b & 1) res *= a; a *= a; b >>= 1; } return res; } // for prime MOD mint inv() const {return pow(MOD-2);} mint& operator/=(const mint a) {return (*this) *= a.inv();} mint operator/(const mint a) const {mint res(*this);return res/=a;} }; ostream& operator<<(ostream& os, const mint& a) {os << a.x; return os;} vector<int> normalize(const vector<ll> v) { const int N = v.size(); vector<int> res(N); vector<pair<ll,int> > t(N); REP(i, N) t[i] = { v[i], i }; sort(ALL(t)); int r = 0; REP(i, N) { r += (i > 0 && t[i - 1].first != t[i].first); res[t[i].second] = r; } return res; } struct BIT { using Val = int; int n; vector<Val> tree; BIT(int n):n(n),tree(n+1) {} void fill(Val val) { REP(i, n+1) tree[i] = (i&-i) * val; } void add(int idx, Val val) { for (int x=idx+1; x<=n; x+=x&-x) tree[x] += val; } // sum[0, idx] Val range(int idx) { Val sum=0; for (int x=idx+1; x>0; x-=x&-x) sum += tree[x]; return sum; } // sum[a, b] Val range(int a, int b) { return range(b) - range(a - 1); } }; const int MAX_N = 212345; mint P[MAX_N]; mint M[MAX_N]; mint L[MAX_N]; const int SZ = 1123456; ll inv[SZ]; ll fact[SZ]; ll fact_inv[SZ]; mint choose(int n, int r) { if (n < 0 || r < 0 || n < r) return 0; ll res = fact[n] * fact_inv[n-r] % MOD * fact_inv[r] % MOD; return mint(res); } int main2() { int N = nextLong(); vector<ll> A_(N); REP(i, N) A_[i] = nextLong(); vector<int> A = normalize(A_); const int R = *max_element(ALL(A)) + 1; pv(ALL(A)); mint ans = 0; P[N+1] = 0; for (int n = N; n >= 1; n--) { P[n] = P[n+1] + (mint(n) / mint(N)); } { REP(i, MAX_N) M[i] = 0; vector<int> sorted = A; sort(ALL(sorted)); REP(i, R) M[i] = lower_bound(ALL(sorted), i) - sorted.begin(); pv(M, M+R); } { mint sm = 0; for (int i = 0; i < N; i++) sm += M[A[i]]; mint sp = 0; for (int n = 1; n <= N; n++) sp += mint(n) / mint(N) * P[n+1]; ans += sm * sp; } { REP(i, MAX_N) L[i] = 0; BIT bit(N+1); for (int i = 0; i < N; i++) { L[i] = i - bit.range(A[i]); bit.add(A[i], 1); } } { mint sn = 0; for (int n = 1; n <= N; n++) sn += mint(n-1) / mint(N-1) * mint(n) / mint(N); mint sl = 0; for (int i = 0; i < N; i++) sl += L[i]; ans += sn * sl; } for (int n = 1; n <= N; n++) ans *= choose(N, n); cout << ans << endl; return 0; } int main() { inv[1] = 1; for (int i = 2; i < SZ; i++) inv[i] = inv[(int) (MOD % i)] * (MOD - MOD / i) % MOD; fact[0] = 1; for (int i = 1; i < SZ; i++) fact[i] = fact[i-1] * i % MOD; fact_inv[0] = 1; for (int i = 1; i < SZ; i++) fact_inv[i] = fact_inv[i-1] * inv[i] % MOD; #ifdef LOCAL for (;!cin.eof();cin>>ws) #endif main2(); return 0; }