結果

問題 No.1300 Sum of Inversions
ユーザー Mr.SpockMr.Spock
提出日時 2020-12-01 16:16:15
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,480 bytes
コンパイル時間 1,752 ms
コンパイル使用メモリ 172,192 KB
実行使用メモリ 14,124 KB
最終ジャッジ日時 2023-10-11 03:37:40
合計ジャッジ時間 6,808 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
7,516 KB
testcase_01 AC 2 ms
7,556 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
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 AC 56 ms
11,832 KB
testcase_34 WA -
testcase_35 AC 65 ms
14,124 KB
testcase_36 AC 72 ms
14,048 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll nax = 2 * 1e5 + 7;
const ll mod = 998244353;
struct bit {
	const static ll siz = 2e5 + 7;
	ll bit[siz];
	ll get(ll idx) {
		ll sum = 0;
		while (idx > 0) {
			sum += bit[idx];
			idx -= (idx & -idx);
		}
		return sum;
	}
	void modify(ll idx, ll val) {
		while (idx < siz) {
			bit[idx] += val;
			idx += (idx & -idx);
		}
	}
	ll range(ll l, ll r) {
		return (get(r) - get(l - 1));
	}
} rightcnt, leftcnt, rightsum, leftsum;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n;
	cin >> n;
	vector<ll>v(n);
	for (ll i = 0; i < n; i++) {
		cin >> v[i];
	}
	vector<ll>a(n);
	for (ll i = 0; i < n; i++) {
		a[i] = v[i];
	}
	a.erase(unique(a.begin(), a.end()), a.end());
	sort(a.begin(), a.end());
	vector<ll>b(n);
	for (ll i = 0; i < n; i++) {
		b[i] = lower_bound(a.begin(), a.end(), v[i]) - a.begin();
		b[i]++;
	}
	for (ll i = 0; i < n; i++) {
		rightcnt.modify(b[i], 1);
		rightsum.modify(b[i], v[i]);
	}
	ll ans = 0;
	for (ll i = 0; i < n; i++) {
		rightsum.modify(b[i], -v[i]);
		rightcnt.modify(b[i], -1);
		ll cnt1 = rightcnt.range(0, b[i]);
		ll cnt2 = leftcnt.range(b[i] + 1, nax);
		ans += ((v[i] % mod) * (cnt1 % mod) * (cnt2 % mod));
		ans %= mod;
		ans += ((rightsum.range(0, b[i]) % mod) * (cnt2 % mod));
		ans %= mod;
		ans += ((leftsum.range(b[i], nax) % mod) * (cnt1 % mod));
		ans %= mod;
		leftsum.modify(b[i], v[i]);
		leftcnt.modify(b[i], 1);
	}
	cout << ans << endl;
}
0