結果

問題 No.1300 Sum of Inversions
ユーザー KudeKude
提出日時 2020-11-27 23:15:28
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,799 bytes
コンパイル時間 2,289 ms
コンパイル使用メモリ 214,196 KB
実行使用メモリ 16,420 KB
最終ジャッジ日時 2023-10-09 21:06:44
合計ジャッジ時間 14,388 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 359 ms
13,356 KB
testcase_04 AC 318 ms
13,048 KB
testcase_05 AC 244 ms
11,508 KB
testcase_06 AC 398 ms
14,644 KB
testcase_07 AC 365 ms
14,124 KB
testcase_08 AC 411 ms
15,212 KB
testcase_09 AC 407 ms
15,152 KB
testcase_10 AC 189 ms
10,032 KB
testcase_11 AC 189 ms
9,988 KB
testcase_12 AC 317 ms
13,032 KB
testcase_13 AC 305 ms
12,900 KB
testcase_14 AC 461 ms
16,240 KB
testcase_15 AC 405 ms
15,044 KB
testcase_16 AC 352 ms
13,512 KB
testcase_17 AC 182 ms
9,728 KB
testcase_18 AC 222 ms
10,712 KB
testcase_19 AC 274 ms
11,972 KB
testcase_20 AC 277 ms
12,160 KB
testcase_21 AC 275 ms
12,228 KB
testcase_22 AC 246 ms
11,312 KB
testcase_23 AC 390 ms
14,548 KB
testcase_24 AC 258 ms
11,680 KB
testcase_25 AC 209 ms
10,528 KB
testcase_26 AC 194 ms
10,300 KB
testcase_27 AC 233 ms
11,172 KB
testcase_28 AC 432 ms
15,480 KB
testcase_29 AC 264 ms
12,112 KB
testcase_30 AC 400 ms
15,064 KB
testcase_31 AC 231 ms
11,464 KB
testcase_32 AC 257 ms
11,668 KB
testcase_33 AC 20 ms
4,380 KB
testcase_34 AC 31 ms
4,376 KB
testcase_35 AC 209 ms
16,420 KB
testcase_36 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<atcoder/fenwicktree>
#include<atcoder/modint>
using namespace std;
using namespace atcoder;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;

using mint = modint998244353;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    VI a(n);
    rep(i, n) cin >> a[i];
    map<int,int> mp;
    rep(i, n) mp[a[i]] = 0;
    {
        int idx = 0;
        for(auto& [k, v]: mp) v = idx++;
    }
    int sz = mp.size();
    mint ans = 0;
    {
        fenwick_tree<ll> ft1(sz), ft2(sz);
        rep(i, n) {
            int idx = mp[a[i]];
            ll cnt1 = ft1.sum(idx + 1, sz);
            ll cnt2 = ft2.sum(idx + 1, sz);
            ans += cnt2 * a[i];
            ft2.add(idx, cnt1);
            ft1.add(idx, 1);
        }
    }
    {
        fenwick_tree<ll> ft1(sz), ft2(sz);
        rrep(i, n) {
            int idx = mp[a[i]];
            ll cnt1 = ft1.sum(0, idx);
            ll cnt2 = ft2.sum(0, idx);
            ans += mint(cnt2) * a[i];
            ft2.add(idx, cnt1);
            ft1.add(idx, 1);
        }
    }
    {
        fenwick_tree<ll> ft1(sz), ft2(sz);
        rrep(i, n) {
            int idx = mp[a[i]];
            ft2.add(idx, 1);
        }
        rep(i, n) {
            int idx = mp[a[i]];
            ans += mint(a[i]) * ft1.sum(idx + 1, sz) * ft2.sum(0, idx);
            ft1.add(idx, 1);
            ft2.add(idx, -1);
        }
    }
    cout << ans.val() << endl;
}
0