結果

問題 No.2250 Split Permutation
ユーザー kcvlexkcvlex
提出日時 2023-03-17 23:10:34
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,046 bytes
コンパイル時間 3,225 ms
コンパイル使用メモリ 158,988 KB
実行使用メモリ 6,556 KB
最終ジャッジ日時 2023-10-18 16:09:13
合計ジャッジ時間 6,213 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 WA -
testcase_04 AC 2 ms
4,348 KB
testcase_05 WA -
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 WA -
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 1 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <atcoder/all>

#define ALL(V) std::begin(V), std::end(V)

using ll = long long;
using modint = atcoder::modint998244353;

int main() {
    int N;
    std::cin >> N;
    std::vector<int> P(N), rP(N);
    for (int i = 0; i < N; i++) {
        std::cin >> P[i];
        P[i]--;
        rP[P[i]] = i;
    }

    std::vector<modint> pow2(N + 10);
    pow2[0] = 1;
    for (int i = 0; i < N + 9; i++) pow2[i + 1] = pow2[i] * 2;

    modint ans = 0;
    {
        atcoder::fenwick_tree<modint> cnt(N);
        for (int i = 0; i < N; i++) {
            int idx = rP[i];
            auto sum = cnt.sum(idx, N);
            ans += sum;
            cnt.add(idx, 1);
        }
        ans *= pow2[N - 1];
    }
    
    atcoder::fenwick_tree<modint> ft(N);
    for (int i = 0; i < N; i++) {
        int idx = rP[i];
        auto sum = ft.sum(idx, N);
        int p = N - 1 + idx;
        ans -= sum * pow2[p];
        ft.add(idx, pow2[idx].inv());
    }
    std::cout << ans.val() << std::endl;
    return 0;
}
0