結果
| 問題 | No.2250 Split Permutation | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2023-03-18 00:55:34 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 47 ms / 3,000 ms | 
| コード長 | 902 bytes | 
| コンパイル時間 | 2,740 ms | 
| コンパイル使用メモリ | 198,280 KB | 
| 最終ジャッジ日時 | 2025-02-11 14:41:01 | 
| ジャッジサーバーID (参考情報) | judge1 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 35 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
#ifdef _RUTHEN
#include <debug.hpp>
#else
#define show(...) true
#endif
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
template <class T> using V = vector<T>;
#include <atcoder/fenwicktree>
#include <atcoder/modint>
using mint = atcoder::modint998244353;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    V<int> P(N);
    rep(i, N) {
        cin >> P[i];
        P[i]--;
    }
    V<mint> p2(N, 1);
    rep(i, N - 1) p2[i + 1] = 2 * p2[i];
    mint ans = 0, inv = 0;
    atcoder::fenwick_tree<mint> seg(N), fen(N);
    rep(i, N) {
        // inversion number
        inv += fen.sum(P[i], N);
        fen.add(P[i], 1);
        ans += seg.sum(P[i], N) * p2[N - 1 - i];
        seg.add(P[i], p2[i]);
    }
    mint res = inv * p2[N - 1] - ans;
    cout << res.val() << '\n';
    return 0;
}
            
            
            
        