結果

問題 No.1300 Sum of Inversions
ユーザー trineutrontrineutron
提出日時 2020-11-27 22:13:52
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,873 bytes
コンパイル時間 2,336 ms
コンパイル使用メモリ 210,140 KB
実行使用メモリ 14,740 KB
最終ジャッジ日時 2023-10-01 06:22:16
合計ジャッジ時間 49,077 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1,349 ms
12,044 KB
testcase_04 AC 1,321 ms
11,948 KB
testcase_05 AC 1,102 ms
10,432 KB
testcase_06 AC 1,529 ms
13,068 KB
testcase_07 AC 1,441 ms
12,752 KB
testcase_08 AC 1,585 ms
13,580 KB
testcase_09 AC 1,570 ms
13,584 KB
testcase_10 AC 890 ms
9,064 KB
testcase_11 AC 906 ms
9,108 KB
testcase_12 AC 1,314 ms
11,704 KB
testcase_13 AC 1,289 ms
11,692 KB
testcase_14 AC 1,739 ms
14,596 KB
testcase_15 AC 1,563 ms
13,544 KB
testcase_16 AC 1,412 ms
12,276 KB
testcase_17 AC 881 ms
8,860 KB
testcase_18 AC 1,003 ms
9,672 KB
testcase_19 AC 1,157 ms
11,040 KB
testcase_20 AC 1,187 ms
11,208 KB
testcase_21 AC 1,185 ms
11,044 KB
testcase_22 AC 1,097 ms
10,416 KB
testcase_23 AC 1,505 ms
13,076 KB
testcase_24 AC 1,138 ms
10,772 KB
testcase_25 AC 964 ms
9,572 KB
testcase_26 AC 940 ms
9,324 KB
testcase_27 AC 1,052 ms
10,104 KB
testcase_28 AC 1,649 ms
13,868 KB
testcase_29 AC 1,171 ms
10,896 KB
testcase_30 AC 1,586 ms
13,848 KB
testcase_31 AC 1,112 ms
10,416 KB
testcase_32 AC 1,138 ms
10,708 KB
testcase_33 AC 1,645 ms
14,660 KB
testcase_34 AC 1,688 ms
14,688 KB
testcase_35 AC 1,675 ms
14,740 KB
testcase_36 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
    constexpr int64_t mod = 998244353;
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a.at(i);
    }
    reverse(a.begin(), a.end());
    vector<int> b = a;
    sort(b.begin(), b.end());
    b.erase(unique(b.begin(), b.end()), b.end());
    vector<int> c(n);
    for (int i = 0; i < n; i++) {
        c.at(i) = lower_bound(b.begin(), b.end(), a.at(i)) - b.begin();
    }
    vector<int64_t> s(n + 1), t(n + 1);
    vector<int64_t> s0(n), t0(n);
    for (int i = 0; i < n; i++) {
        int x = c.at(i);
        while (x) {
            (s0.at(i) += s.at(x)) %= mod;
            t0.at(i) += t.at(x);
            x -= x & -x;
        }
        x = c.at(i) + 1;
        while (x <= n) {
            (s.at(x) += b.at(c.at(i))) %= mod;
            t.at(x)++;
            x += x & -x;
        }
    }
    for (int i = 0; i <= n; i++) {
        s.at(i) = 0;
        t.at(i) = 0;
    }
    reverse(c.begin(), c.end());
    vector<int64_t> s1(n), t1(n);
    int64_t ssum = 0;
    for (int i = 0; i < n; i++) {
        int x = c.at(i) + 1;
        s1.at(i) = ssum;
        t1.at(i) = i;
        (ssum += b.at(c.at(i))) %= mod;
        while (x) {
            (s1.at(i) -= s.at(x)) %= mod;
            t1.at(i) -= t.at(x);
            x -= x & -x;
        }
        x = c.at(i) + 1;
        while (x <= n) {
            (s.at(x) += b.at(c.at(i))) %= mod;
            t.at(x)++;
            x += x & -x;
        }
    }
    int64_t ans = 0;
    for (int i = 0; i < n; i++) {
        int p = n - 1 - i;
        ans += a.at(i) * t0.at(i) * t1.at(p) % mod;
        ans += s0.at(i) * t1.at(p) % mod;
        ans += t0.at(i) * s1.at(p) % mod;
        ans %= mod;
        cerr << a.at(i) << " " << t0.at(i) << " " << t1.at(p) << endl;
    }
    cout << (ans + mod) % mod << endl;
}
0