Submission #7121405
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
using LL = long long; using PII = pair<LL, LL>; using VI = vector<LL>; using VVI = vector<VI>;
using VB = vector<bool>; using VS = vector<string>; using VP = vector<PII>;
#define VV(T) vector<vector<T>>
#define PB push_back
#define MP make_pair
#define SZ(a) LL((a).size())
#define EACH(x, c) for (auto x : (c))
#define ALL(c) (c).begin(), (c).end()
#define REVERSE(c) reverse(ALL(c))
#define SORT(c) stable_sort(ALL(c))
#define RSORT(c) stable_sort((c).rbegin(), (c).rend())
#define FOR(i, a, b) for (LL i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define $(x) {cout << #x << " = " << (x) << endl;}
const LL MOD = 1000000007;
inline LL mod_add(LL a, LL b) { return (a + b) % MOD; }
inline LL mod_sub(LL a, LL b) { return (a + MOD - b) % MOD; }
inline LL mod_mul(LL a, LL b) { return ((a % MOD) * (b % MOD)) % MOD; }
LL mod_bipow(LL x, LL y) { // x^y by bisection method
if (y == 0) return 1;
else if (y == 1) return x % MOD;
else if (y % 2 == 0) {
LL val = mod_bipow(x, (LL)(y / 2));
return mod_mul(val, val);
} else {
LL val = mod_bipow(x, (LL)(y / 2));
return mod_mul(mod_mul(val, val), x);
}
}
LL mod_inv(LL x) { return mod_bipow(x, MOD - 2); } // x^{-1} = x^{MOD-2} (MOD: prime number)
LL mod_div(LL a, LL b) { return mod_mul(a, mod_inv(b)); } // a/b = a*b^{-1}
void solve(LL N, LL K, vector<LL> A){
LL ans = 0;
LL cl = mod_div(mod_mul(mod_sub(K, 1), K), 2);
LL cr = mod_div(mod_mul(K, mod_add(K, 1)), 2);
//$(cl);
//$(cr);
REP(i, N) {
LL left = 0, right = 0; // smaller than A[i]
REP(j, i) {
if (A[j] < A[i]) left++;
}
FOR(j, i + 1, N) {
if (A[i] > A[j]) right++;
}
//$(left);
//$(right);
ans = mod_add(ans, mod_add(mod_mul(cr, right), mod_mul(cl, left)));
}
cout << ans << endl;
}
int main(){
LL N;
scanf("%lld",&N);
LL K;
scanf("%lld",&K);
vector<LL> A(N-1-0+1);
for(int i = 0 ; i < N-1-0+1 ; i++){
scanf("%lld",&A[i]);
}
solve(N, K, move(A));
return 0;
}
Submission Info
| Submission Time |
|
| Task |
B - Kleene Inversion |
| User |
yetnone |
| Language |
C++14 (GCC 5.4.1) |
| Score |
300 |
| Code Size |
2211 Byte |
| Status |
AC |
| Exec Time |
4 ms |
| Memory |
256 KiB |
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:59:21: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld",&N);
^
./Main.cpp:61:21: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld",&K);
^
./Main.cpp:64:28: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld",&A[i]);
^
Judge Result
| Set Name |
All |
Sample |
| Score / Max Score |
300 / 300 |
0 / 0 |
| Status |
|
|
| 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 |
1 ms |
256 KiB |
| sample_02 |
AC |
1 ms |
256 KiB |
| sample_03 |
AC |
1 ms |
256 KiB |
| testcase_0 |
AC |
3 ms |
256 KiB |
| testcase_1 |
AC |
1 ms |
256 KiB |
| testcase_10 |
AC |
2 ms |
256 KiB |
| testcase_11 |
AC |
1 ms |
256 KiB |
| testcase_12 |
AC |
1 ms |
256 KiB |
| testcase_13 |
AC |
2 ms |
256 KiB |
| testcase_14 |
AC |
1 ms |
256 KiB |
| testcase_15 |
AC |
1 ms |
256 KiB |
| testcase_16 |
AC |
1 ms |
256 KiB |
| testcase_17 |
AC |
2 ms |
256 KiB |
| testcase_18 |
AC |
3 ms |
256 KiB |
| testcase_19 |
AC |
2 ms |
256 KiB |
| testcase_2 |
AC |
1 ms |
256 KiB |
| testcase_20 |
AC |
3 ms |
256 KiB |
| testcase_3 |
AC |
1 ms |
256 KiB |
| testcase_4 |
AC |
1 ms |
256 KiB |
| testcase_5 |
AC |
1 ms |
256 KiB |
| testcase_6 |
AC |
1 ms |
256 KiB |
| testcase_7 |
AC |
4 ms |
256 KiB |
| testcase_8 |
AC |
4 ms |
256 KiB |
| testcase_9 |
AC |
4 ms |
256 KiB |