Submission #19539391


Source Code Expand

Copy
// #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
 
using namespace std;
 
#define ll long long

const ll p = 1e9 + 7;

ll ans;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	ll n, k;
	cin >> n >> k;
	vector<ll> a(n);
	for (auto& x : a) {
		cin >> x;
	}
	for (int i = 0; i < n; ++i) {
		ll t1 = 0, t2 = 0;
		for (int j = 0; j < n; ++j) {
			if (a[j] < a[i]) t2++;
			if (a[j] < a[i] && j > i) t1++;
		}
		ll f = t1 + t1 + (k - 1) * t2;
		if (f % 2) {
			f = k / 2 * (f % p) % p;
		} else {
			f = f / 2 % p * k % p;
		}
		ans = (ans + f) % p;
	}
	cout << ans;
}

Submission Info

Submission Time
Task B - Kleene Inversion
User Cervidae
Language C++ (GCC 9.2.1)
Score 300
Code Size 633 Byte
Status AC
Exec Time 19 ms
Memory 3556 KB

Judge Result

Set Name All Sample
Score / Max Score 300 / 300 0 / 0
Status
AC × 24
AC × 3
Set Name Test Cases
All sample_01, sample_02, sample_03, testcase_0, testcase_1, testcase_10, testcase_11, testcase_12, testcase_13, testcase_14, testcase_15, testcase_16, testcase_17, testcase_18, testcase_19, testcase_2, testcase_20, testcase_3, testcase_4, testcase_5, testcase_6, testcase_7, testcase_8, testcase_9
Sample sample_01, sample_02, sample_03
Case Name Status Exec Time Memory
sample_01 AC 8 ms 3468 KB
sample_02 AC 3 ms 3464 KB
sample_03 AC 2 ms 3524 KB
testcase_0 AC 1 ms 3440 KB
testcase_1 AC 2 ms 3536 KB
testcase_10 AC 10 ms 3432 KB
testcase_11 AC 2 ms 3384 KB
testcase_12 AC 2 ms 3524 KB
testcase_13 AC 14 ms 3512 KB
testcase_14 AC 2 ms 3532 KB
testcase_15 AC 2 ms 3532 KB
testcase_16 AC 4 ms 3472 KB
testcase_17 AC 9 ms 3544 KB
testcase_18 AC 12 ms 3548 KB
testcase_19 AC 8 ms 3504 KB
testcase_2 AC 2 ms 3476 KB
testcase_20 AC 13 ms 3552 KB
testcase_3 AC 2 ms 3492 KB
testcase_4 AC 2 ms 3448 KB
testcase_5 AC 2 ms 3524 KB
testcase_6 AC 2 ms 3532 KB
testcase_7 AC 19 ms 3556 KB
testcase_8 AC 19 ms 3468 KB
testcase_9 AC 18 ms 3552 KB