結果

問題 No.2327 Inversion Sum
ユーザー t98slidert98slider
提出日時 2023-05-28 16:54:15
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 18 ms / 2,000 ms
コード長 975 bytes
コンパイル時間 3,667 ms
コンパイル使用メモリ 234,644 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-27 14:18:58
合計ジャッジ時間 5,181 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
4,376 KB
testcase_01 AC 16 ms
4,380 KB
testcase_02 AC 12 ms
4,380 KB
testcase_03 AC 3 ms
4,376 KB
testcase_04 AC 18 ms
4,380 KB
testcase_05 AC 3 ms
4,380 KB
testcase_06 AC 12 ms
4,380 KB
testcase_07 AC 8 ms
4,380 KB
testcase_08 AC 4 ms
4,380 KB
testcase_09 AC 16 ms
4,380 KB
testcase_10 AC 5 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 11 ms
4,380 KB
testcase_15 AC 17 ms
4,380 KB
testcase_16 AC 6 ms
4,384 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 3 ms
4,376 KB
testcase_19 AC 5 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 2 ms
4,384 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using mint = modint998244353;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m, p, k, rem;
    cin >> n >> m;
    vector<pair<int,int>> a(m);
    vector<int> s2(n + 1, 1);
    for(int i = 0; i < m; i++){
        cin >> p >> k;
        s2[k]--;
        a[i] = make_pair(--p, --k);
    }
    sort(a.begin(), a.end());
    for(int i = 0; i < n; i++) s2[i + 1] += s2[i];
    rem = n - m;
    mint ans, fr, ba, up, down, ten;
    fenwick_tree<int> fw(n);
    for(int i = 0; i < m; i++){
        tie(p, k) = a[i];
        fr = p - i, ba = n - p - (m - i);
        down = s2[k] - 1, up = s2[n] - s2[k];
        ans += fr * up + ba * down;
        ten += fw.sum(k, n);
        fw.add(k, 1);
    }
    if(rem) ans /= rem;
    ans += mint(rem) * (rem - 1) / 4 + ten;
    for(int i = 2; i <= rem; i++) ans *= i;
    cout << ans.val() << '\n';
}
0