結果
問題 | No.1300 Sum of Inversions |
ユーザー | 259_Momone |
提出日時 | 2020-11-27 22:16:50 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 165 ms / 2,000 ms |
コード長 | 2,718 bytes |
コンパイル時間 | 2,313 ms |
コンパイル使用メモリ | 213,284 KB |
実行使用メモリ | 18,912 KB |
最終ジャッジ日時 | 2024-07-26 13:14:58 |
合計ジャッジ時間 | 7,799 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 1 ms
6,944 KB |
testcase_02 | AC | 2 ms
6,940 KB |
testcase_03 | AC | 123 ms
15,216 KB |
testcase_04 | AC | 122 ms
14,968 KB |
testcase_05 | AC | 100 ms
12,920 KB |
testcase_06 | AC | 142 ms
16,640 KB |
testcase_07 | AC | 136 ms
16,100 KB |
testcase_08 | AC | 150 ms
17,472 KB |
testcase_09 | AC | 149 ms
17,488 KB |
testcase_10 | AC | 85 ms
11,252 KB |
testcase_11 | AC | 87 ms
11,408 KB |
testcase_12 | AC | 129 ms
14,996 KB |
testcase_13 | AC | 124 ms
14,708 KB |
testcase_14 | AC | 165 ms
18,720 KB |
testcase_15 | AC | 148 ms
17,308 KB |
testcase_16 | AC | 128 ms
15,524 KB |
testcase_17 | AC | 79 ms
11,144 KB |
testcase_18 | AC | 94 ms
12,356 KB |
testcase_19 | AC | 106 ms
13,844 KB |
testcase_20 | AC | 125 ms
13,940 KB |
testcase_21 | AC | 110 ms
13,856 KB |
testcase_22 | AC | 114 ms
12,992 KB |
testcase_23 | AC | 142 ms
16,656 KB |
testcase_24 | AC | 105 ms
13,224 KB |
testcase_25 | AC | 88 ms
11,816 KB |
testcase_26 | AC | 87 ms
11,864 KB |
testcase_27 | AC | 99 ms
12,600 KB |
testcase_28 | AC | 149 ms
17,924 KB |
testcase_29 | AC | 112 ms
13,776 KB |
testcase_30 | AC | 145 ms
17,272 KB |
testcase_31 | AC | 101 ms
12,976 KB |
testcase_32 | AC | 103 ms
13,336 KB |
testcase_33 | AC | 81 ms
18,784 KB |
testcase_34 | AC | 130 ms
18,900 KB |
testcase_35 | AC | 102 ms
18,904 KB |
testcase_36 | AC | 122 ms
18,912 KB |
ソースコード
#include<bits/stdc++.h> int main(){ using namespace std; const auto N{[]{unsigned long N; cin >> N; return N;}()}; auto perm{[&N]{ vector<pair<unsigned long, unsigned long>> ret(N); unsigned long idx{0}; for(auto&& [p, i] : ret){ cin >> p; i = idx++; } return ret; }()}; const auto small{[&N, &perm]{ sort(begin(perm), end(perm)); vector<complex<unsigned long>> segtree(N * 2); vector<pair<unsigned long, unsigned long>> ret(N); const auto update{[&N, &segtree](unsigned long idx, const auto& val){ idx += N; segtree[idx] += val; while(idx >>= 1UL)segtree[idx] += val; }}; const auto fold{[&N, &segtree](unsigned long l, unsigned long r){ decltype(segtree)::value_type ret{}; l += N; r += N; while(l < r){ if(l & 1UL)ret += segtree[l++]; if(r & 1UL)ret += segtree[--r]; l >>= 1UL; r >>= 1UL; } return ret; }}; for(const auto& [p, i] : perm){ const auto& tmp{fold(i, N)}; ret[i] = {tmp.real(), tmp.imag()}; update(i, complex{p, 1UL}); } return ret; }()}; const auto large{[&N, &perm]{ reverse(begin(perm), end(perm)); vector<complex<unsigned long>> segtree(N * 2); vector<pair<unsigned long, unsigned long>> ret(N); const auto update{[&N, &segtree](unsigned long idx, const auto& val){ idx += N; segtree[idx] += val; while(idx >>= 1UL)segtree[idx] += val; }}; const auto fold{[&N, &segtree](unsigned long l, unsigned long r){ decltype(segtree)::value_type ret{}; l += N; r += N; while(l < r){ if(l & 1UL)ret += segtree[l++]; if(r & 1UL)ret += segtree[--r]; l >>= 1UL; r >>= 1UL; } return ret; }}; for(const auto& [p, i] : perm){ const auto& tmp{fold(0, i)}; ret[i] = {tmp.real(), tmp.imag()}; update(i, complex{p, 1UL}); } return ret; }()}; unsigned long ans{0}; sort(begin(perm), end(perm), [](const auto& i, const auto& j){return i.second < j.second;}); constexpr unsigned long MOD{998244353}; for(unsigned long i{0}; i < N; ++i)ans += small[i].second * large[i].second % MOD * perm[i].first % MOD + small[i].second * large[i].first % MOD + small[i].first * large[i].second % MOD; cout << ans % MOD << endl; return 0; }