結果

問題 No.1300 Sum of Inversions
ユーザー uzzyuzzy
提出日時 2020-11-27 23:01:13
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 113 ms / 2,000 ms
コード長 2,246 bytes
コンパイル時間 1,613 ms
コンパイル使用メモリ 168,880 KB
実行使用メモリ 20,640 KB
最終ジャッジ日時 2023-10-09 20:59:34
合計ジャッジ時間 6,054 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
11,852 KB
testcase_01 AC 3 ms
11,676 KB
testcase_02 AC 3 ms
11,708 KB
testcase_03 AC 84 ms
18,148 KB
testcase_04 AC 85 ms
18,596 KB
testcase_05 AC 68 ms
16,508 KB
testcase_06 AC 96 ms
19,368 KB
testcase_07 AC 92 ms
19,312 KB
testcase_08 AC 102 ms
19,752 KB
testcase_09 AC 101 ms
19,628 KB
testcase_10 AC 55 ms
16,456 KB
testcase_11 AC 56 ms
15,604 KB
testcase_12 AC 84 ms
18,020 KB
testcase_13 AC 80 ms
17,724 KB
testcase_14 AC 113 ms
20,568 KB
testcase_15 AC 102 ms
19,684 KB
testcase_16 AC 88 ms
18,340 KB
testcase_17 AC 54 ms
15,468 KB
testcase_18 AC 61 ms
16,612 KB
testcase_19 AC 74 ms
17,580 KB
testcase_20 AC 75 ms
17,068 KB
testcase_21 AC 74 ms
17,048 KB
testcase_22 AC 67 ms
16,604 KB
testcase_23 AC 96 ms
19,360 KB
testcase_24 AC 70 ms
16,612 KB
testcase_25 AC 59 ms
15,904 KB
testcase_26 AC 59 ms
15,884 KB
testcase_27 AC 65 ms
17,236 KB
testcase_28 AC 103 ms
19,816 KB
testcase_29 AC 73 ms
17,004 KB
testcase_30 AC 102 ms
19,604 KB
testcase_31 AC 67 ms
17,232 KB
testcase_32 AC 70 ms
17,356 KB
testcase_33 AC 47 ms
14,384 KB
testcase_34 AC 66 ms
14,400 KB
testcase_35 AC 60 ms
20,600 KB
testcase_36 AC 65 ms
20,640 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//#pragma GCC optimize ("O2")
//#pragma GCC target ("avx2")
#include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int mod = 998244353;

const int bm = 200201;
ll BIT00[bm], BIT01[bm], BIT10[bm], BIT11[bm];
void add00(int A) {
	while (A <= bm) {
		BIT00[A]++;
		A += A & -A;
	}
}
int query00(int A) {
	int ret = 0;
	while (A > 0) {
		ret += BIT00[A];
		A -= A & -A;
	}
	return ret;
}
void add01(int A, ll B) {
	while (A <= bm) {
		BIT01[A] += B;
		A += A & -A;
	}
}
ll query01(int A) {
	ll ret = 0;
	while (A > 0) {
		ret += BIT01[A];
		A -= A & -A;
	}
	return ret;
}
void add10(int A) {
	while (A > 0) {
		BIT10[A]++;
		A -= A & -A;
	}
}
int query10(int A) {
	int ret = 0;
	while (A <= bm) {
		ret += BIT10[A];
		A += A & -A;
	}
	return ret;
}
void add11(int A, ll B) {
	while (A > 0) {
		BIT11[A] += B;
		A -= A & -A;
	}
}
ll query11(int A) {
	ll ret = 0;
	while (A <= bm) {
		ret += BIT11[A];
		A += A & -A;
	}
	return ret;
}
void zaatu(int N, ll A[]) {
	ll tmp[200000];
	rep(i, N) tmp[i] = A[i];
	sort(tmp, tmp + N);
	rep(i, N) A[i] = lower_bound(tmp, tmp + N, A[i]) - tmp + 1;
}


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);


	int N;
	cin >> N;
	ll A[200000], B[200000];
	rep(i, N) {
		cin >> A[i];
		B[i] = A[i];
	}
	zaatu(N, A);

	ll amae[200000], bmae[200000], aato[200000], bato[200000];
	rep(i, N) {
		amae[i] = query10(A[i] + 2);
		bmae[i] = query11(A[i] + 2);
		add10(A[i] + 1);
		add11(A[i] + 1, B[i]);
	}
	for (int i = N - 1; i >= 0; i--) {
		aato[i] = query00(A[i] + 1);
		bato[i] = query01(A[i] + 1);
		add00(A[i] + 2);
		add01(A[i] + 2, B[i]);
	}

	ll kotae = 0;
	rep(i, N) {
		kotae += B[i] * amae[i] % mod * aato[i] % mod;
		kotae += bmae[i] % mod * aato[i] % mod;
		kotae += bato[i] % mod * amae[i] % mod;
	}

	co(kotae% mod);

	Would you please return 0;
}
0