problem_id
stringlengths 6
6
| buggy_code
stringlengths 8
526k
| fixed_code
stringlengths 12
526k
| labels
listlengths 0
15
⌀ | buggy_submission_id
int64 1
1.54M
| fixed_submission_id
int64 2
1.54M
| user_id
stringlengths 10
10
| language
stringclasses 8
values |
|---|---|---|---|---|---|---|---|
p02928
|
#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
// 引数の受け取り
long long N, K;
cin >> N >> K;
long long A[N];
for (long long i = 0; i < N; i++) {
cin >> A[i];
}
long long mod = 1000000007;
long long ans1 = 0;
long long ans2 = 0;
long long ans = 0;
long long o = K * (K - 1) / 2;
for (long long i = 0; i < N; i++) {
ans1 = 0;
for (long long j = 0; j < N; j++) {
if (A[i] > A[j]) {
ans1++; //ブロックにあるかず
if (i < j) {
ans2++; // →にあるかず
}
}
}
ans = (ans + ans1 * o % mod) % mod;
}
ans = (ans + ans2 * K % mod) % mod;
// printf("%d",(((ans2*K%mod)+(ans1*K*(K-1)/2 % mod))%mod));
cout << ans << endl;
return 0;
}
|
#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
// 引数の受け取り
long long N, K;
cin >> N >> K;
long long A[N];
for (long long i = 0; i < N; i++) {
cin >> A[i];
}
long long mod = 1000000007;
long long ans1 = 0;
long long ans2 = 0;
long long ans = 0;
long long o = K * (K - 1) / 2 % mod;
for (long long i = 0; i < N; i++) {
ans1 = 0;
for (long long j = 0; j < N; j++) {
if (A[i] > A[j]) {
ans1++; //ブロックにあるかず
if (i < j) {
ans2++; // →にあるかず
}
}
}
ans = (ans + ans1 * o % mod) % mod;
}
ans = (ans + ans2 * K % mod) % mod;
// printf("%d",(((ans2*K%mod)+(ans1*K*(K-1)/2 % mod))%mod));
cout << ans << endl;
return 0;
}
|
[
"assignment.change"
] | 731,601
| 731,602
|
u641145334
|
cpp
|
p02928
|
#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
// 引数の受け取り
long long N, K;
cin >> N >> K;
long long A[N];
for (long long i = 0; i < N; i++) {
cin >> A[i];
}
long long mod = 1000000007;
long long ans1 = 0;
long long ans2 = 0;
long long ans = 0;
long long o = K * (K - 1) / 2;
for (long long i = 0; i < N; i++) {
ans1 = 0;
for (long long j = 0; j < N; j++) {
if (A[i] > A[j]) {
ans1++; //ブロックにあるかず
if (i < j) {
ans2++; // →にあるかず
}
}
}
ans = (ans + ans1 * o % mod) % mod;
}
ans = (ans + ans2 * K % mod) % mod;
// printf("%d",(((ans2*K%mod)+(ans1*K*(K-1)/2 % mod))%mod));
cout << ans << endl;
return 0;
}
|
#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
// 引数の受け取り
long long N, K;
cin >> N >> K;
long long A[N];
for (long long i = 0; i < N; i++) {
cin >> A[i];
}
long long mod = 1000000007;
long long ans1 = 0;
long long ans2 = 0;
long long ans = 0;
long long o = K * (K - 1) / 2 % mod;
for (long long i = 0; i < N; i++) {
ans1 = 0;
for (long long j = 0; j < N; j++) {
if (A[i] > A[j]) {
ans1++; //ブロックにあるかず
if (i < j) {
ans2++; // →にあるかず
}
}
}
ans = (ans + ans1 * o % mod) % mod;
}
ans = (ans + ans2 * K % mod) % mod;
// printf("%d",(((ans2*K%mod)+(ans1*K*(K-1)/2 % mod))%mod));
cout << ans << endl;
return 0;
}
|
[
"assignment.change"
] | 731,603
| 731,602
|
u641145334
|
cpp
|
p02928
|
#include <algorithm>
#include <array>
#include <climits>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
using P = pair<int, int>;
using T = tuple<long, long, long>;
long long MOD = 1000000007;
long long dp[100005][4];
int main() {
long long N, K;
cin >> N >> K;
vector<long long> A(N);
for (int i = 0; i < N; ++i)
cin >> A[i];
vector<long long> small(N);
for (int i = 0; i < N; ++i)
for (int j = 0; j < i; ++j)
if (A[i] < A[j])
small[i]++;
vector<long long> small2(N);
for (int i = 0; i < N; ++i)
for (int j = 0; j < N; ++j)
if (A[i] < A[j])
small2[i]++;
long long ans = 0;
long long k = (K * (K - 1)) / 2;
for (int i = 0; i < N; ++i) {
ans = (ans + ((small[i] * K) % MOD)) % MOD;
ans = (ans + ((small2[i] * k) % MOD)) % MOD;
}
cout << ans << endl;
}
|
#include <algorithm>
#include <array>
#include <climits>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
using P = pair<int, int>;
using T = tuple<long, long, long>;
long long MOD = 1000000007;
long long dp[100005][4];
int main() {
long long N, K;
cin >> N >> K;
vector<long long> A(N);
for (int i = 0; i < N; ++i)
cin >> A[i];
vector<long long> small(N);
for (int i = 0; i < N; ++i)
for (int j = 0; j < i; ++j)
if (A[i] < A[j])
small[i]++;
vector<long long> small2(N);
for (int i = 0; i < N; ++i)
for (int j = 0; j < N; ++j)
if (A[i] < A[j])
small2[i]++;
long long ans = 0;
long long k = ((K * (K - 1)) / 2) % MOD;
for (int i = 0; i < N; ++i) {
ans = (ans + ((small[i] * K) % MOD)) % MOD;
ans = (ans + ((small2[i] * k) % MOD)) % MOD;
}
cout << ans << endl;
}
|
[
"assignment.change"
] | 731,604
| 731,605
|
u168621426
|
cpp
|
p02928
|
#include <bits/stdc++.h>
#define mod 1000000007
#define rep(i, n) for (int i = 0; i < n; ++i)
using namespace std;
typedef long long ll;
const long long INF = 1LL << 60;
int main(void) {
int N;
ll K, ans = 0;
cin >> N >> K;
int A[N];
rep(i, N) cin >> A[i];
rep(i, N) {
rep(j, N) {
if (i == j)
continue;
if (i < j && A[i] > A[j])
ans += ((K * (K + 1)) / 2) % mod;
else if (i < j && A[i] > A[j])
ans += (((K - 1) * K) / 2) % mod;
}
ans %= mod;
}
cout << ans % mod;
return 0;
}
|
#include <bits/stdc++.h>
#define mod 1000000007
#define rep(i, n) for (int i = 0; i < n; ++i)
using namespace std;
typedef long long ll;
const long long INF = 1LL << 60;
int main(void) {
int N;
ll K, ans = 0;
cin >> N >> K;
int A[N];
rep(i, N) cin >> A[i];
rep(i, N) {
rep(j, N) {
if (i == j)
continue;
if (i < j && A[i] > A[j])
ans += ((K * (K + 1)) / 2) % mod;
else if (i > j && A[i] > A[j])
ans += (((K - 1) * K) / 2) % mod;
}
ans %= mod;
}
cout << ans % mod;
return 0;
}
|
[
"misc.opposites",
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 731,619
| 731,620
|
u895536055
|
cpp
|
p02928
|
#include <bits/stdc++.h>
#define rep(i, a) for (int i = 0; i < int(a); ++i)
#define REP(i, a, b) for (int i = int(a); i < int(b); ++i)
#define pb push_back
#define mp make_pair
#define F first
#define S second
using ll = long long;
using itn = int;
using namespace std;
int GCD(int a, int b) { return b ? GCD(b, a % b) : a; }
int main() {
ll N, K;
cin >> N >> K;
vector<ll> A(N);
vector<ll> p(N);
vector<ll> q(N);
rep(i, N) cin >> A.at(i);
rep(i, N) {
for (int j = i + 1; j < N; j++) {
if (A.at(i) > A.at(j))
p.at(i)++;
}
}
rep(i, N) {
rep(j, N) {
if (A.at(i) > A.at(j))
q.at(i)++;
}
}
ll ans = 0;
ll mod = 1e9 + 7;
rep(i, N) {
ans += (K * p.at(i) + q.at(i) * ((K * (K - 1) / 2))) % mod;
ans %= mod;
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
#define rep(i, a) for (int i = 0; i < int(a); ++i)
#define REP(i, a, b) for (int i = int(a); i < int(b); ++i)
#define pb push_back
#define mp make_pair
#define F first
#define S second
using ll = long long;
using itn = int;
using namespace std;
int GCD(int a, int b) { return b ? GCD(b, a % b) : a; }
int main() {
ll N, K;
cin >> N >> K;
vector<ll> A(N);
vector<ll> p(N, 0);
vector<ll> q(N, 0);
rep(i, N) cin >> A.at(i);
rep(i, N) {
for (int j = i + 1; j < N; j++) {
if (A.at(i) > A.at(j))
p.at(i)++;
}
}
rep(i, N) {
rep(j, N) {
if (A.at(i) > A.at(j))
q.at(i)++;
}
}
ll ans = 0;
ll mod = 1e9 + 7;
rep(i, N) {
ans += (K * p.at(i) + q.at(i) * ((K * (K - 1) / 2) % mod)) % mod;
ans %= mod;
}
cout << ans << endl;
}
|
[
"call.arguments.add",
"assignment.change"
] | 731,621
| 731,622
|
u089885969
|
cpp
|
p02928
|
#include <bits/stdc++.h>
#define rep(i, a) for (int i = 0; i < int(a); ++i)
#define REP(i, a, b) for (int i = int(a); i < int(b); ++i)
#define pb push_back
#define mp make_pair
#define F first
#define S second
using ll = long long;
using itn = int;
using namespace std;
int GCD(int a, int b) { return b ? GCD(b, a % b) : a; }
long long modinv(long long a, long long m) {
long long b = m, u = 1, v = 0;
while (b) {
long long t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
u %= m;
if (u < 0)
u += m;
return u;
}
int main() {
ll N, K;
cin >> N >> K;
vector<ll> A(N);
vector<ll> AA(2 * N);
rep(i, N) {
cin >> A.at(i);
AA.at(i) = A.at(i);
AA.at(i + N) = A.at(i);
}
vector<ll> base(N);
rep(i, N) {
for (int j = i + 1; j < N; j++) {
if (A.at(i) > A.at(j)) {
base.at(i)++;
}
}
}
vector<ll> inc(N);
rep(i, N) {
for (int j = N; j < 2 * N; j++) {
if (AA.at(i) > AA.at(j)) {
inc.at(i)++;
}
}
}
ll ans = 0;
ll mod = 1000000007;
ll minv = modinv(2, mod);
rep(i, N) {
//初項base.at(i)
//公差inc.at(i)
//項数K
ll tmp = ((2 * base.at(i)) + ((K - 1) * inc.at(i))) * K % mod * minv % mod;
ans += tmp;
ans %= mod;
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
#define rep(i, a) for (int i = 0; i < int(a); ++i)
#define REP(i, a, b) for (int i = int(a); i < int(b); ++i)
#define pb push_back
#define mp make_pair
#define F first
#define S second
using ll = long long;
using itn = int;
using namespace std;
int GCD(int a, int b) { return b ? GCD(b, a % b) : a; }
long long modinv(long long a, long long m) {
long long b = m, u = 1, v = 0;
while (b) {
long long t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
u %= m;
if (u < 0)
u += m;
return u;
}
int main() {
ll N, K;
cin >> N >> K;
vector<ll> A(N);
vector<ll> AA(2 * N);
rep(i, N) {
cin >> A.at(i);
AA.at(i) = A.at(i);
AA.at(i + N) = A.at(i);
}
vector<ll> base(N);
rep(i, N) {
for (int j = i + 1; j < N; j++) {
if (A.at(i) > A.at(j)) {
base.at(i)++;
}
}
}
vector<ll> inc(N);
rep(i, N) {
for (int j = N; j < 2 * N; j++) {
if (AA.at(i) > AA.at(j)) {
inc.at(i)++;
}
}
}
ll ans = 0;
ll mod = 1000000007;
ll minv = modinv(2, mod);
rep(i, N) {
//初項base.at(i)
//公差inc.at(i)
//項数K
ll tmp =
((2 * base.at(i)) + ((K - 1) * inc.at(i))) % mod * K % mod * minv % mod;
ans += tmp;
ans %= mod;
}
cout << ans << endl;
}
|
[
"assignment.change"
] | 731,623
| 731,624
|
u089885969
|
cpp
|
p02928
|
#include <bits/stdc++.h>
#define rep(i, a) for (int i = 0; i < int(a); ++i)
#define REP(i, a, b) for (int i = int(a); i < int(b); ++i)
#define pb push_back
#define mp make_pair
#define F first
#define S second
using ll = long long;
using itn = int;
using namespace std;
int GCD(int a, int b) { return b ? GCD(b, a % b) : a; }
long long modinv(long long a, long long m) {
long long b = m, u = 1, v = 0;
while (b) {
long long t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
u %= m;
if (u < 0)
u += m;
return u;
}
int main() {
ll N, K;
cin >> N >> K;
vector<ll> A(N);
vector<ll> AA(2 * N);
rep(i, N) {
cin >> A.at(i);
AA.at(i) = A.at(i);
AA.at(i + N) = A.at(i);
}
vector<ll> base(N);
rep(i, N) {
for (int j = i + 1; j < N; j++) {
if (A.at(i) > A.at(j)) {
base.at(i)++;
}
}
}
vector<int> inc(N);
rep(i, N) {
for (int j = N; j < 2 * N; j++) {
if (AA.at(i) > AA.at(j)) {
inc.at(i)++;
}
}
}
ll ans = 0;
ll mod = 1000000007;
ll minv = modinv(2, mod);
rep(i, N) {
//初項base.at(i)
//公差inc.at(i)
//項数K
ll tmp = ((2 * base.at(i)) + ((K - 1) * inc.at(i))) * K % mod * minv % mod;
ans += tmp;
ans %= mod;
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
#define rep(i, a) for (int i = 0; i < int(a); ++i)
#define REP(i, a, b) for (int i = int(a); i < int(b); ++i)
#define pb push_back
#define mp make_pair
#define F first
#define S second
using ll = long long;
using itn = int;
using namespace std;
int GCD(int a, int b) { return b ? GCD(b, a % b) : a; }
long long modinv(long long a, long long m) {
long long b = m, u = 1, v = 0;
while (b) {
long long t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
u %= m;
if (u < 0)
u += m;
return u;
}
int main() {
ll N, K;
cin >> N >> K;
vector<ll> A(N);
vector<ll> AA(2 * N);
rep(i, N) {
cin >> A.at(i);
AA.at(i) = A.at(i);
AA.at(i + N) = A.at(i);
}
vector<ll> base(N);
rep(i, N) {
for (int j = i + 1; j < N; j++) {
if (A.at(i) > A.at(j)) {
base.at(i)++;
}
}
}
vector<ll> inc(N);
rep(i, N) {
for (int j = N; j < 2 * N; j++) {
if (AA.at(i) > AA.at(j)) {
inc.at(i)++;
}
}
}
ll ans = 0;
ll mod = 1000000007;
ll minv = modinv(2, mod);
rep(i, N) {
//初項base.at(i)
//公差inc.at(i)
//項数K
ll tmp =
((2 * base.at(i)) + ((K - 1) * inc.at(i))) % mod * K % mod * minv % mod;
ans += tmp;
ans %= mod;
}
cout << ans << endl;
}
|
[
"assignment.change"
] | 731,625
| 731,624
|
u089885969
|
cpp
|
p02928
|
#include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
//#include <stdio.h>
//#include <stack>
//#include <queue>
//#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
//#include <fstream>
//#include <list>
#include <iomanip>
//#include <stdlib.h>
//#include <cctype>
using namespace std;
const int MAX_N = 1000000;
#define IOS ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define prec std::cout << std::fixed << std::setprecision(15);
#define endl "\n"
#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979
#define rep(i, n) for (int i = 0; i < int(n); i++)
#define ssort(z) sort(z.begin(), z.end())
#define rsort(z) sort(z.rbegin(), z.rend())
#define eerase(z) z.erase(unique(z.begin(), z.end()), z.end())
#define ccnt(z, w) count(z.begin(), z.end(), w)
void printVec(std::vector<int> &vec) {
std::cout << "";
for (auto it = vec.begin(); it != vec.end(); ++it) {
std::cout << *it << " ";
}
cout << '\n';
}
void printVec1(std::vector<string> &vec) {
std::cout << "";
for (auto it = vec.begin(); it != vec.end(); ++it) {
std::cout << *it << " ";
}
cout << '\n';
}
void printVec2(std::vector<Int> &vec) {
std::cout << "";
for (auto it = vec.begin(); it != vec.end(); ++it) {
std::cout << *it << " ";
}
cout << '\n';
}
Int gcd(Int a, Int b) { return b != 0 ? gcd(b, a % b) : a; }
Int lcm(Int a, Int b) {
return a / gcd(a, b) * b;
// a*bは64bit integer overflow
}
bool integer(double num) { return floor(num) == num; }
Int fact(int num) {
if (num == 0)
return 1;
else
return num * fact(num - 1);
}
int main() {
IOS;
// cout << fixed << setprecision(20);
// int a;cin >> a;
// string s;cin>>s;
Int n, k;
cin >> n >> k;
vector<int> a(n), b;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
Int cnt = 0, cnt2 = 0;
Int ans = 0;
for (int i = 0; i < n; i++) {
int num = a[i];
cnt = 0;
cnt2 = 0;
for (int j = i + 1; j < n; j++) {
if (num > a[j])
cnt++;
}
for (int k = 0; k < n; k++) {
if (num > a[k])
cnt2++;
}
// cout << num << " " << cnt << endl;
Int dif = cnt2 - cnt;
ans += k * (k + 1) / 2 % MOD * cnt2 % MOD - (k * dif) % MOD; // WA
// ans += k * (k - 1) / 2 % MOD * cnt2 % MOD + k * cnt % MOD;//AC
// ans%=MOD;
}
cout << ans % MOD;
cout << endl;
return 0;
}
/*
テレビも無ェ ラジオも無ェ
自動車もそれほど走って無ェ
ピアノも無ェ バーも無ェ
巡査 毎日ぐーるぐる
朝起ぎで 牛連れで
二時間ちょっとの散歩道
電話も無ェ 瓦斯も無ェ
バスは一日一度来る
俺らこんな村いやだ 俺らこんな村いやだ
東京へ出るだ 東京へ出だなら
銭コァ貯めで 東京でベコ(牛)飼うだ
*/
|
#include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
//#include <stdio.h>
//#include <stack>
//#include <queue>
//#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
//#include <fstream>
//#include <list>
#include <iomanip>
//#include <stdlib.h>
//#include <cctype>
using namespace std;
const int MAX_N = 1000000;
#define IOS ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define prec std::cout << std::fixed << std::setprecision(15);
#define endl "\n"
#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979
#define rep(i, n) for (int i = 0; i < int(n); i++)
#define ssort(z) sort(z.begin(), z.end())
#define rsort(z) sort(z.rbegin(), z.rend())
#define eerase(z) z.erase(unique(z.begin(), z.end()), z.end())
#define ccnt(z, w) count(z.begin(), z.end(), w)
void printVec(std::vector<int> &vec) {
std::cout << "";
for (auto it = vec.begin(); it != vec.end(); ++it) {
std::cout << *it << " ";
}
cout << '\n';
}
void printVec1(std::vector<string> &vec) {
std::cout << "";
for (auto it = vec.begin(); it != vec.end(); ++it) {
std::cout << *it << " ";
}
cout << '\n';
}
void printVec2(std::vector<Int> &vec) {
std::cout << "";
for (auto it = vec.begin(); it != vec.end(); ++it) {
std::cout << *it << " ";
}
cout << '\n';
}
Int gcd(Int a, Int b) { return b != 0 ? gcd(b, a % b) : a; }
Int lcm(Int a, Int b) {
return a / gcd(a, b) * b;
// a*bは64bit integer overflow
}
bool integer(double num) { return floor(num) == num; }
Int fact(int num) {
if (num == 0)
return 1;
else
return num * fact(num - 1);
}
int main() {
IOS;
// cout << fixed << setprecision(20);
// int a;cin >> a;
// string s;cin>>s;
Int n, k;
cin >> n >> k;
vector<int> a(n), b;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
Int cnt = 0, cnt2 = 0;
Int ans = 0;
for (int i = 0; i < n; i++) {
int num = a[i];
cnt = 0;
cnt2 = 0;
for (int j = i + 1; j < n; j++) {
if (num > a[j])
cnt++;
}
for (int k = 0; k < n; k++) {
if (num > a[k])
cnt2++;
}
// cout << num << " " << cnt << endl;
Int dif = cnt2 - cnt;
// ans += k *(k + 1) / 2 % MOD *cnt2 % MOD - (k *dif) % MOD;//WA
ans += k * (k - 1) / 2 % MOD * cnt2 % MOD + k * cnt % MOD; // AC
// ans%=MOD;
}
cout << ans % MOD;
cout << endl;
return 0;
}
/*
テレビも無ェ ラジオも無ェ
自動車もそれほど走って無ェ
ピアノも無ェ バーも無ェ
巡査 毎日ぐーるぐる
朝起ぎで 牛連れで
二時間ちょっとの散歩道
電話も無ェ 瓦斯も無ェ
バスは一日一度来る
俺らこんな村いやだ 俺らこんな村いやだ
東京へ出るだ 東京へ出だなら
銭コァ貯めで 東京でベコ(牛)飼うだ
*/
|
[
"misc.opposites",
"expression.operator.arithmetic.change",
"assignment.value.change",
"expression.operation.binary.change",
"identifier.change"
] | 731,626
| 731,627
|
u565624841
|
cpp
|
p02928
|
#include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
//#include <stdio.h>
//#include <stack>
//#include <queue>
//#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
//#include <fstream>
//#include <list>
#include <iomanip>
//#include <stdlib.h>
//#include <cctype>
using namespace std;
const int MAX_N = 1000000;
#define IOS ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define prec std::cout << std::fixed << std::setprecision(15);
#define endl "\n"
#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979
#define rep(i, n) for (int i = 0; i < int(n); i++)
#define ssort(z) sort(z.begin(), z.end())
#define rsort(z) sort(z.rbegin(), z.rend())
#define eerase(z) z.erase(unique(z.begin(), z.end()), z.end())
#define ccnt(z, w) count(z.begin(), z.end(), w)
void printVec(std::vector<int> &vec) {
std::cout << "";
for (auto it = vec.begin(); it != vec.end(); ++it) {
std::cout << *it << " ";
}
cout << '\n';
}
void printVec1(std::vector<string> &vec) {
std::cout << "";
for (auto it = vec.begin(); it != vec.end(); ++it) {
std::cout << *it << " ";
}
cout << '\n';
}
void printVec2(std::vector<Int> &vec) {
std::cout << "";
for (auto it = vec.begin(); it != vec.end(); ++it) {
std::cout << *it << " ";
}
cout << '\n';
}
Int gcd(Int a, Int b) { return b != 0 ? gcd(b, a % b) : a; }
Int lcm(Int a, Int b) {
return a / gcd(a, b) * b;
// a*bは64bit integer overflow
}
bool integer(double num) { return floor(num) == num; }
Int fact(int num) {
if (num == 0)
return 1;
else
return num * fact(num - 1);
}
int main() {
IOS;
// cout << fixed << setprecision(20);
// int a;cin >> a;
// string s;cin>>s;
Int n, k;
cin >> n >> k;
vector<int> a(n), b;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
Int cnt = 0, cnt2 = 0;
Int ans = 0;
for (int i = 0; i < n; i++) {
int num = a[i];
cnt = 0;
cnt2 = 0;
for (int j = i + 1; j < n; j++) {
if (num > a[j])
cnt++;
}
for (int k = 0; k < n; k++) {
if (num > a[k])
cnt2++;
}
// cout << num << " " << cnt << endl;
Int dif = cnt2 - cnt;
ans += k * (k + 1) / 2 % MOD * cnt2 % MOD - k * dif % MOD; // WA
// ans += k * (k - 1) / 2 % MOD * cnt2 % MOD + k * cnt % MOD;//AC
// ans%=MOD;
}
cout << ans % MOD;
cout << endl;
return 0;
}
/*
テレビも無ェ ラジオも無ェ
自動車もそれほど走って無ェ
ピアノも無ェ バーも無ェ
巡査 毎日ぐーるぐる
朝起ぎで 牛連れで
二時間ちょっとの散歩道
電話も無ェ 瓦斯も無ェ
バスは一日一度来る
俺らこんな村いやだ 俺らこんな村いやだ
東京へ出るだ 東京へ出だなら
銭コァ貯めで 東京でベコ(牛)飼うだ
*/
|
#include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
//#include <stdio.h>
//#include <stack>
//#include <queue>
//#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
//#include <fstream>
//#include <list>
#include <iomanip>
//#include <stdlib.h>
//#include <cctype>
using namespace std;
const int MAX_N = 1000000;
#define IOS ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define prec std::cout << std::fixed << std::setprecision(15);
#define endl "\n"
#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979
#define rep(i, n) for (int i = 0; i < int(n); i++)
#define ssort(z) sort(z.begin(), z.end())
#define rsort(z) sort(z.rbegin(), z.rend())
#define eerase(z) z.erase(unique(z.begin(), z.end()), z.end())
#define ccnt(z, w) count(z.begin(), z.end(), w)
void printVec(std::vector<int> &vec) {
std::cout << "";
for (auto it = vec.begin(); it != vec.end(); ++it) {
std::cout << *it << " ";
}
cout << '\n';
}
void printVec1(std::vector<string> &vec) {
std::cout << "";
for (auto it = vec.begin(); it != vec.end(); ++it) {
std::cout << *it << " ";
}
cout << '\n';
}
void printVec2(std::vector<Int> &vec) {
std::cout << "";
for (auto it = vec.begin(); it != vec.end(); ++it) {
std::cout << *it << " ";
}
cout << '\n';
}
Int gcd(Int a, Int b) { return b != 0 ? gcd(b, a % b) : a; }
Int lcm(Int a, Int b) {
return a / gcd(a, b) * b;
// a*bは64bit integer overflow
}
bool integer(double num) { return floor(num) == num; }
Int fact(int num) {
if (num == 0)
return 1;
else
return num * fact(num - 1);
}
int main() {
IOS;
// cout << fixed << setprecision(20);
// int a;cin >> a;
// string s;cin>>s;
Int n, k;
cin >> n >> k;
vector<int> a(n), b;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
Int cnt = 0, cnt2 = 0;
Int ans = 0;
for (int i = 0; i < n; i++) {
int num = a[i];
cnt = 0;
cnt2 = 0;
for (int j = i + 1; j < n; j++) {
if (num > a[j])
cnt++;
}
for (int k = 0; k < n; k++) {
if (num > a[k])
cnt2++;
}
// cout << num << " " << cnt << endl;
Int dif = cnt2 - cnt;
// ans += k *(k + 1) / 2 % MOD *cnt2 % MOD - (k *dif) % MOD;//WA
ans += k * (k - 1) / 2 % MOD * cnt2 % MOD + k * cnt % MOD; // AC
// ans%=MOD;
}
cout << ans % MOD;
cout << endl;
return 0;
}
/*
テレビも無ェ ラジオも無ェ
自動車もそれほど走って無ェ
ピアノも無ェ バーも無ェ
巡査 毎日ぐーるぐる
朝起ぎで 牛連れで
二時間ちょっとの散歩道
電話も無ェ 瓦斯も無ェ
バスは一日一度来る
俺らこんな村いやだ 俺らこんな村いやだ
東京へ出るだ 東京へ出だなら
銭コァ貯めで 東京でベコ(牛)飼うだ
*/
|
[
"misc.opposites",
"expression.operator.arithmetic.change",
"assignment.value.change",
"expression.operation.binary.change",
"identifier.change"
] | 731,628
| 731,627
|
u565624841
|
cpp
|
p02928
|
#include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
//#include <stdio.h>
//#include <stack>
//#include <queue>
//#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
//#include <fstream>
//#include <list>
#include <iomanip>
//#include <stdlib.h>
//#include <cctype>
using namespace std;
const int MAX_N = 1000000;
#define IOS ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define prec std::cout << std::fixed << std::setprecision(15);
#define endl "\n"
#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979
#define rep(i, n) for (int i = 0; i < int(n); i++)
#define ssort(z) sort(z.begin(), z.end())
#define rsort(z) sort(z.rbegin(), z.rend())
#define eerase(z) z.erase(unique(z.begin(), z.end()), z.end())
#define ccnt(z, w) count(z.begin(), z.end(), w)
void printVec(std::vector<int> &vec) {
std::cout << "";
for (auto it = vec.begin(); it != vec.end(); ++it) {
std::cout << *it << " ";
}
cout << '\n';
}
void printVec1(std::vector<string> &vec) {
std::cout << "";
for (auto it = vec.begin(); it != vec.end(); ++it) {
std::cout << *it << " ";
}
cout << '\n';
}
void printVec2(std::vector<Int> &vec) {
std::cout << "";
for (auto it = vec.begin(); it != vec.end(); ++it) {
std::cout << *it << " ";
}
cout << '\n';
}
Int gcd(Int a, Int b) { return b != 0 ? gcd(b, a % b) : a; }
Int lcm(Int a, Int b) {
return a / gcd(a, b) * b;
// a*bは64bit integer overflow
}
bool integer(double num) { return floor(num) == num; }
Int fact(int num) {
if (num == 0)
return 1;
else
return num * fact(num - 1);
}
int main() {
IOS;
// cout << fixed << setprecision(20);
// int a;cin >> a;
// string s;cin>>s;
int n, k;
cin >> n >> k;
vector<int> a(n), b;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
Int cnt = 0, cnt2 = 0;
Int ans = 0;
for (int i = 0; i < n; i++) {
int num = a[i];
cnt = 0;
cnt2 = 0;
for (int j = i + 1; j < n; j++) {
if (num > a[j])
cnt++;
}
for (int k = 0; k < n; k++) {
if (num > a[k])
cnt2++;
}
// cout << num << " " << cnt << endl;
Int dif = cnt2 - cnt;
// cout << dif << endl;
Int z = k % MOD;
// ans += k *(k + 1) / 2 % MOD *cnt2 % MOD - dif * k % MOD;
ans += k * (k - 1) / 2 % MOD * cnt2 % MOD + k * cnt % MOD;
ans %= MOD;
}
cout << ans % MOD;
cout << endl;
return 0;
}
/*
テレビも無ェ ラジオも無ェ
自動車もそれほど走って無ェ
ピアノも無ェ バーも無ェ
巡査 毎日ぐーるぐる
朝起ぎで 牛連れで
二時間ちょっとの散歩道
電話も無ェ 瓦斯も無ェ
バスは一日一度来る
俺らこんな村いやだ 俺らこんな村いやだ
東京へ出るだ 東京へ出だなら
銭コァ貯めで 東京でベコ(牛)飼うだ
*/
|
#include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
//#include <stdio.h>
//#include <stack>
//#include <queue>
//#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
//#include <fstream>
//#include <list>
#include <iomanip>
//#include <stdlib.h>
//#include <cctype>
using namespace std;
const int MAX_N = 1000000;
#define IOS ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define prec std::cout << std::fixed << std::setprecision(15);
#define endl "\n"
#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979
#define rep(i, n) for (int i = 0; i < int(n); i++)
#define ssort(z) sort(z.begin(), z.end())
#define rsort(z) sort(z.rbegin(), z.rend())
#define eerase(z) z.erase(unique(z.begin(), z.end()), z.end())
#define ccnt(z, w) count(z.begin(), z.end(), w)
void printVec(std::vector<int> &vec) {
std::cout << "";
for (auto it = vec.begin(); it != vec.end(); ++it) {
std::cout << *it << " ";
}
cout << '\n';
}
void printVec1(std::vector<string> &vec) {
std::cout << "";
for (auto it = vec.begin(); it != vec.end(); ++it) {
std::cout << *it << " ";
}
cout << '\n';
}
void printVec2(std::vector<Int> &vec) {
std::cout << "";
for (auto it = vec.begin(); it != vec.end(); ++it) {
std::cout << *it << " ";
}
cout << '\n';
}
Int gcd(Int a, Int b) { return b != 0 ? gcd(b, a % b) : a; }
Int lcm(Int a, Int b) {
return a / gcd(a, b) * b;
// a*bは64bit integer overflow
}
bool integer(double num) { return floor(num) == num; }
Int fact(int num) {
if (num == 0)
return 1;
else
return num * fact(num - 1);
}
int main() {
IOS;
// cout << fixed << setprecision(20);
// int a;cin >> a;
// string s;cin>>s;
Int n, k;
cin >> n >> k;
vector<int> a(n), b;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
Int cnt = 0, cnt2 = 0;
Int ans = 0;
for (int i = 0; i < n; i++) {
int num = a[i];
cnt = 0;
cnt2 = 0;
for (int j = i + 1; j < n; j++) {
if (num > a[j])
cnt++;
}
for (int k = 0; k < n; k++) {
if (num > a[k])
cnt2++;
}
// cout << num << " " << cnt << endl;
Int dif = cnt2 - cnt;
// cout << dif << endl;
Int z = k % MOD;
// ans += k *(k + 1) / 2 % MOD *cnt2 % MOD - dif * k % MOD;
ans += k * (k - 1) / 2 % MOD * cnt2 % MOD + k * cnt % MOD; // AC
// ans%=MOD;
}
cout << ans % MOD;
cout << endl;
return 0;
}
/*
テレビも無ェ ラジオも無ェ
自動車もそれほど走って無ェ
ピアノも無ェ バーも無ェ
巡査 毎日ぐーるぐる
朝起ぎで 牛連れで
二時間ちょっとの散歩道
電話も無ェ 瓦斯も無ェ
バスは一日一度来る
俺らこんな村いやだ 俺らこんな村いやだ
東京へ出るだ 東京へ出だなら
銭コァ貯めで 東京でベコ(牛)飼うだ
*/
|
[
"variable_declaration.type.change"
] | 731,629
| 731,630
|
u565624841
|
cpp
|
p02928
|
#include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
//#include <stdio.h>
//#include <stack>
//#include <queue>
//#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
//#include <fstream>
//#include <list>
#include <iomanip>
//#include <stdlib.h>
//#include <cctype>
using namespace std;
const int MAX_N = 1000000;
#define IOS ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define prec std::cout << std::fixed << std::setprecision(15);
#define endl "\n"
#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979
#define rep(i, n) for (int i = 0; i < int(n); i++)
#define ssort(z) sort(z.begin(), z.end())
#define rsort(z) sort(z.rbegin(), z.rend())
#define eerase(z) z.erase(unique(z.begin(), z.end()), z.end())
#define ccnt(z, w) count(z.begin(), z.end(), w)
void printVec(std::vector<int> &vec) {
std::cout << "";
for (auto it = vec.begin(); it != vec.end(); ++it) {
std::cout << *it << " ";
}
cout << '\n';
}
void printVec1(std::vector<string> &vec) {
std::cout << "";
for (auto it = vec.begin(); it != vec.end(); ++it) {
std::cout << *it << " ";
}
cout << '\n';
}
void printVec2(std::vector<Int> &vec) {
std::cout << "";
for (auto it = vec.begin(); it != vec.end(); ++it) {
std::cout << *it << " ";
}
cout << '\n';
}
Int gcd(Int a, Int b) { return b != 0 ? gcd(b, a % b) : a; }
Int lcm(Int a, Int b) {
return a / gcd(a, b) * b;
// a*bは64bit integer overflow
}
bool integer(double num) { return floor(num) == num; }
Int fact(int num) {
if (num == 0)
return 1;
else
return num * fact(num - 1);
}
int main() {
IOS;
// cout << fixed << setprecision(20);
// int a;cin >> a;
// string s;cin>>s;
int n, k;
cin >> n >> k;
vector<int> a(n), b;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
Int cnt = 0, cnt2 = 0;
Int ans = 0;
for (int i = 0; i < n; i++) {
int num = a[i];
cnt = 0;
cnt2 = 0;
for (int j = i + 1; j < n; j++) {
if (num > a[j])
cnt++;
}
for (int k = 0; k < n; k++) {
if (num > a[k])
cnt2++;
}
// cout << num << " " << cnt << endl;
Int dif = cnt2 - cnt;
// cout << dif << endl;
Int z = k % MOD;
// ans += k *(k + 1) / 2 % MOD *cnt2 % MOD - dif * k % MOD;
ans += k * (k - 1) / 2 % MOD * cnt2 % MOD + k * cnt % MOD; // AC
ans %= MOD;
}
cout << ans % MOD;
cout << endl;
return 0;
}
/*
テレビも無ェ ラジオも無ェ
自動車もそれほど走って無ェ
ピアノも無ェ バーも無ェ
巡査 毎日ぐーるぐる
朝起ぎで 牛連れで
二時間ちょっとの散歩道
電話も無ェ 瓦斯も無ェ
バスは一日一度来る
俺らこんな村いやだ 俺らこんな村いやだ
東京へ出るだ 東京へ出だなら
銭コァ貯めで 東京でベコ(牛)飼うだ
*/
|
#include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
//#include <stdio.h>
//#include <stack>
//#include <queue>
//#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
//#include <fstream>
//#include <list>
#include <iomanip>
//#include <stdlib.h>
//#include <cctype>
using namespace std;
const int MAX_N = 1000000;
#define IOS ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define prec std::cout << std::fixed << std::setprecision(15);
#define endl "\n"
#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979
#define rep(i, n) for (int i = 0; i < int(n); i++)
#define ssort(z) sort(z.begin(), z.end())
#define rsort(z) sort(z.rbegin(), z.rend())
#define eerase(z) z.erase(unique(z.begin(), z.end()), z.end())
#define ccnt(z, w) count(z.begin(), z.end(), w)
void printVec(std::vector<int> &vec) {
std::cout << "";
for (auto it = vec.begin(); it != vec.end(); ++it) {
std::cout << *it << " ";
}
cout << '\n';
}
void printVec1(std::vector<string> &vec) {
std::cout << "";
for (auto it = vec.begin(); it != vec.end(); ++it) {
std::cout << *it << " ";
}
cout << '\n';
}
void printVec2(std::vector<Int> &vec) {
std::cout << "";
for (auto it = vec.begin(); it != vec.end(); ++it) {
std::cout << *it << " ";
}
cout << '\n';
}
Int gcd(Int a, Int b) { return b != 0 ? gcd(b, a % b) : a; }
Int lcm(Int a, Int b) {
return a / gcd(a, b) * b;
// a*bは64bit integer overflow
}
bool integer(double num) { return floor(num) == num; }
Int fact(int num) {
if (num == 0)
return 1;
else
return num * fact(num - 1);
}
int main() {
IOS;
// cout << fixed << setprecision(20);
// int a;cin >> a;
// string s;cin>>s;
Int n, k;
cin >> n >> k;
vector<int> a(n), b;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
Int cnt = 0, cnt2 = 0;
Int ans = 0;
for (int i = 0; i < n; i++) {
int num = a[i];
cnt = 0;
cnt2 = 0;
for (int j = i + 1; j < n; j++) {
if (num > a[j])
cnt++;
}
for (int k = 0; k < n; k++) {
if (num > a[k])
cnt2++;
}
// cout << num << " " << cnt << endl;
Int dif = cnt2 - cnt;
// cout << dif << endl;
Int z = k % MOD;
// ans += k *(k + 1) / 2 % MOD *cnt2 % MOD - dif * k % MOD;
ans += k * (k - 1) / 2 % MOD * cnt2 % MOD + k * cnt % MOD; // AC
// ans%=MOD;
}
cout << ans % MOD;
cout << endl;
return 0;
}
/*
テレビも無ェ ラジオも無ェ
自動車もそれほど走って無ェ
ピアノも無ェ バーも無ェ
巡査 毎日ぐーるぐる
朝起ぎで 牛連れで
二時間ちょっとの散歩道
電話も無ェ 瓦斯も無ェ
バスは一日一度来る
俺らこんな村いやだ 俺らこんな村いやだ
東京へ出るだ 東京へ出だなら
銭コァ貯めで 東京でベコ(牛)飼うだ
*/
|
[
"variable_declaration.type.change"
] | 731,631
| 731,630
|
u565624841
|
cpp
|
p02928
|
#include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
//#include <stdio.h>
//#include <stack>
//#include <queue>
//#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
//#include <fstream>
//#include <list>
#include <iomanip>
//#include <stdlib.h>
//#include <cctype>
using namespace std;
const int MAX_N = 1000000;
#define IOS ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define prec std::cout << std::fixed << std::setprecision(15);
#define endl "\n"
#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979
#define rep(i, n) for (int i = 0; i < int(n); i++)
#define ssort(z) sort(z.begin(), z.end())
#define rsort(z) sort(z.rbegin(), z.rend())
#define eerase(z) z.erase(unique(z.begin(), z.end()), z.end())
#define ccnt(z, w) count(z.begin(), z.end(), w)
void printVec(std::vector<int> &vec) {
std::cout << "";
for (auto it = vec.begin(); it != vec.end(); ++it) {
std::cout << *it << " ";
}
cout << '\n';
}
void printVec1(std::vector<string> &vec) {
std::cout << "";
for (auto it = vec.begin(); it != vec.end(); ++it) {
std::cout << *it << " ";
}
cout << '\n';
}
void printVec2(std::vector<Int> &vec) {
std::cout << "";
for (auto it = vec.begin(); it != vec.end(); ++it) {
std::cout << *it << " ";
}
cout << '\n';
}
Int gcd(Int a, Int b) { return b != 0 ? gcd(b, a % b) : a; }
Int lcm(Int a, Int b) {
return a / gcd(a, b) * b;
// a*bは64bit integer overflow
}
bool integer(double num) { return floor(num) == num; }
Int fact(int num) {
if (num == 0)
return 1;
else
return num * fact(num - 1);
}
int main() {
IOS;
// cout << fixed << setprecision(20);
// int a;cin >> a;
// string s;cin>>s;
int n, k;
cin >> n >> k;
vector<int> a(n), b;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
Int cnt = 0, cnt2 = 0;
Int ans = 0;
for (int i = 0; i < n; i++) {
int num = a[i];
cnt = 0;
cnt2 = 0;
for (int j = i + 1; j < n; j++) {
if (num > a[j])
cnt++;
}
for (int k = 0; k < n; k++) {
if (num > a[k])
cnt2++;
}
// cout << num << " " << cnt << endl;
Int dif = cnt2 - cnt;
// cout << dif << endl;
Int z = k % MOD;
// ans += k *(k + 1) / 2 % MOD *cnt2 % MOD - dif * k % MOD;
ans += k * (k - 1) / 2 % MOD * cnt2 % MOD + k * cnt % MOD; // AC
}
cout << ans % MOD;
cout << endl;
return 0;
}
/*
テレビも無ェ ラジオも無ェ
自動車もそれほど走って無ェ
ピアノも無ェ バーも無ェ
巡査 毎日ぐーるぐる
朝起ぎで 牛連れで
二時間ちょっとの散歩道
電話も無ェ 瓦斯も無ェ
バスは一日一度来る
俺らこんな村いやだ 俺らこんな村いやだ
東京へ出るだ 東京へ出だなら
銭コァ貯めで 東京でベコ(牛)飼うだ
*/
|
#include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
//#include <stdio.h>
//#include <stack>
//#include <queue>
//#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
//#include <fstream>
//#include <list>
#include <iomanip>
//#include <stdlib.h>
//#include <cctype>
using namespace std;
const int MAX_N = 1000000;
#define IOS ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define prec std::cout << std::fixed << std::setprecision(15);
#define endl "\n"
#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979
#define rep(i, n) for (int i = 0; i < int(n); i++)
#define ssort(z) sort(z.begin(), z.end())
#define rsort(z) sort(z.rbegin(), z.rend())
#define eerase(z) z.erase(unique(z.begin(), z.end()), z.end())
#define ccnt(z, w) count(z.begin(), z.end(), w)
void printVec(std::vector<int> &vec) {
std::cout << "";
for (auto it = vec.begin(); it != vec.end(); ++it) {
std::cout << *it << " ";
}
cout << '\n';
}
void printVec1(std::vector<string> &vec) {
std::cout << "";
for (auto it = vec.begin(); it != vec.end(); ++it) {
std::cout << *it << " ";
}
cout << '\n';
}
void printVec2(std::vector<Int> &vec) {
std::cout << "";
for (auto it = vec.begin(); it != vec.end(); ++it) {
std::cout << *it << " ";
}
cout << '\n';
}
Int gcd(Int a, Int b) { return b != 0 ? gcd(b, a % b) : a; }
Int lcm(Int a, Int b) {
return a / gcd(a, b) * b;
// a*bは64bit integer overflow
}
bool integer(double num) { return floor(num) == num; }
Int fact(int num) {
if (num == 0)
return 1;
else
return num * fact(num - 1);
}
int main() {
IOS;
// cout << fixed << setprecision(20);
// int a;cin >> a;
// string s;cin>>s;
Int n, k;
cin >> n >> k;
vector<int> a(n), b;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
Int cnt = 0, cnt2 = 0;
Int ans = 0;
for (int i = 0; i < n; i++) {
int num = a[i];
cnt = 0;
cnt2 = 0;
for (int j = i + 1; j < n; j++) {
if (num > a[j])
cnt++;
}
for (int k = 0; k < n; k++) {
if (num > a[k])
cnt2++;
}
// cout << num << " " << cnt << endl;
Int dif = cnt2 - cnt;
// cout << dif << endl;
Int z = k % MOD;
// ans += k *(k + 1) / 2 % MOD *cnt2 % MOD - dif * k % MOD;
ans += k * (k - 1) / 2 % MOD * cnt2 % MOD + k * cnt % MOD; // AC
// ans%=MOD;
}
cout << ans % MOD;
cout << endl;
return 0;
}
/*
テレビも無ェ ラジオも無ェ
自動車もそれほど走って無ェ
ピアノも無ェ バーも無ェ
巡査 毎日ぐーるぐる
朝起ぎで 牛連れで
二時間ちょっとの散歩道
電話も無ェ 瓦斯も無ェ
バスは一日一度来る
俺らこんな村いやだ 俺らこんな村いやだ
東京へ出るだ 東京へ出だなら
銭コァ貯めで 東京でベコ(牛)飼うだ
*/
|
[
"variable_declaration.type.change"
] | 731,632
| 731,630
|
u565624841
|
cpp
|
p02928
|
#include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
//#include <stdio.h>
//#include <stack>
//#include <queue>
//#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
//#include <fstream>
//#include <list>
#include <iomanip>
//#include <stdlib.h>
//#include <cctype>
using namespace std;
const int MAX_N = 1000000;
#define IOS ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define prec std::cout << std::fixed << std::setprecision(15);
#define endl "\n"
#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979
#define rep(i, n) for (int i = 0; i < int(n); i++)
#define ssort(z) sort(z.begin(), z.end())
#define rsort(z) sort(z.rbegin(), z.rend())
#define eerase(z) z.erase(unique(z.begin(), z.end()), z.end())
#define ccnt(z, w) count(z.begin(), z.end(), w)
void printVec(std::vector<int> &vec) {
std::cout << "";
for (auto it = vec.begin(); it != vec.end(); ++it) {
std::cout << *it << " ";
}
cout << '\n';
}
void printVec1(std::vector<string> &vec) {
std::cout << "";
for (auto it = vec.begin(); it != vec.end(); ++it) {
std::cout << *it << " ";
}
cout << '\n';
}
void printVec2(std::vector<Int> &vec) {
std::cout << "";
for (auto it = vec.begin(); it != vec.end(); ++it) {
std::cout << *it << " ";
}
cout << '\n';
}
Int gcd(Int a, Int b) { return b != 0 ? gcd(b, a % b) : a; }
Int lcm(Int a, Int b) {
return a / gcd(a, b) * b;
// a*bは64bit integer overflow
}
bool integer(double num) { return floor(num) == num; }
Int fact(int num) {
if (num == 0)
return 1;
else
return num * fact(num - 1);
}
int main() {
IOS;
// cout << fixed << setprecision(20);
// int a;cin >> a;
// string s;cin>>s;
Int n, k;
cin >> n >> k;
vector<int> a(n), b;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
Int cnt = 0, cnt2 = 0;
Int ans = 0;
for (int i = 0; i < n; i++) {
int num = a[i];
cnt = 0;
cnt2 = 0;
for (int j = i + 1; j < n; j++) {
if (num > a[j])
cnt++;
}
for (int k = 0; k < n; k++) {
if (num > a[k])
cnt2++;
}
// cout << num << " " << cnt << endl;
Int dif = cnt2 - cnt;
// cout << dif << endl;
Int z = k % MOD;
ans += k * (k + 1) / 2 % MOD * cnt2 % MOD - dif * k % MOD;
// ans += k * (k - 1) / 2 % MOD * cnt2 % MOD + k * cnt % MOD;//AC
ans %= MOD;
}
cout << ans % MOD;
cout << endl;
return 0;
}
/*
テレビも無ェ ラジオも無ェ
自動車もそれほど走って無ェ
ピアノも無ェ バーも無ェ
巡査 毎日ぐーるぐる
朝起ぎで 牛連れで
二時間ちょっとの散歩道
電話も無ェ 瓦斯も無ェ
バスは一日一度来る
俺らこんな村いやだ 俺らこんな村いやだ
東京へ出るだ 東京へ出だなら
銭コァ貯めで 東京でベコ(牛)飼うだ
*/
|
#include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
//#include <stdio.h>
//#include <stack>
//#include <queue>
//#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
//#include <fstream>
//#include <list>
#include <iomanip>
//#include <stdlib.h>
//#include <cctype>
using namespace std;
const int MAX_N = 1000000;
#define IOS ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define prec std::cout << std::fixed << std::setprecision(15);
#define endl "\n"
#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979
#define rep(i, n) for (int i = 0; i < int(n); i++)
#define ssort(z) sort(z.begin(), z.end())
#define rsort(z) sort(z.rbegin(), z.rend())
#define eerase(z) z.erase(unique(z.begin(), z.end()), z.end())
#define ccnt(z, w) count(z.begin(), z.end(), w)
void printVec(std::vector<int> &vec) {
std::cout << "";
for (auto it = vec.begin(); it != vec.end(); ++it) {
std::cout << *it << " ";
}
cout << '\n';
}
void printVec1(std::vector<string> &vec) {
std::cout << "";
for (auto it = vec.begin(); it != vec.end(); ++it) {
std::cout << *it << " ";
}
cout << '\n';
}
void printVec2(std::vector<Int> &vec) {
std::cout << "";
for (auto it = vec.begin(); it != vec.end(); ++it) {
std::cout << *it << " ";
}
cout << '\n';
}
Int gcd(Int a, Int b) { return b != 0 ? gcd(b, a % b) : a; }
Int lcm(Int a, Int b) {
return a / gcd(a, b) * b;
// a*bは64bit integer overflow
}
bool integer(double num) { return floor(num) == num; }
Int fact(int num) {
if (num == 0)
return 1;
else
return num * fact(num - 1);
}
int main() {
IOS;
// cout << fixed << setprecision(20);
// int a;cin >> a;
// string s;cin>>s;
Int n, k;
cin >> n >> k;
vector<int> a(n), b;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
Int cnt = 0, cnt2 = 0;
Int ans = 0;
for (int i = 0; i < n; i++) {
int num = a[i];
cnt = 0;
cnt2 = 0;
for (int j = i + 1; j < n; j++) {
if (num > a[j])
cnt++;
}
for (int k = 0; k < n; k++) {
if (num > a[k])
cnt2++;
}
// cout << num << " " << cnt << endl;
Int dif = cnt2 - cnt;
// cout << dif << endl;
Int z = k % MOD;
// ans += k *(k + 1) / 2 % MOD *cnt2 % MOD - dif * k % MOD;
ans += k * (k - 1) / 2 % MOD * cnt2 % MOD + k * cnt % MOD; // AC
ans %= MOD;
}
cout << ans % MOD;
cout << endl;
return 0;
}
/*
テレビも無ェ ラジオも無ェ
自動車もそれほど走って無ェ
ピアノも無ェ バーも無ェ
巡査 毎日ぐーるぐる
朝起ぎで 牛連れで
二時間ちょっとの散歩道
電話も無ェ 瓦斯も無ェ
バスは一日一度来る
俺らこんな村いやだ 俺らこんな村いやだ
東京へ出るだ 東京へ出だなら
銭コァ貯めで 東京でベコ(牛)飼うだ
*/
|
[
"misc.opposites",
"expression.operator.arithmetic.change",
"assignment.value.change",
"expression.operation.binary.change",
"expression.operation.binary.remove",
"assignment.change"
] | 731,633
| 731,634
|
u565624841
|
cpp
|
p02928
|
#include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
//#include <stdio.h>
//#include <stack>
//#include <queue>
//#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
//#include <fstream>
//#include <list>
#include <iomanip>
//#include <stdlib.h>
//#include <cctype>
using namespace std;
const int MAX_N = 1000000;
#define IOS ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define prec std::cout << std::fixed << std::setprecision(15);
#define endl "\n"
#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979
#define rep(i, n) for (int i = 0; i < int(n); i++)
#define ssort(z) sort(z.begin(), z.end())
#define rsort(z) sort(z.rbegin(), z.rend())
#define eerase(z) z.erase(unique(z.begin(), z.end()), z.end())
#define ccnt(z, w) count(z.begin(), z.end(), w)
void printVec(std::vector<int> &vec) {
std::cout << "";
for (auto it = vec.begin(); it != vec.end(); ++it) {
std::cout << *it << " ";
}
cout << '\n';
}
void printVec1(std::vector<string> &vec) {
std::cout << "";
for (auto it = vec.begin(); it != vec.end(); ++it) {
std::cout << *it << " ";
}
cout << '\n';
}
void printVec2(std::vector<Int> &vec) {
std::cout << "";
for (auto it = vec.begin(); it != vec.end(); ++it) {
std::cout << *it << " ";
}
cout << '\n';
}
Int gcd(Int a, Int b) { return b != 0 ? gcd(b, a % b) : a; }
Int lcm(Int a, Int b) {
return a / gcd(a, b) * b;
// a*bは64bit integer overflow
}
bool integer(double num) { return floor(num) == num; }
Int fact(int num) {
if (num == 0)
return 1;
else
return num * fact(num - 1);
}
int main() {
IOS;
// cout << fixed << setprecision(20);
// int a;cin >> a;
// string s;cin>>s;
int n, k;
cin >> n >> k;
vector<int> a(n), b;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
Int cnt = 0, cnt2 = 0;
Int ans = 0;
for (int i = 0; i < n; i++) {
int num = a[i];
cnt = 0;
cnt2 = 0;
for (int j = i + 1; j < n; j++) {
if (num > a[j])
cnt++;
}
for (int k = 0; k < n; k++) {
if (num > a[k])
cnt2++;
}
// cout << num << " " << cnt << endl;
Int dif = cnt2 - cnt;
// cout << dif << endl;
Int z = k % MOD;
// ans += k *(k + 1) / 2 % MOD *cnt2 % MOD - dif * k % MOD;
ans += k * (k - 1) / 2 % MOD * cnt2 % MOD + k * cnt % MOD;
ans %= MOD;
}
cout << ans % MOD;
cout << endl;
return 0;
}
/*
テレビも無ェ ラジオも無ェ
自動車もそれほど走って無ェ
ピアノも無ェ バーも無ェ
巡査 毎日ぐーるぐる
朝起ぎで 牛連れで
二時間ちょっとの散歩道
電話も無ェ 瓦斯も無ェ
バスは一日一度来る
俺らこんな村いやだ 俺らこんな村いやだ
東京へ出るだ 東京へ出だなら
銭コァ貯めで 東京でベコ(牛)飼うだ
*/
|
#include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
//#include <stdio.h>
//#include <stack>
//#include <queue>
//#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
//#include <fstream>
//#include <list>
#include <iomanip>
//#include <stdlib.h>
//#include <cctype>
using namespace std;
const int MAX_N = 1000000;
#define IOS ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define prec std::cout << std::fixed << std::setprecision(15);
#define endl "\n"
#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979
#define rep(i, n) for (int i = 0; i < int(n); i++)
#define ssort(z) sort(z.begin(), z.end())
#define rsort(z) sort(z.rbegin(), z.rend())
#define eerase(z) z.erase(unique(z.begin(), z.end()), z.end())
#define ccnt(z, w) count(z.begin(), z.end(), w)
void printVec(std::vector<int> &vec) {
std::cout << "";
for (auto it = vec.begin(); it != vec.end(); ++it) {
std::cout << *it << " ";
}
cout << '\n';
}
void printVec1(std::vector<string> &vec) {
std::cout << "";
for (auto it = vec.begin(); it != vec.end(); ++it) {
std::cout << *it << " ";
}
cout << '\n';
}
void printVec2(std::vector<Int> &vec) {
std::cout << "";
for (auto it = vec.begin(); it != vec.end(); ++it) {
std::cout << *it << " ";
}
cout << '\n';
}
Int gcd(Int a, Int b) { return b != 0 ? gcd(b, a % b) : a; }
Int lcm(Int a, Int b) {
return a / gcd(a, b) * b;
// a*bは64bit integer overflow
}
bool integer(double num) { return floor(num) == num; }
Int fact(int num) {
if (num == 0)
return 1;
else
return num * fact(num - 1);
}
int main() {
IOS;
// cout << fixed << setprecision(20);
// int a;cin >> a;
// string s;cin>>s;
Int n, k;
cin >> n >> k;
vector<int> a(n), b;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
Int cnt = 0, cnt2 = 0;
Int ans = 0;
for (int i = 0; i < n; i++) {
int num = a[i];
cnt = 0;
cnt2 = 0;
for (int j = i + 1; j < n; j++) {
if (num > a[j])
cnt++;
}
for (int k = 0; k < n; k++) {
if (num > a[k])
cnt2++;
}
// cout << num << " " << cnt << endl;
Int dif = cnt2 - cnt;
// cout << dif << endl;
Int z = k % MOD;
// ans += k *(k + 1) / 2 % MOD *cnt2 % MOD - dif * k % MOD;
ans += k * (k - 1) / 2 % MOD * cnt2 % MOD + k * cnt % MOD; // AC
ans %= MOD;
}
cout << ans % MOD;
cout << endl;
return 0;
}
/*
テレビも無ェ ラジオも無ェ
自動車もそれほど走って無ェ
ピアノも無ェ バーも無ェ
巡査 毎日ぐーるぐる
朝起ぎで 牛連れで
二時間ちょっとの散歩道
電話も無ェ 瓦斯も無ェ
バスは一日一度来る
俺らこんな村いやだ 俺らこんな村いやだ
東京へ出るだ 東京へ出だなら
銭コァ貯めで 東京でベコ(牛)飼うだ
*/
|
[
"variable_declaration.type.change"
] | 731,629
| 731,634
|
u565624841
|
cpp
|
p02928
|
#include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
//#include <stdio.h>
//#include <stack>
//#include <queue>
//#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
//#include <fstream>
//#include <list>
#include <iomanip>
//#include <stdlib.h>
//#include <cctype>
using namespace std;
const int MAX_N = 1000000;
#define IOS ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define prec std::cout << std::fixed << std::setprecision(15);
#define endl "\n"
#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979
#define rep(i, n) for (int i = 0; i < int(n); i++)
#define ssort(z) sort(z.begin(), z.end())
#define rsort(z) sort(z.rbegin(), z.rend())
#define eerase(z) z.erase(unique(z.begin(), z.end()), z.end())
#define ccnt(z, w) count(z.begin(), z.end(), w)
void printVec(std::vector<int> &vec) {
std::cout << "";
for (auto it = vec.begin(); it != vec.end(); ++it) {
std::cout << *it << " ";
}
cout << '\n';
}
void printVec1(std::vector<string> &vec) {
std::cout << "";
for (auto it = vec.begin(); it != vec.end(); ++it) {
std::cout << *it << " ";
}
cout << '\n';
}
void printVec2(std::vector<Int> &vec) {
std::cout << "";
for (auto it = vec.begin(); it != vec.end(); ++it) {
std::cout << *it << " ";
}
cout << '\n';
}
Int gcd(Int a, Int b) { return b != 0 ? gcd(b, a % b) : a; }
Int lcm(Int a, Int b) {
return a / gcd(a, b) * b;
// a*bは64bit integer overflow
}
bool integer(double num) { return floor(num) == num; }
Int fact(int num) {
if (num == 0)
return 1;
else
return num * fact(num - 1);
}
int main() {
IOS;
// cout << fixed << setprecision(20);
// int a;cin >> a;
// string s;cin>>s;
int n, k;
cin >> n >> k;
vector<int> a(n), b;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
Int cnt = 0, cnt2 = 0;
Int ans = 0;
for (int i = 0; i < n; i++) {
int num = a[i];
cnt = 0;
cnt2 = 0;
for (int j = i + 1; j < n; j++) {
if (num > a[j])
cnt++;
}
for (int k = 0; k < n; k++) {
if (num > a[k])
cnt2++;
}
// cout << num << " " << cnt << endl;
Int dif = cnt2 - cnt;
// cout << dif << endl;
Int z = k % MOD;
// ans += k *(k + 1) / 2 % MOD *cnt2 % MOD - dif * k % MOD;
ans += k * (k - 1) / 2 % MOD * cnt2 % MOD + k * cnt % MOD; // AC
ans %= MOD;
}
cout << ans % MOD;
cout << endl;
return 0;
}
/*
テレビも無ェ ラジオも無ェ
自動車もそれほど走って無ェ
ピアノも無ェ バーも無ェ
巡査 毎日ぐーるぐる
朝起ぎで 牛連れで
二時間ちょっとの散歩道
電話も無ェ 瓦斯も無ェ
バスは一日一度来る
俺らこんな村いやだ 俺らこんな村いやだ
東京へ出るだ 東京へ出だなら
銭コァ貯めで 東京でベコ(牛)飼うだ
*/
|
#include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
//#include <stdio.h>
//#include <stack>
//#include <queue>
//#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
//#include <fstream>
//#include <list>
#include <iomanip>
//#include <stdlib.h>
//#include <cctype>
using namespace std;
const int MAX_N = 1000000;
#define IOS ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define prec std::cout << std::fixed << std::setprecision(15);
#define endl "\n"
#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979
#define rep(i, n) for (int i = 0; i < int(n); i++)
#define ssort(z) sort(z.begin(), z.end())
#define rsort(z) sort(z.rbegin(), z.rend())
#define eerase(z) z.erase(unique(z.begin(), z.end()), z.end())
#define ccnt(z, w) count(z.begin(), z.end(), w)
void printVec(std::vector<int> &vec) {
std::cout << "";
for (auto it = vec.begin(); it != vec.end(); ++it) {
std::cout << *it << " ";
}
cout << '\n';
}
void printVec1(std::vector<string> &vec) {
std::cout << "";
for (auto it = vec.begin(); it != vec.end(); ++it) {
std::cout << *it << " ";
}
cout << '\n';
}
void printVec2(std::vector<Int> &vec) {
std::cout << "";
for (auto it = vec.begin(); it != vec.end(); ++it) {
std::cout << *it << " ";
}
cout << '\n';
}
Int gcd(Int a, Int b) { return b != 0 ? gcd(b, a % b) : a; }
Int lcm(Int a, Int b) {
return a / gcd(a, b) * b;
// a*bは64bit integer overflow
}
bool integer(double num) { return floor(num) == num; }
Int fact(int num) {
if (num == 0)
return 1;
else
return num * fact(num - 1);
}
int main() {
IOS;
// cout << fixed << setprecision(20);
// int a;cin >> a;
// string s;cin>>s;
Int n, k;
cin >> n >> k;
vector<int> a(n), b;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
Int cnt = 0, cnt2 = 0;
Int ans = 0;
for (int i = 0; i < n; i++) {
int num = a[i];
cnt = 0;
cnt2 = 0;
for (int j = i + 1; j < n; j++) {
if (num > a[j])
cnt++;
}
for (int k = 0; k < n; k++) {
if (num > a[k])
cnt2++;
}
// cout << num << " " << cnt << endl;
Int dif = cnt2 - cnt;
// cout << dif << endl;
Int z = k % MOD;
// ans += k *(k + 1) / 2 % MOD *cnt2 % MOD - dif * k % MOD;
ans += k * (k - 1) / 2 % MOD * cnt2 % MOD + k * cnt % MOD; // AC
ans %= MOD;
}
cout << ans % MOD;
cout << endl;
return 0;
}
/*
テレビも無ェ ラジオも無ェ
自動車もそれほど走って無ェ
ピアノも無ェ バーも無ェ
巡査 毎日ぐーるぐる
朝起ぎで 牛連れで
二時間ちょっとの散歩道
電話も無ェ 瓦斯も無ェ
バスは一日一度来る
俺らこんな村いやだ 俺らこんな村いやだ
東京へ出るだ 東京へ出だなら
銭コァ貯めで 東京でベコ(牛)飼うだ
*/
|
[
"variable_declaration.type.change"
] | 731,631
| 731,634
|
u565624841
|
cpp
|
p02928
|
#include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
//#include <stdio.h>
//#include <stack>
//#include <queue>
//#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
//#include <fstream>
//#include <list>
#include <iomanip>
//#include <stdlib.h>
//#include <cctype>
using namespace std;
const int MAX_N = 1000000;
#define IOS ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define prec std::cout << std::fixed << std::setprecision(15);
#define endl "\n"
#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979
#define rep(i, n) for (int i = 0; i < int(n); i++)
#define ssort(z) sort(z.begin(), z.end())
#define rsort(z) sort(z.rbegin(), z.rend())
#define eerase(z) z.erase(unique(z.begin(), z.end()), z.end())
#define ccnt(z, w) count(z.begin(), z.end(), w)
void printVec(std::vector<int> &vec) {
std::cout << "";
for (auto it = vec.begin(); it != vec.end(); ++it) {
std::cout << *it << " ";
}
cout << '\n';
}
void printVec1(std::vector<string> &vec) {
std::cout << "";
for (auto it = vec.begin(); it != vec.end(); ++it) {
std::cout << *it << " ";
}
cout << '\n';
}
void printVec2(std::vector<Int> &vec) {
std::cout << "";
for (auto it = vec.begin(); it != vec.end(); ++it) {
std::cout << *it << " ";
}
cout << '\n';
}
Int gcd(Int a, Int b) { return b != 0 ? gcd(b, a % b) : a; }
Int lcm(Int a, Int b) {
return a / gcd(a, b) * b;
// a*bは64bit integer overflow
}
bool integer(double num) { return floor(num) == num; }
Int fact(int num) {
if (num == 0)
return 1;
else
return num * fact(num - 1);
}
int main() {
IOS;
// cout << fixed << setprecision(20);
// int a;cin >> a;
// string s;cin>>s;
int n, k;
cin >> n >> k;
vector<int> a(n), b;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
Int cnt = 0, cnt2 = 0;
Int ans = 0;
for (int i = 0; i < n; i++) {
int num = a[i];
cnt = 0;
cnt2 = 0;
for (int j = i + 1; j < n; j++) {
if (num > a[j])
cnt++;
}
for (int k = 0; k < n; k++) {
if (num > a[k])
cnt2++;
}
// cout << num << " " << cnt << endl;
Int dif = cnt2 - cnt;
// cout << dif << endl;
Int z = k % MOD;
// ans += k *(k + 1) / 2 % MOD *cnt2 % MOD - dif * k % MOD;
ans += k * (k - 1) / 2 % MOD * cnt2 % MOD + k * cnt % MOD; // AC
}
cout << ans % MOD;
cout << endl;
return 0;
}
/*
テレビも無ェ ラジオも無ェ
自動車もそれほど走って無ェ
ピアノも無ェ バーも無ェ
巡査 毎日ぐーるぐる
朝起ぎで 牛連れで
二時間ちょっとの散歩道
電話も無ェ 瓦斯も無ェ
バスは一日一度来る
俺らこんな村いやだ 俺らこんな村いやだ
東京へ出るだ 東京へ出だなら
銭コァ貯めで 東京でベコ(牛)飼うだ
*/
|
#include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
//#include <stdio.h>
//#include <stack>
//#include <queue>
//#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
//#include <fstream>
//#include <list>
#include <iomanip>
//#include <stdlib.h>
//#include <cctype>
using namespace std;
const int MAX_N = 1000000;
#define IOS ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define prec std::cout << std::fixed << std::setprecision(15);
#define endl "\n"
#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979
#define rep(i, n) for (int i = 0; i < int(n); i++)
#define ssort(z) sort(z.begin(), z.end())
#define rsort(z) sort(z.rbegin(), z.rend())
#define eerase(z) z.erase(unique(z.begin(), z.end()), z.end())
#define ccnt(z, w) count(z.begin(), z.end(), w)
void printVec(std::vector<int> &vec) {
std::cout << "";
for (auto it = vec.begin(); it != vec.end(); ++it) {
std::cout << *it << " ";
}
cout << '\n';
}
void printVec1(std::vector<string> &vec) {
std::cout << "";
for (auto it = vec.begin(); it != vec.end(); ++it) {
std::cout << *it << " ";
}
cout << '\n';
}
void printVec2(std::vector<Int> &vec) {
std::cout << "";
for (auto it = vec.begin(); it != vec.end(); ++it) {
std::cout << *it << " ";
}
cout << '\n';
}
Int gcd(Int a, Int b) { return b != 0 ? gcd(b, a % b) : a; }
Int lcm(Int a, Int b) {
return a / gcd(a, b) * b;
// a*bは64bit integer overflow
}
bool integer(double num) { return floor(num) == num; }
Int fact(int num) {
if (num == 0)
return 1;
else
return num * fact(num - 1);
}
int main() {
IOS;
// cout << fixed << setprecision(20);
// int a;cin >> a;
// string s;cin>>s;
Int n, k;
cin >> n >> k;
vector<int> a(n), b;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
Int cnt = 0, cnt2 = 0;
Int ans = 0;
for (int i = 0; i < n; i++) {
int num = a[i];
cnt = 0;
cnt2 = 0;
for (int j = i + 1; j < n; j++) {
if (num > a[j])
cnt++;
}
for (int k = 0; k < n; k++) {
if (num > a[k])
cnt2++;
}
// cout << num << " " << cnt << endl;
Int dif = cnt2 - cnt;
// cout << dif << endl;
Int z = k % MOD;
// ans += k *(k + 1) / 2 % MOD *cnt2 % MOD - dif * k % MOD;
ans += k * (k - 1) / 2 % MOD * cnt2 % MOD + k * cnt % MOD; // AC
ans %= MOD;
}
cout << ans % MOD;
cout << endl;
return 0;
}
/*
テレビも無ェ ラジオも無ェ
自動車もそれほど走って無ェ
ピアノも無ェ バーも無ェ
巡査 毎日ぐーるぐる
朝起ぎで 牛連れで
二時間ちょっとの散歩道
電話も無ェ 瓦斯も無ェ
バスは一日一度来る
俺らこんな村いやだ 俺らこんな村いやだ
東京へ出るだ 東京へ出だなら
銭コァ貯めで 東京でベコ(牛)飼うだ
*/
|
[
"variable_declaration.type.change",
"assignment.add"
] | 731,632
| 731,634
|
u565624841
|
cpp
|
p02928
|
#include <bits/stdc++.h>
#include <cstdio>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
int main() {
int n, k;
cin >> n >> k;
int a[2010] = {};
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int cntl[2010] = {};
int cntr[2010] = {};
for (int i = 0; i < n; i++) {
for (int j = 0; j < i; j++) {
if (a[i] < a[j])
cntl[i]++;
}
for (int j = i + 1; j < n; j++) {
if (a[i] < a[j])
cntr[i]++;
}
}
ll ans = 0;
for (int i = 0; i < n; i++) {
ans = (ans + (ll)k * (2 * cntl[i]) / 2 % mod +
((ll)k * (ll)(k - 1)) % mod * (cntl[i] + cntr[i]) / 2 % mod) %
mod;
// ans = (ans + k%mod*(((k-1)%mod*(cntl[i]+cntrs[i]))/2+cntl[i])%mod) % mod;
// ans = (ans + (ll)k * cntl[i] % mod + ((ll)k*((ll)k-1)/2) % mod *
// (cntl[i]+cntr[i]))%mod; ans = (ans + (ll)k * cntl[i] % mod +
// ((ll)k*(ll)(k-1)/2) % mod * (cntl[i]+cntr[i]))%mod;
}
cout << ans << "\n";
}
|
#include <bits/stdc++.h>
#include <cstdio>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
int main() {
int n, k;
cin >> n >> k;
int a[2010] = {};
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int cntl[2010] = {};
int cntr[2010] = {};
for (int i = 0; i < n; i++) {
for (int j = 0; j < i; j++) {
if (a[i] < a[j])
cntl[i]++;
}
for (int j = i + 1; j < n; j++) {
if (a[i] < a[j])
cntr[i]++;
}
}
ll ans = 0;
for (int i = 0; i < n; i++) {
ans = (ans + (ll)k * (2 * cntl[i]) / 2 % mod +
((ll)k * (ll)(k - 1) / 2) % mod * (cntl[i] + cntr[i]) % mod) %
mod;
// ans = (ans + k%mod*(((k-1)%mod*(cntl[i]+cntrs[i]))/2+cntl[i])%mod) % mod;
// ans = (ans + (ll)k * cntl[i] % mod + ((ll)k*((ll)k-1)/2) % mod *
// (cntl[i]+cntr[i]))%mod; ans = (ans + (ll)k * cntl[i] % mod +
// ((ll)k*(ll)(k-1)/2) % mod * (cntl[i]+cntr[i]))%mod;
}
cout << ans << "\n";
}
|
[
"assignment.change",
"expression.operation.binary.remove"
] | 731,650
| 731,651
|
u108648546
|
cpp
|
p02928
|
#include <bits/stdc++.h>
#include <cstdio>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
int main() {
int n, k;
cin >> n >> k;
int a[2010] = {};
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int cntl[2010] = {};
int cntr[2010] = {};
for (int i = 0; i < n; i++) {
for (int j = 0; j < i; j++) {
if (a[i] < a[j])
cntl[i]++;
}
for (int j = i + 1; j < n; j++) {
if (a[i] < a[j])
cntr[i]++;
}
}
ll ans = 0;
for (int i = 0; i < n; i++) {
ans = (ans + (ll)k * (2 * cntl[i]) / 2 % mod +
(ll)k * (ll)(k - 1) % mod * (cntl[i] + cntr[i]) / 2 % mod) %
mod;
// ans = (ans + k%mod*(((k-1)%mod*(cntl[i]+cntrs[i]))/2+cntl[i])%mod) % mod;
// ans = (ans + (ll)k * cntl[i] % mod + ((ll)k*((ll)k-1)/2) % mod *
// (cntl[i]+cntr[i]))%mod; ans = (ans + (ll)k * cntl[i] % mod +
// ((ll)k*(ll)(k-1)/2) % mod * (cntl[i]+cntr[i]))%mod;
}
cout << ans << "\n";
}
|
#include <bits/stdc++.h>
#include <cstdio>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
int main() {
int n, k;
cin >> n >> k;
int a[2010] = {};
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int cntl[2010] = {};
int cntr[2010] = {};
for (int i = 0; i < n; i++) {
for (int j = 0; j < i; j++) {
if (a[i] < a[j])
cntl[i]++;
}
for (int j = i + 1; j < n; j++) {
if (a[i] < a[j])
cntr[i]++;
}
}
ll ans = 0;
for (int i = 0; i < n; i++) {
ans = (ans + (ll)k * (2 * cntl[i]) / 2 % mod +
((ll)k * (ll)(k - 1) / 2) % mod * (cntl[i] + cntr[i]) % mod) %
mod;
// ans = (ans + k%mod*(((k-1)%mod*(cntl[i]+cntrs[i]))/2+cntl[i])%mod) % mod;
// ans = (ans + (ll)k * cntl[i] % mod + ((ll)k*((ll)k-1)/2) % mod *
// (cntl[i]+cntr[i]))%mod; ans = (ans + (ll)k * cntl[i] % mod +
// ((ll)k*(ll)(k-1)/2) % mod * (cntl[i]+cntr[i]))%mod;
}
cout << ans << "\n";
}
|
[
"assignment.change",
"expression.operation.binary.remove"
] | 731,652
| 731,651
|
u108648546
|
cpp
|
p02928
|
#include <iostream>
using namespace std;
#define MOD 1000000007
int main() {
int N, f = 0, b = 0;
long long int K, ans = 0;
cin >> N >> K;
int A[N];
long long int x = K * (K - 1) % MOD, y = (K * (K - 1) + 2 * K) % MOD;
for (int i = 0; i < N; i++)
cin >> A[i];
for (int i = 0; i < N; i++) {
b = 0;
f = 0;
for (int j = 0; j < i; j++)
if (A[j] < A[i])
f++;
for (int j = i + 1; j < N; j++)
if (A[j] < A[i])
b++;
ans += f * x + b * y / 2;
ans %= MOD;
}
cout << ans << endl;
}
|
#include <iostream>
using namespace std;
#define MOD 1000000007
int main() {
int N, f = 0, b = 0;
long long int K, ans = 0;
cin >> N >> K;
int A[N];
long long int x = K * (K - 1) / 2 % MOD, y = (K * (K - 1) / 2 + K) % MOD;
for (int i = 0; i < N; i++)
cin >> A[i];
for (int i = 0; i < N; i++) {
b = 0;
f = 0;
for (int j = 0; j < i; j++)
if (A[j] < A[i])
f++;
for (int j = i + 1; j < N; j++)
if (A[j] < A[i])
b++;
ans += f * x + b * y;
ans %= MOD;
}
cout << ans << endl;
}
|
[
"expression.operator.arithmetic.change",
"expression.operation.binary.change",
"expression.operation.binary.remove"
] | 731,655
| 731,656
|
u310690147
|
cpp
|
p02928
|
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
int main() {
long long N, K;
cin >> N >> K;
vector<long long> a(N);
for (int i = 0; i < N; i++) {
cin >> a.at(i);
}
long long ans = 0;
for (int i = 0; i < N; i++) {
long long p = 0, q = 0;
for (int j = 0; j < N; j++) {
if (a.at(i) > a.at(j)) {
p += 1;
if (i < j) {
q += 1;
}
}
}
ans += ((q * K) % MOD + (p * (K * (K - 1) / 2) % MOD) % MOD) % MOD;
ans = ans % MOD;
}
cout << ans % MOD << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
int main() {
long long N, K;
cin >> N >> K;
vector<long long> a(N);
for (int i = 0; i < N; i++) {
cin >> a.at(i);
}
long long ans = 0;
for (int i = 0; i < N; i++) {
long long p = 0, q = 0;
for (int j = 0; j < N; j++) {
if (a.at(i) > a.at(j)) {
p += 1;
if (i < j) {
q += 1;
}
}
}
ans += ((q * K) % MOD + (p * ((K * (K - 1) / 2) % MOD)) % MOD) % MOD;
ans = ans % MOD;
}
cout << ans % MOD << endl;
}
|
[] | 731,668
| 731,669
|
u579355226
|
cpp
|
p02928
|
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
int main() {
long long N, K;
cin >> N >> K;
vector<long long> a(N);
for (int i = 0; i < N; i++) {
cin >> a.at(i);
}
long long ans = 0;
for (int i = 0; i < N; i++) {
long long p = 0, q = 0;
for (int j = 0; j < N; j++) {
if (a.at(i) > a.at(j)) {
p += 1;
if (i < j) {
q += 1;
}
}
}
ans += ((q * K) % MOD + (p * (K * (K - 1) / 2) % MOD) % MOD) % MOD;
ans = ans % MOD;
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
int main() {
long long N, K;
cin >> N >> K;
vector<long long> a(N);
for (int i = 0; i < N; i++) {
cin >> a.at(i);
}
long long ans = 0;
for (int i = 0; i < N; i++) {
long long p = 0, q = 0;
for (int j = 0; j < N; j++) {
if (a.at(i) > a.at(j)) {
p += 1;
if (i < j) {
q += 1;
}
}
}
ans += ((q * K) % MOD + (p * ((K * (K - 1) / 2) % MOD)) % MOD) % MOD;
ans = ans % MOD;
}
cout << ans % MOD << endl;
}
|
[
"expression.operation.binary.add"
] | 731,670
| 731,669
|
u579355226
|
cpp
|
p02928
|
#include <cstdio>
int N = 1000000007;
int main(void) {
int n;
long long k;
scanf("%d %lld", &n, &k);
int arr[n], arr1[n], arr2[n];
for (int i = 0; i < n; i++) {
scanf("%d", &arr[i]);
arr1[i] = 0, arr2[i] = 0;
}
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (arr[i] < arr[j]) {
arr2[j]++;
} else if (arr[i] > arr[j]) {
arr1[i]++, arr2[i]++;
}
}
}
long long answer = 0;
long long b = k * (k - 1) / 2;
for (int i = 0; i < n; i++) {
answer = (answer + k * arr1[i]) % N;
answer = (answer + b * arr2[i]) % N;
}
printf("%lld", answer);
}
|
#include <cstdio>
int N = 1000000007;
int main(void) {
int n;
long long k;
scanf("%d %lld", &n, &k);
int arr[n], arr1[n], arr2[n];
for (int i = 0; i < n; i++) {
scanf("%d", &arr[i]);
arr1[i] = 0, arr2[i] = 0;
}
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (arr[i] < arr[j]) {
arr2[j]++;
} else if (arr[i] > arr[j]) {
arr1[i]++, arr2[i]++;
}
}
}
long long answer = 0;
long long b = k * (k - 1) / 2 % N;
for (int i = 0; i < n; i++) {
answer = (answer + k * arr1[i]) % N;
answer = (answer + b * arr2[i]) % N;
}
printf("%lld", answer);
}
|
[
"assignment.change"
] | 731,671
| 731,672
|
u946105795
|
cpp
|
p02928
|
///**Bismillahir Rahmanir Rahim.**
#include <bits/stdc++.h>
#define clr(a, v) memset(a, v, sizeof a)
#define all(v) v.begin(), v.end()
#define ast(v) sort(v.begin(), v.end())
#define dst(v) sort(v.begin(), v.end(), greater<int>())
#define fast \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
#define ass(tmp, v) tmp.assign(v.begin(), v.end())
#define rep(i, l, r) for (int i = l; i < r; i++)
#define rep2(i, l, r) for (int i = l - 1; i >= r; i--)
#define sf(n) scanf("%d", &n)
#define sff(n, m) scanf("%d %d", &n, &m)
#define sfl(n) scanf("%lld", &n)
#define sfu(n) scanf("%llu", &n)
#define sffl(n, m) scanf("%lld %lld", &n, &m)
#define sfff(n, m, o) scanf("%d %d %d", &n, &m, &o)
#define pf(n) printf("%d", n)
#define sp printf(" ")
#define nl printf("\n")
#define prln(n) printf("%d\n", n)
#define pfl(n) printf("%lld", n)
#define pfu(n) printf("%llu", n)
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define S second
#define F first
#define PI 3.1415926
struct greaters {
bool operator()(const long &a, const long &b) const { return a > b; }
};
//-----------------------------------***********************----------------------------------------------//
typedef long long int ll;
typedef unsigned long long int ull;
using namespace std;
const int N = 2050;
const int mod = 1e9 + 7;
int main() {
// freopen("test.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
fast;
int tcase = 1, cas = 0;
while (tcase--) {
ll n, k;
cin >> n >> k;
int a[N];
rep(i, 1, n + 1) cin >> a[i];
ll ans = 0;
for (int i = 1; i <= n; i++) {
for (int j = i; j <= n; j++) {
if (a[i] > a[j])
ans += (1LL * (k * (k + 1)) / 2);
else if (a[i] < a[j])
ans += (1LL * (k * (k - 1)) / 2);
}
ans %= mod;
}
cout << ans;
/// printf("Case %d: %lld\n", ++cas, ans);
}
return 0;
}
//-----------------------------------***********************----------------------------------------------//
|
///**Bismillahir Rahmanir Rahim.**
#include <bits/stdc++.h>
#define clr(a, v) memset(a, v, sizeof a)
#define all(v) v.begin(), v.end()
#define ast(v) sort(v.begin(), v.end())
#define dst(v) sort(v.begin(), v.end(), greater<int>())
#define fast \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
#define ass(tmp, v) tmp.assign(v.begin(), v.end())
#define rep(i, l, r) for (int i = l; i < r; i++)
#define rep2(i, l, r) for (int i = l - 1; i >= r; i--)
#define sf(n) scanf("%d", &n)
#define sff(n, m) scanf("%d %d", &n, &m)
#define sfl(n) scanf("%lld", &n)
#define sfu(n) scanf("%llu", &n)
#define sffl(n, m) scanf("%lld %lld", &n, &m)
#define sfff(n, m, o) scanf("%d %d %d", &n, &m, &o)
#define pf(n) printf("%d", n)
#define sp printf(" ")
#define nl printf("\n")
#define prln(n) printf("%d\n", n)
#define pfl(n) printf("%lld", n)
#define pfu(n) printf("%llu", n)
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define S second
#define F first
#define PI 3.1415926
struct greaters {
bool operator()(const long &a, const long &b) const { return a > b; }
};
//-----------------------------------***********************----------------------------------------------//
typedef long long int ll;
typedef unsigned long long int ull;
using namespace std;
const int N = 2050;
const int mod = 1e9 + 7;
int main() {
// freopen("test.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
fast;
int tcase = 1, cas = 0;
while (tcase--) {
ll n, k;
cin >> n >> k;
int a[N];
rep(i, 1, n + 1) cin >> a[i];
ll ans = 0;
for (int i = 1; i <= n; i++) {
for (int j = i; j <= n; j++) {
if (a[i] > a[j])
ans += (1LL * (k * (k + 1)) / 2);
else if (a[i] < a[j])
ans += (1LL * (k * (k - 1)) / 2);
ans %= mod;
}
}
cout << ans;
/// printf("Case %d: %lld\n", ++cas, ans);
}
return 0;
}
//-----------------------------------***********************----------------------------------------------//
|
[] | 731,683
| 731,684
|
u912245812
|
cpp
|
p02928
|
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define REPr(i, n) for (int i = (n)-1; i >= 0; --i)
#define FORq(i, m, n) for (int i = (m); i <= (n); ++i)
#define FORqr(i, m, n) for (int i = (n); i >= (m); --i)
#define PB push_back
#define MP make_pair
#define DEBUG printf("%s\n", "debug")
#define fst first
#define snd second
#define SIN(x, S) (S.count(x) != 0)
#define M0(x) memset(x, 0, sizeof(x))
#define FILL(x, y) memset(x, y, sizeof(x))
#define MM(x) memset(x, -1, sizeof(x))
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
/* (๑╹◡╹) */
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll MOD = 1000000007;
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
/* (๑╹◡╹)(๑╹◡╹)(๑╹◡╹)*/
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
/* (๑╹◡╹)(๑╹◡╹)(๑╹◡╹)(๑╹◡╹)(๑╹◡╹)(๑╹◡╹) */
///////////////////////////////////////////////
const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 二項係数計算
long long COM(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main() {
ll N, K;
cin >> N >> K;
ll MOD = 1000000007;
vector<ll> A;
for (int i = 0; i < N; i++) {
ll a;
cin >> a;
A.PB(a);
}
ll c = 0; // Aの中での転倒数
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
if (j > i and A[i] > A[j]) {
c++;
c = c % MOD;
}
}
}
ll d = 0; // Aの外での転倒数
for (int i = 0; i < N - 1; i++) {
for (int j = 0; j < N; j++) {
if (A[i] > A[j] and i != j) {
d++;
d = d % MOD;
}
}
}
K = K % MOD;
ll ans = (K * c) % MOD + ((d % MOD) * (((K * (K - 1)) / 2) % MOD) % MOD);
ans = ans % MOD;
cout << ans << endl;
}
|
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define REPr(i, n) for (int i = (n)-1; i >= 0; --i)
#define FORq(i, m, n) for (int i = (m); i <= (n); ++i)
#define FORqr(i, m, n) for (int i = (n); i >= (m); --i)
#define PB push_back
#define MP make_pair
#define DEBUG printf("%s\n", "debug")
#define fst first
#define snd second
#define SIN(x, S) (S.count(x) != 0)
#define M0(x) memset(x, 0, sizeof(x))
#define FILL(x, y) memset(x, y, sizeof(x))
#define MM(x) memset(x, -1, sizeof(x))
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
/* (๑╹◡╹) */
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll MOD = 1000000007;
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
/* (๑╹◡╹)(๑╹◡╹)(๑╹◡╹)*/
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
/* (๑╹◡╹)(๑╹◡╹)(๑╹◡╹)(๑╹◡╹)(๑╹◡╹)(๑╹◡╹) */
///////////////////////////////////////////////
const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 二項係数計算
long long COM(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main() {
ll N, K;
cin >> N >> K;
ll MOD = 1000000007;
vector<ll> A;
for (int i = 0; i < N; i++) {
ll a;
cin >> a;
A.PB(a);
}
ll c = 0; // Aの中での転倒数
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
if (j > i and A[i] > A[j]) {
c++;
c = c % MOD;
}
}
}
ll d = 0; // Aの外での転倒数
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
if (A[i] > A[j] and i != j) {
d++;
d = d % MOD;
}
}
}
K = K % MOD;
ll ans = (K * c) % MOD + ((d % MOD) * (((K * (K - 1)) / 2) % MOD) % MOD);
ans = ans % MOD;
cout << ans << endl;
}
|
[
"control_flow.loop.for.condition.change",
"expression.operation.binary.remove"
] | 731,689
| 731,690
|
u236433947
|
cpp
|
p02928
|
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define REPr(i, n) for (int i = (n)-1; i >= 0; --i)
#define FORq(i, m, n) for (int i = (m); i <= (n); ++i)
#define FORqr(i, m, n) for (int i = (n); i >= (m); --i)
#define PB push_back
#define MP make_pair
#define DEBUG printf("%s\n", "debug")
#define fst first
#define snd second
#define SIN(x, S) (S.count(x) != 0)
#define M0(x) memset(x, 0, sizeof(x))
#define FILL(x, y) memset(x, y, sizeof(x))
#define MM(x) memset(x, -1, sizeof(x))
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
/* (๑╹◡╹) */
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll MOD = 1000000007;
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
/* (๑╹◡╹)(๑╹◡╹)(๑╹◡╹)*/
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
/* (๑╹◡╹)(๑╹◡╹)(๑╹◡╹)(๑╹◡╹)(๑╹◡╹)(๑╹◡╹) */
///////////////////////////////////////////////
const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 二項係数計算
long long COM(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main() {
ll N, K;
cin >> N >> K;
ll MOD = 1000000007;
vector<ll> A;
for (int i = 0; i < N; i++) {
ll a;
cin >> a;
A.PB(a);
}
ll c = 0; // Aの中での転倒数
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
if (j > i and A[i] > A[j]) {
c++;
c = c % MOD;
}
}
}
ll d = 0; // Aの外での転倒数
for (int i = 0; i < N - 1; i++) {
for (int j = 0; j < N; j++) {
if (A[i] > A[j] and i != j) {
d++;
d = d % MOD;
}
}
}
K = K % MOD;
ll ans = (K * c) % MOD + ((d % MOD) * (((K * (K - 1)) / 2)) % MOD);
ans = ans % MOD;
cout << ans << endl;
}
|
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define REPr(i, n) for (int i = (n)-1; i >= 0; --i)
#define FORq(i, m, n) for (int i = (m); i <= (n); ++i)
#define FORqr(i, m, n) for (int i = (n); i >= (m); --i)
#define PB push_back
#define MP make_pair
#define DEBUG printf("%s\n", "debug")
#define fst first
#define snd second
#define SIN(x, S) (S.count(x) != 0)
#define M0(x) memset(x, 0, sizeof(x))
#define FILL(x, y) memset(x, y, sizeof(x))
#define MM(x) memset(x, -1, sizeof(x))
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
/* (๑╹◡╹) */
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll MOD = 1000000007;
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
/* (๑╹◡╹)(๑╹◡╹)(๑╹◡╹)*/
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
/* (๑╹◡╹)(๑╹◡╹)(๑╹◡╹)(๑╹◡╹)(๑╹◡╹)(๑╹◡╹) */
///////////////////////////////////////////////
const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 二項係数計算
long long COM(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main() {
ll N, K;
cin >> N >> K;
ll MOD = 1000000007;
vector<ll> A;
for (int i = 0; i < N; i++) {
ll a;
cin >> a;
A.PB(a);
}
ll c = 0; // Aの中での転倒数
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
if (j > i and A[i] > A[j]) {
c++;
c = c % MOD;
}
}
}
ll d = 0; // Aの外での転倒数
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
if (A[i] > A[j] and i != j) {
d++;
d = d % MOD;
}
}
}
K = K % MOD;
ll ans = (K * c) % MOD + ((d % MOD) * (((K * (K - 1)) / 2) % MOD) % MOD);
ans = ans % MOD;
cout << ans << endl;
}
|
[
"control_flow.loop.for.condition.change",
"expression.operation.binary.remove"
] | 731,691
| 731,690
|
u236433947
|
cpp
|
p02928
|
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define REPr(i, n) for (int i = (n)-1; i >= 0; --i)
#define FORq(i, m, n) for (int i = (m); i <= (n); ++i)
#define FORqr(i, m, n) for (int i = (n); i >= (m); --i)
#define PB push_back
#define MP make_pair
#define DEBUG printf("%s\n", "debug")
#define fst first
#define snd second
#define SIN(x, S) (S.count(x) != 0)
#define M0(x) memset(x, 0, sizeof(x))
#define FILL(x, y) memset(x, y, sizeof(x))
#define MM(x) memset(x, -1, sizeof(x))
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
/* (๑╹◡╹) */
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll MOD = 1000000007;
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
/* (๑╹◡╹)(๑╹◡╹)(๑╹◡╹)*/
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
/* (๑╹◡╹)(๑╹◡╹)(๑╹◡╹)(๑╹◡╹)(๑╹◡╹)(๑╹◡╹) */
///////////////////////////////////////////////
const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 二項係数計算
long long COM(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main() {
ll N, K;
cin >> N >> K;
vector<ll> A;
for (int i = 0; i < N; i++) {
ll a;
cin >> a;
A.PB(a);
}
ll c = 0; // Aの中での転倒数
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
if (j > i and A[i] > A[j]) {
c++;
c = c % MOD;
}
}
}
ll d = 0; // Aの外での転倒数
for (int i = 0; i < N - 1; i++) {
for (int j = 0; j < N; j++) {
if (A[i] > A[j] and i != j) {
d++;
d = d % MOD;
}
}
}
K = K % MOD;
ll ans = (K * c) % MOD + (d % MOD) * (((K * (K - 1)) / 2) % MOD);
ans = ans % MOD;
cout << ans << endl;
}
|
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define REPr(i, n) for (int i = (n)-1; i >= 0; --i)
#define FORq(i, m, n) for (int i = (m); i <= (n); ++i)
#define FORqr(i, m, n) for (int i = (n); i >= (m); --i)
#define PB push_back
#define MP make_pair
#define DEBUG printf("%s\n", "debug")
#define fst first
#define snd second
#define SIN(x, S) (S.count(x) != 0)
#define M0(x) memset(x, 0, sizeof(x))
#define FILL(x, y) memset(x, y, sizeof(x))
#define MM(x) memset(x, -1, sizeof(x))
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
/* (๑╹◡╹) */
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll MOD = 1000000007;
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
/* (๑╹◡╹)(๑╹◡╹)(๑╹◡╹)*/
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
/* (๑╹◡╹)(๑╹◡╹)(๑╹◡╹)(๑╹◡╹)(๑╹◡╹)(๑╹◡╹) */
///////////////////////////////////////////////
const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 二項係数計算
long long COM(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main() {
ll N, K;
cin >> N >> K;
vector<ll> A;
for (int i = 0; i < N; i++) {
ll a;
cin >> a;
A.PB(a);
}
ll c = 0; // Aの中での転倒数
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
if (j > i and A[i] > A[j]) {
c++;
c = c % MOD;
}
}
}
ll d = 0; // Aの外での転倒数
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
if (A[i] > A[j] and i != j) {
d++;
d = d % MOD;
}
}
}
K = K % MOD;
ll ans = (K * c) % MOD + (d % MOD) * (((K * (K - 1)) / 2) % MOD);
ans = ans % MOD;
cout << ans << endl;
}
|
[
"control_flow.loop.for.condition.change",
"expression.operation.binary.remove"
] | 731,694
| 731,695
|
u532894762
|
cpp
|
p02928
|
#include <algorithm>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <sstream>
#include <stdio.h>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
#define MOD (long long int)(1e9 + 7)
#define ll long long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n) for (int i = 1; i <= (int)(n); i++)
#define REP(i, n) for (int i = n - 1; i >= 0; i--)
#define REPS(i, n) for (int i = n; i > 0; i--)
#define FOR(i, a, b) for (int i = a; i < (int)(b); i++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0, sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const double PI = acos(-1.0);
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
std::fill((T *)array, (T *)(array + N), val);
}
__attribute__((constructor)) void initial() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
}
signed main() {
ll n, k;
cin >> n >> k;
vector<ll> a(n);
rep(i, n) cin >> a[i];
// 数列Aの中で、各項の転倒数がいくつあるかを考える
vector<vector<ll>> cnt;
rep(i, n) {
vector<ll> c;
c.PB(0);
c.PB(0);
cnt.PB(c);
}
rep(i, n) {
for (int j = i; j < n; j++) {
if (a[i] > a[j])
cnt[i][0]++; // A内の転倒数の数
}
}
rep(i, n) {
rep(j, n) {
if (a[i] > a[j])
cnt[i][1]++; // A内に自分より小さい数が何個
}
}
ll ans = 0;
rep(i, n) {
ans += (cnt[i][0] * k) % MOD;
ans %= MOD;
}
rep(i, n) {
ll p = (k * (k - 1)) % MOD;
ans += (p * cnt[i][1] / 2) % MOD;
ans %= MOD;
}
cout << ans % MOD << endl;
return 0;
}
|
#include <algorithm>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <sstream>
#include <stdio.h>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
#define MOD (long long int)(1e9 + 7)
#define ll long long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n) for (int i = 1; i <= (int)(n); i++)
#define REP(i, n) for (int i = n - 1; i >= 0; i--)
#define REPS(i, n) for (int i = n; i > 0; i--)
#define FOR(i, a, b) for (int i = a; i < (int)(b); i++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0, sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const double PI = acos(-1.0);
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
std::fill((T *)array, (T *)(array + N), val);
}
__attribute__((constructor)) void initial() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
}
signed main() {
ll n, k;
cin >> n >> k;
vector<ll> a(n);
rep(i, n) cin >> a[i];
// 数列Aの中で、各項の転倒数がいくつあるかを考える
vector<vector<ll>> cnt;
rep(i, n) {
vector<ll> c;
c.PB(0);
c.PB(0);
cnt.PB(c);
}
rep(i, n) {
for (int j = i; j < n; j++) {
if (a[i] > a[j])
cnt[i][0]++; // A内の転倒数の数
}
}
rep(i, n) {
rep(j, n) {
if (a[i] > a[j])
cnt[i][1]++; // A内に自分より小さい数が何個
}
}
ll ans = 0;
rep(i, n) {
ans += (cnt[i][0] * k) % MOD;
ans %= MOD;
}
rep(i, n) {
ll p = (k * (k - 1) / 2) % MOD;
ans += (p * cnt[i][1]) % MOD;
ans %= MOD;
}
cout << ans << endl;
return 0;
}
|
[
"expression.operation.binary.remove"
] | 731,711
| 731,712
|
u050698451
|
cpp
|
p02928
|
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define Rep(i, sta, n) for (int i = sta; i < n; ++i)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
int main() {
int n, k;
cin >> n >> k;
int a[n];
rep(i, n) cin >> a[i];
ll ans = 0;
rep(i, n) {
Rep(j, i + 1, n) {
if (a[i] < a[j]) {
ans += k * (k - 1) / 2;
ans %= mod;
}
if (a[i] > a[j]) {
ans += (k + 1) * k / 2;
ans %= mod;
}
}
}
cout << ans << endl;
return 0;
}
|
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define Rep(i, sta, n) for (int i = sta; i < n; ++i)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
int main() {
int n;
ll k;
cin >> n >> k;
int a[n];
rep(i, n) cin >> a[i];
ll ans = 0;
rep(i, n) {
Rep(j, i + 1, n) {
if (a[i] < a[j]) {
ans += k * (k - 1) / 2;
ans %= mod;
}
if (a[i] > a[j]) {
ans += (k + 1) * k / 2;
ans %= mod;
}
}
}
cout << ans << endl;
return 0;
}
|
[] | 731,733
| 731,734
|
u655777757
|
cpp
|
p02928
|
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define double long double
#define low lower_bound
#define upp upper_bound
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define Rep(i, n) for (int i = (int)(n); i >= 0; i--)
#define all(vec) vec.begin(), vec.end()
#define rever(vec) reverse(all(vec));
#define cend cout << endl;
#define prique(T) priority_queue<T, vector<T>, greater<T>>
#define prique2(T) priority_queue<T>
struct edge {
int to, cost;
};
using P = pair<int, int>;
using PP = pair<P, int>;
const int mod2 = 998244353;
const int mod = (int)1e9 + 7, inf = (int)1e16;
int modpow(int x, int n) {
int ans = 1;
while (n > 0) {
if (n & 1) {
ans *= x;
if (mod <= ans)
ans %= mod;
}
x *= x;
if (mod <= x)
x %= mod;
n >>= 1;
}
return ans;
}
int fact[114514];
void f_init(int n) {
fact[0] = fact[1] = 1;
for (int i = 2; i <= n; ++i) {
fact[i] *= fact[i - 1];
if (mod <= fact[i])
fact[i] %= mod;
}
return;
}
int comb(int n, int r) {
if (n < r)
return 0;
int ans =
fact[n] * modpow(fact[n - r], mod - 2) % mod * modpow(fact[r], mod - 2);
if (ans < 0)
return ans + mod;
return ans;
}
int perm(int n, int r) {
if (n < r)
return 0;
if (n - r < r)
r = n - r;
int ans = fact[n] * modpow(fact[n - r], mod - 2) % mod;
if (ans < 0)
return ans + mod;
return ans;
}
int gcd(int a, int b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
int lcm(int a, int b) { return a * b / gcd(a, b); }
bool pri(int p) {
for (int i = 2; i * i <= p; ++i)
if (p % i == 0)
return false;
return p > 1;
}
map<int, int> factring(int n) {
map<int, int> ans;
for (int i = 2; i * i <= n; ++i) {
while (n % i == 0) {
n /= i;
++ans[i];
}
}
if (n != 1)
++ans[n];
return ans;
}
P operator+(const P &a, const P &b) {
return P(a.first + b.first, a.second + b.second);
}
P operator-(const P &a, const P &b) {
return P(a.first - b.first, a.second - b.second);
}
int n, k;
int a[2222];
int ans;
signed main() {
cin >> n >> k;
rep(i, n) { cin >> a[i]; }
rep(i, n) {
int cnt = 0, cnt1 = 0;
for (int j = i + 1; j < n; j++) {
if (a[i] > a[j])
cnt++;
}
rep(j, n) {
if (i != j)
if (a[i] > a[j])
cnt1++;
}
ans += k * cnt % mod + k * (k - 1) / 2 * cnt1 % mod;
ans %= mod;
}
cout << ans << endl;
}
|
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define double long double
#define low lower_bound
#define upp upper_bound
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define Rep(i, n) for (int i = (int)(n); i >= 0; i--)
#define all(vec) vec.begin(), vec.end()
#define rever(vec) reverse(all(vec));
#define cend cout << endl;
#define prique(T) priority_queue<T, vector<T>, greater<T>>
#define prique2(T) priority_queue<T>
struct edge {
int to, cost;
};
using P = pair<int, int>;
using PP = pair<P, int>;
const int mod2 = 998244353;
const int mod = (int)1e9 + 7, inf = (int)1e16;
int modpow(int x, int n) {
int ans = 1;
while (n > 0) {
if (n & 1) {
ans *= x;
if (mod <= ans)
ans %= mod;
}
x *= x;
if (mod <= x)
x %= mod;
n >>= 1;
}
return ans;
}
int fact[114514];
void f_init(int n) {
fact[0] = fact[1] = 1;
for (int i = 2; i <= n; ++i) {
fact[i] *= fact[i - 1];
if (mod <= fact[i])
fact[i] %= mod;
}
return;
}
int comb(int n, int r) {
if (n < r)
return 0;
int ans =
fact[n] * modpow(fact[n - r], mod - 2) % mod * modpow(fact[r], mod - 2);
if (ans < 0)
return ans + mod;
return ans;
}
int perm(int n, int r) {
if (n < r)
return 0;
if (n - r < r)
r = n - r;
int ans = fact[n] * modpow(fact[n - r], mod - 2) % mod;
if (ans < 0)
return ans + mod;
return ans;
}
int gcd(int a, int b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
int lcm(int a, int b) { return a * b / gcd(a, b); }
bool pri(int p) {
for (int i = 2; i * i <= p; ++i)
if (p % i == 0)
return false;
return p > 1;
}
map<int, int> factring(int n) {
map<int, int> ans;
for (int i = 2; i * i <= n; ++i) {
while (n % i == 0) {
n /= i;
++ans[i];
}
}
if (n != 1)
++ans[n];
return ans;
}
P operator+(const P &a, const P &b) {
return P(a.first + b.first, a.second + b.second);
}
P operator-(const P &a, const P &b) {
return P(a.first - b.first, a.second - b.second);
}
int n, k;
int a[2222];
int ans;
signed main() {
cin >> n >> k;
rep(i, n) { cin >> a[i]; }
rep(i, n) {
int cnt = 0, cnt1 = 0;
for (int j = i + 1; j < n; j++) {
if (a[i] > a[j])
cnt++;
}
rep(j, n) {
if (i != j)
if (a[i] > a[j])
cnt1++;
}
ans += k * cnt % mod + k * (k - 1) / 2 % mod * cnt1 % mod;
ans %= mod;
}
cout << ans << endl;
}
|
[
"assignment.change"
] | 731,745
| 731,746
|
u054475353
|
cpp
|
p02928
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF (ll)1000000007
int main() {
int N;
ll K;
cin >> N >> K;
int A[N];
for (int i = 0; i < N; i++) {
cin >> A[i];
}
ll c = 0; // i桁目の数字よりも大きい数の総数(1≦i≦N)
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
if (i != j) {
if (A[j] > A[i]) {
c++;
c %= INF;
}
}
}
}
ll count = 0; //(0≤i<j≤N−1)であって A[i]>A[j]のものの数の総数
for (int i = N - 1; i >= 0; i--) {
for (int j = i - 1; j >= 0; j--) {
if (A[j] > A[i]) {
count++;
count %= INF;
}
}
}
ll ans = 0;
ll k = K;
K = K * (K - 1) % INF / 2;
ans = k * count % INF + K * c % INF;
cout << ans % INF << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF (ll)1000000007
int main() {
int N;
ll K;
cin >> N >> K;
int A[N];
for (int i = 0; i < N; i++) {
cin >> A[i];
}
ll c = 0; // i桁目の数字よりも大きい数の総数(1≦i≦N)
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
if (i != j) {
if (A[j] > A[i]) {
c++;
c %= INF;
}
}
}
}
ll count = 0; //(0≤i<j≤N−1)であって A[i]>A[j]のものの数の総数
for (int i = N - 1; i >= 0; i--) {
for (int j = i - 1; j >= 0; j--) {
if (A[j] > A[i]) {
count++;
count %= INF;
}
}
}
ll ans = 0;
ll k = K;
K = K * (K - 1) / 2 % INF;
ans = k * count % INF + K * c % INF;
cout << ans % INF << endl;
}
|
[
"expression.operation.binary.remove",
"assignment.change"
] | 731,749
| 731,750
|
u568545273
|
cpp
|
p02928
|
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdio>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
#define rep(i, x) for (int i = 0; i < x; i++)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
const ll N = 1e9 + 7;
const int n_max = 1e5 + 10;
void print() { cout << endl; }
template <class Head, class... Tail> void print(Head &&head, Tail &&...tail) {
cout << head;
if (sizeof...(tail) != 0)
cout << ' ';
print(forward<Tail>(tail)...);
}
template <class T> void print(vector<T> &vec) {
for (auto &a : vec) {
cout << a;
if (&a != &vec.back())
cout << ' ';
}
cout << endl;
}
template <class T> void print(vector<vector<T>> &df) {
for (auto &vec : df) {
print(vec);
}
}
int main() {
ll n, k;
cin >> n >> k;
vector<ll> a(n), abig(n, 0), afront(n, 0);
rep(i, n) cin >> a[i];
rep(i, n) {
rep(j, n) {
if (i == j)
continue;
if (a[i] < a[j]) {
if (j < i) {
afront[i]++;
abig[i]++;
} else
abig[i]++;
}
}
}
// print(abig);
// print(afront);
ll abig_sum = 0;
ll afront_sum = 0;
abig_sum = accumulate(abig.begin(), abig.end(), 0) % N;
afront_sum = accumulate(afront.begin(), afront.end(), 0) % N;
ll ks = (k * (k - 1) % N) / 2;
cout << (((ks * abig_sum) % N) + ((afront_sum * k) % N)) % N << endl;
return 0;
}
|
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdio>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
#define rep(i, x) for (int i = 0; i < x; i++)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
const ll N = 1e9 + 7;
const int n_max = 1e5 + 10;
void print() { cout << endl; }
template <class Head, class... Tail> void print(Head &&head, Tail &&...tail) {
cout << head;
if (sizeof...(tail) != 0)
cout << ' ';
print(forward<Tail>(tail)...);
}
template <class T> void print(vector<T> &vec) {
for (auto &a : vec) {
cout << a;
if (&a != &vec.back())
cout << ' ';
}
cout << endl;
}
template <class T> void print(vector<vector<T>> &df) {
for (auto &vec : df) {
print(vec);
}
}
int main() {
ll n, k;
cin >> n >> k;
vector<ll> a(n), abig(n, 0), afront(n, 0);
rep(i, n) cin >> a[i];
rep(i, n) {
rep(j, n) {
if (i == j)
continue;
if (a[i] < a[j]) {
if (j < i) {
afront[i]++;
abig[i]++;
} else
abig[i]++;
}
}
}
// print(abig);
// print(afront);
ll abig_sum = 0;
ll afront_sum = 0;
abig_sum = accumulate(abig.begin(), abig.end(), 0) % N;
afront_sum = accumulate(afront.begin(), afront.end(), 0) % N;
ll ks = (k * (k - 1) / 2) % N;
cout << (((ks * abig_sum) % N) + ((afront_sum * k) % N)) % N << endl;
return 0;
}
|
[
"assignment.change"
] | 731,769
| 731,770
|
u899645116
|
cpp
|
p02928
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, k;
long long int a[2001];
long long int cnt = 0;
long long int cnt2 = 0;
long long int MOD = 1000000007;
cin >> n >> k;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (a[i] > a[j]) {
cnt++;
if (cnt >= MOD) {
cnt = cnt % MOD;
}
}
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (a[i] > a[j]) {
cnt2++;
if (cnt2 >= MOD) {
cnt2 = cnt2 % MOD;
}
}
}
}
long long int kkk;
kkk = (0.5 * (k - 1) * (k));
kkk = kkk % MOD;
cnt = cnt % MOD;
cnt2 = cnt2 % MOD;
long long int ans;
// cout<< cnt * k%MOD<<" "<<cnt2 * kkk%MOD<<endl;
ans = (cnt * k % MOD + cnt2 * kkk % MOD) % MOD;
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, k;
long long int a[2001];
long long int cnt = 0;
long long int cnt2 = 0;
long long int MOD = 1000000007;
cin >> n >> k;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (a[i] > a[j]) {
cnt++;
if (cnt >= MOD) {
cnt = cnt % MOD;
}
}
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (a[i] > a[j]) {
cnt2++;
if (cnt2 >= MOD) {
cnt2 = cnt2 % MOD;
}
}
}
}
long long int kkk;
kkk = ((k - 1) * (k)) / 2;
kkk = kkk % MOD;
cnt = cnt % MOD;
cnt2 = cnt2 % MOD;
long long int ans;
// cout<< cnt * k%MOD<<" "<<cnt2 * kkk%MOD<<endl;
ans = (cnt * k % MOD + cnt2 * kkk % MOD) % MOD;
cout << ans << endl;
return 0;
}
|
[
"expression.operation.binary.remove",
"assignment.change"
] | 731,780
| 731,781
|
u681005393
|
cpp
|
p02928
|
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0, i##_limit = (n); i < i##_limit; ++i)
#define FOR(i, a, b) for (int i = (a), i##_limit = (b); i < i##_limit; ++i)
#define pb push_back
#define mp make_pair
using namespace std;
using ll = long long;
using pi = pair<int, int>;
#define MOD 1000000007
ll modinv(ll a, ll m) {
ll b = m, u = 1, v = 0;
while (b) {
ll t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
u %= m;
if (u < 0)
u += m;
return u;
}
int main() {
ll N, K;
cin >> N >> K;
ll A[N];
REP(i, N) cin >> A[i];
ll ret0 = 0;
ll ret1 = 0;
REP(i, N - 1) FOR(j, i + 1, N) if (A[i] > A[j])++ ret0;
REP(i, N - 1) REP(j, N) if (i != j && A[i] > A[j])++ ret1;
ll ret = K * ret0 % MOD;
ret += K * (K - 1) / 2 % MOD * ret1 % MOD;
ret %= MOD;
cout << ret << endl;
return 0;
}
|
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0, i##_limit = (n); i < i##_limit; ++i)
#define FOR(i, a, b) for (int i = (a), i##_limit = (b); i < i##_limit; ++i)
#define pb push_back
#define mp make_pair
using namespace std;
using ll = long long;
using pi = pair<int, int>;
#define MOD 1000000007
ll modinv(ll a, ll m) {
ll b = m, u = 1, v = 0;
while (b) {
ll t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
u %= m;
if (u < 0)
u += m;
return u;
}
int main() {
ll N, K;
cin >> N >> K;
ll A[N];
REP(i, N) cin >> A[i];
ll ret0 = 0;
ll ret1 = 0;
REP(i, N - 1) FOR(j, i + 1, N) if (A[i] > A[j])++ ret0;
REP(i, N) REP(j, N) if (i != j && A[i] > A[j])++ ret1;
ll ret = K * ret0 % MOD;
ret += K * (K - 1) / 2 % MOD * ret1 % MOD;
ret %= MOD;
cout << ret << endl;
return 0;
}
|
[
"expression.operation.binary.remove"
] | 731,782
| 731,783
|
u986334889
|
cpp
|
p02928
|
#include <iostream>
#include <unordered_map>
using namespace std;
int A[2000];
int MOD = 1000000007;
int main() {
int N, K;
cin >> N >> K;
for (int i = 0; i < N; ++i) {
cin >> A[i];
}
int t = 0;
for (int i = N - 1; i >= 0; --i) {
for (int j = 0; j < i; ++j) {
if (A[j] > A[j + 1]) {
int tmp = A[j];
A[j] = A[j + 1];
A[j + 1] = tmp;
++t;
}
}
}
unordered_map<int, int> m;
for (int i = 0; i < N; ++i) {
m.emplace(A[i], i);
}
long long T = 0;
for (int i = 0; i < N; ++i) {
T += m[A[i]];
}
long long KK = K * (K - 1) / 2 % MOD;
long long ans = (T * KK) % MOD + ((long long)t * K) % MOD;
ans %= MOD;
cout << ans << endl;
return 0;
}
|
#include <iostream>
#include <unordered_map>
using namespace std;
int A[2000];
int MOD = 1000000007;
int main() {
int N, K;
cin >> N >> K;
for (int i = 0; i < N; ++i) {
cin >> A[i];
}
int t = 0;
for (int i = N - 1; i >= 0; --i) {
for (int j = 0; j < i; ++j) {
if (A[j] > A[j + 1]) {
int tmp = A[j];
A[j] = A[j + 1];
A[j + 1] = tmp;
++t;
}
}
}
unordered_map<int, int> m;
for (int i = 0; i < N; ++i) {
m.emplace(A[i], i);
}
long long T = 0;
for (int i = 0; i < N; ++i) {
T += m[A[i]];
}
long long KK = (long long)K * (K - 1) / 2 % MOD;
long long ans = (T * KK) % MOD + ((long long)t * K) % MOD;
ans %= MOD;
cout << ans << endl;
return 0;
}
|
[
"type_conversion.add"
] | 731,784
| 731,785
|
u673928159
|
cpp
|
p02928
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1000000000 + 7;
int main(void) {
ll N, K;
cin >> N >> K;
vector<int> A(N);
for (int i = 0; i < N; i++) {
cin >> A[i];
}
ll c1;
ll c2;
ll count = 0;
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
if (A[i] > A[j]) {
if (i < j) {
c1++;
}
c2++;
}
}
c1 %= mod;
c2 %= mod;
}
count += c1 * K % mod;
count %= mod;
count += c2 * (((K * K - K) / 2) % mod) % mod;
count %= mod;
cout << count << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1000000000 + 7;
int main(void) {
ll N, K;
cin >> N >> K;
vector<int> A(N);
for (int i = 0; i < N; i++) {
cin >> A[i];
}
ll c1 = 0;
ll c2 = 0;
ll count = 0;
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
if (A[i] > A[j]) {
if (i < j) {
c1++;
}
c2++;
}
}
c1 %= mod;
c2 %= mod;
}
count += c1 * K % mod;
count %= mod;
count += c2 * (((K * K - K) / 2) % mod) % mod;
count %= mod;
cout << count << endl;
return 0;
}
|
[
"variable_declaration.value.change"
] | 731,789
| 731,790
|
u010725318
|
cpp
|
p02928
|
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>
using namespace std;
const int64_t R = 1e9 + 7;
#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)
int64_t a[2'000];
int64_t b[2'000];
int64_t c[2'000];
int main() {
int64_t n, k;
cin >> n >> k;
rep(i, n) { cin >> a[i]; }
rep(i, n - 1) {
b[i] = 0;
for (int j = i + 1; j < n; j++) {
if (a[i] > a[j]) {
b[i]++;
}
}
c[i] = 0;
rep(j, n) {
if (a[i] > a[j]) {
c[i]++;
}
}
}
int64_t bsum = 0;
int64_t csum = 0;
rep(i, n) {
bsum = (bsum + b[i]) % R;
csum = (csum + c[i]) % R;
}
int64_t kk = k * (k - 1) / 2 % R;
int64_t result = (k * bsum % R + kk * csum % R) % R;
cout << result << endl;
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>
using namespace std;
const int64_t R = 1e9 + 7;
#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)
int64_t a[2'000];
int64_t b[2'000];
int64_t c[2'000];
int main() {
int64_t n, k;
cin >> n >> k;
rep(i, n) { cin >> a[i]; }
rep(i, n) {
b[i] = 0;
for (int j = i + 1; j < n; j++) {
if (a[i] > a[j]) {
b[i]++;
}
}
c[i] = 0;
rep(j, n) {
if (a[i] > a[j]) {
c[i]++;
}
}
}
int64_t bsum = 0;
int64_t csum = 0;
rep(i, n) {
bsum = (bsum + b[i]) % R;
csum = (csum + c[i]) % R;
}
int64_t kk = k * (k - 1) / 2 % R;
int64_t result = (k * bsum % R + kk * csum % R) % R;
cout << result << endl;
return 0;
}
|
[
"expression.operation.binary.remove"
] | 731,796
| 731,797
|
u395676079
|
cpp
|
p02928
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int N, K;
long long int mod = 1e9 + 7;
cin >> N >> K;
long long int A[N];
for (int i = 0; i < N; i++) {
cin >> A[i];
// cout << A[i] << endl;
}
long long int A1[N], A2[N];
for (int i = 0; i < N - 1; i++) {
long long int count = 0;
for (int j = i + 1; j < N; j++) {
if (A[i] > A[j]) {
count++;
}
}
A1[i] = count;
// cout << count << endl;
}
A1[N - 1] = 0;
for (int i = 0; i < N; i++) {
long long int count = 0;
for (int j = 0; j < N; j++) {
if (A[i] > A[j] && i != j) {
count++;
// cout << i << j << A[i] << A[j] << endl;
}
}
A2[i] = count;
// cout << count << endl;
}
long long int ans = 0, ans1 = 0, ans2 = 0;
for (int i = 0; i < N; i++) {
ans1 += A1[i] * K;
ans1 = ans1 % mod;
}
for (int i = 0; i < N; i++) {
ans2 += A2[i] * (K - 1) * K / 2;
ans2 = ans2 % mod;
}
ans = ans1 + ans2;
ans = ans % mod;
cout << ans; //<< ' '<<ans1<<' '<<ans2<< endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int N, K;
long long int mod = 1e9 + 7;
cin >> N >> K;
long long int A[N];
for (int i = 0; i < N; i++) {
cin >> A[i];
// cout << A[i] << endl;
}
long long int A1[N], A2[N];
for (int i = 0; i < N - 1; i++) {
long long int count = 0;
for (int j = i + 1; j < N; j++) {
if (A[i] > A[j]) {
count++;
}
}
A1[i] = count;
// cout << count << endl;
}
A1[N - 1] = 0;
for (int i = 0; i < N; i++) {
long long int count = 0;
for (int j = 0; j < N; j++) {
if (A[i] > A[j] && i != j) {
count++;
// cout << i << j << A[i] << A[j] << endl;
}
}
A2[i] = count;
// cout << count << endl;
}
long long int ans = 0, ans1 = 0, ans2 = 0;
for (int i = 0; i < N; i++) {
ans1 += A1[i] * K;
ans1 = ans1 % mod;
}
for (int i = 0; i < N; i++) {
ans2 += A2[i] * (((K - 1) * K / 2) % mod);
ans2 = ans2 % mod;
}
ans = ans1 + ans2;
ans = ans % mod;
cout << ans; //<< ' '<<ans1<<' '<<ans2<< endl;
}
|
[] | 731,798
| 731,799
|
u422506696
|
cpp
|
p02928
|
#include <bits/stdc++.h>
#define ll long long
#define speed_up \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
#define rep(i, a, b) for (ll i = a; i < b; i++)
#define per(i, a, b) for (ll i = b - 1; i >= a; i--)
#define pb push_back
#define Max(x, y, z) max(x, max(y, z))
#define f first
#define s second
#define lbd lower_bound
#define sz(x) (ll) x.size()
#define pi 3.1415926536
#define mod 1000000007
#define MOD 998244353
#define maxi 100000000000000000
using namespace std;
const int N = 120;
/*bool isprime(ll x)
{
for(ll i=2;(i*i)<=x;i++)
{
if(x%i==0) return 0;
}
return 1;
}*/
/*ll power(ll x,ll n)
{
ll res=1;
while(n>0){
if(n%2) res=(res*x)%mod;
x=(x*x)%mod;
n=n/2;}
return res;
}*/
void solve() {
ll n, m, l = 0, r = 0, z, sum1 = 0, h, a, b, c, d, x = 0, y = 0;
cin >> n >> m;
ll ans = 0;
ll ar[n];
rep(i, 0, n) cin >> ar[i];
ll prefix[n] = {0}, suffix[n] = {0};
rep(i, 0, n) rep(j, i + 1, n) if (ar[i] > ar[j]) l++;
// cout<<l<<" ";
ans = (m * l) % mod;
rep(i, 1, n) {
rep(j, 0, i) if (ar[i] > ar[j]) prefix[i]++;
// cout<<prefix[i]<<" ";
}
// cout<<"\n";
rep(i, 0, n) {
rep(j, i + 1, n) if (ar[i] > ar[j]) suffix[i]++;
// cout<<suffix[i]<<" ";
}
rep(i, 0, n) {
r = ((m - 1) * m) % mod;
r /= 2LL;
r = r % mod;
ans += ((r * suffix[i]) % mod + (r * prefix[i]) % mod) % mod;
ans = ans % mod;
}
cout << ans;
}
int main() {
speed_up ll t = 1;
// cin>>t;
while (t--)
solve();
}
|
#include <bits/stdc++.h>
#define ll long long
#define speed_up \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
#define rep(i, a, b) for (ll i = a; i < b; i++)
#define per(i, a, b) for (ll i = b - 1; i >= a; i--)
#define pb push_back
#define Max(x, y, z) max(x, max(y, z))
#define f first
#define s second
#define lbd lower_bound
#define sz(x) (ll) x.size()
#define pi 3.1415926536
#define mod 1000000007
#define MOD 998244353
#define maxi 100000000000000000
using namespace std;
const int N = 120;
/*bool isprime(ll x)
{
for(ll i=2;(i*i)<=x;i++)
{
if(x%i==0) return 0;
}
return 1;
}*/
/*ll power(ll x,ll n)
{
ll res=1;
while(n>0){
if(n%2) res=(res*x)%mod;
x=(x*x)%mod;
n=n/2;}
return res;
}*/
void solve() {
ll n, m, l = 0, r = 0, z, sum1 = 0, h, a, b, c, d, x = 0, y = 0;
cin >> n >> m;
ll ans = 0;
ll ar[n];
rep(i, 0, n) cin >> ar[i];
ll prefix[n] = {0}, suffix[n] = {0};
rep(i, 0, n) rep(j, i + 1, n) if (ar[i] > ar[j]) l++;
// cout<<l<<" ";
ans = (m * l) % mod;
rep(i, 1, n) {
rep(j, 0, i) if (ar[i] > ar[j]) prefix[i]++;
// cout<<prefix[i]<<" ";
}
// cout<<"\n";
rep(i, 0, n) {
rep(j, i + 1, n) if (ar[i] > ar[j]) suffix[i]++;
// cout<<suffix[i]<<" ";
}
rep(i, 0, n) {
r = ((m - 1) * m) / 2LL;
r = r % mod;
ans += ((r * suffix[i]) % mod + (r * prefix[i]) % mod) % mod;
ans = ans % mod;
}
cout << ans;
}
int main() {
speed_up ll t = 1;
// cin>>t;
while (t--)
solve();
}
|
[
"expression.operator.arithmetic.change",
"assignment.value.change",
"expression.operation.binary.change",
"assignment.change"
] | 731,804
| 731,805
|
u103799157
|
cpp
|
p02928
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using int64 = int64_t;
const int inf = 100000000;
int in() {
int a;
cin >> a;
return a;
} // int型関数の受け取り
void forin(int *x, int y) {
for (int i = 0; i < y; i++) {
cin >> x[i];
}
} //(x,y) int型配列x[y]の受け取り
int intpow(int x, int y) {
double a = x, b = y;
return pow(a, b);
} //(x,y) xをy乗
int intfabs(int x) {
double a = x;
return fabs(a);
} //(x) xの絶対値
int fact(int x) {
if (x == 1)
return 1;
return x * fact(x - 1);
} //(x) x!
int fib(int x) {
if (x <= 2)
return x;
int a[x];
a[0] = 1;
a[1] = 2;
for (int i = 2; i < x; i++) {
a[i] = a[i - 1] + a[i - 2];
}
return a[x - 1];
} //(x) フィボナッチ数列のx番目
ll div1(ll x) { return x % 1000000007; }
// ost:列順で大きい,kst:列の中で大きい
main() {
ll n = in(), k = in(), a[n], ans = 0, ost, kst;
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < n; i++) {
ost = 0;
kst = 0;
for (int i2 = 0; i2 < n; i2++) {
if (a[i2] < a[i] && i < i2)
ost++;
if (a[i2] < a[i]) {
kst++;
}
}
ans += div1(ost * k) + div1(kst * k * (k - 1) / 2);
ans = div1(ans);
// cout << a[i] <<' ' << ost << ' ' << kst << ' ' << ans << endl;
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using int64 = int64_t;
const int inf = 100000000;
int in() {
int a;
cin >> a;
return a;
} // int型関数の受け取り
void forin(int *x, int y) {
for (int i = 0; i < y; i++) {
cin >> x[i];
}
} //(x,y) int型配列x[y]の受け取り
int intpow(int x, int y) {
double a = x, b = y;
return pow(a, b);
} //(x,y) xをy乗
int intfabs(int x) {
double a = x;
return fabs(a);
} //(x) xの絶対値
int fact(int x) {
if (x == 1)
return 1;
return x * fact(x - 1);
} //(x) x!
int fib(int x) {
if (x <= 2)
return x;
int a[x];
a[0] = 1;
a[1] = 2;
for (int i = 2; i < x; i++) {
a[i] = a[i - 1] + a[i - 2];
}
return a[x - 1];
} //(x) フィボナッチ数列のx番目
ll div1(ll x) { return x % 1000000007; }
// ost:列順で大きい,kst:列の中で大きい
main() {
ll n = in(), k = in(), a[n], ans = 0, ost, kst;
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < n; i++) {
ost = 0;
kst = 0;
for (int i2 = 0; i2 < n; i2++) {
if (a[i2] < a[i] && i < i2)
ost++;
if (a[i2] < a[i])
kst++;
}
ans += div1(ost * k) + div1(kst * div1(k * (k - 1) / 2));
ans = div1(ans);
// cout << a[i] <<' ' << ost << ' ' << kst << ' ' << ans << endl;
}
cout << ans << endl;
}
|
[
"call.add",
"call.arguments.change"
] | 731,806
| 731,807
|
u160321725
|
cpp
|
p02928
|
#include <bits/stdc++.h>
using namespace std;
const long long M = 1e9 + 7;
int a[2010];
long long n, k;
long long ans;
long long js(long long k) {
if (k == 0)
return 0;
return ((((1 + k) % M) * (k % M) % M) / 2) % M;
}
int main() {
while (cin >> n >> k) {
memset(a, 0, sizeof(a));
for (int i = 0; i < n; i++)
cin >> a[i];
long long sum = 0, sum2 = 0;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (a[i] > a[j]) {
sum++;
} else if (a[j] > a[i]) {
sum2++;
}
}
}
ans = ((sum * js(k)) % M + (sum2 * js(k - 1)) % M);
cout << (ans % M) << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long M = 1e9 + 7;
int a[2010];
long long n, k;
long long ans;
long long js(long long k) {
if (k == 0)
return 0;
return ((((1 + k) % M) * (k % M)) / 2) % M;
}
int main() {
while (cin >> n >> k) {
memset(a, 0, sizeof(a));
for (int i = 0; i < n; i++)
cin >> a[i];
long long sum = 0, sum2 = 0;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (a[i] > a[j]) {
sum++;
} else if (a[j] > a[i]) {
sum2++;
}
}
}
ans = ((sum * js(k)) % M + (sum2 * js(k - 1)) % M);
cout << (ans % M) << endl;
}
return 0;
}
|
[
"expression.operation.binary.remove"
] | 731,808
| 731,809
|
u397880990
|
cpp
|
p02928
|
#include <bits/stdc++.h>
#define MAX_INT 2100000000
#define rep(i, n) for (i = 1; i <= (n); ++i)
using namespace std;
typedef long long int ll;
#ifdef COMPILE_IN_VCPP
#include <windows.h>
HWND GetConsoleHwnd(void) {
#define MY_BUFSIZE 1024 // Buffer size for console window titles.
HWND hwndFound; // This is what is returned to the caller.
char pszNewWindowTitle[MY_BUFSIZE]; // Contains fabricated// WindowTitle.
char pszOldWindowTitle[MY_BUFSIZE]; // Contains original// WindowTitle.
ULARGE_INTEGER nt;
nt.QuadPart = GetTickCount64();
GetConsoleTitle(pszOldWindowTitle, MY_BUFSIZE);
wsprintf(pszNewWindowTitle, "%d%d/%d", nt.HighPart, nt.LowPart,
GetCurrentProcessId());
SetConsoleTitle(pszNewWindowTitle);
Sleep(40);
hwndFound = FindWindow(NULL, pszNewWindowTitle);
SetConsoleTitle(pszOldWindowTitle);
return (hwndFound);
}
#endif
ll mod = 1e9 + 7;
int main() {
static ll n, k, a[2010], b[2010], i, j, l;
ll g1 = 0, g2 = 0;
cin >> n >> k;
for (i = 1; i <= n; i++) {
cin >> a[i];
b[i] = b[i + n] = a[i];
}
// puts("グループ1");
for (i = 1; i < n; i++) {
for (j = i + 1; j <= n; j++) {
if (i < j && a[i] > a[j]) {
// printf("(i%d,j%d)%d,%d\n",i,j, a[i], a[j]);
g1++;
}
}
}
// puts("グループ1と2");
for (i = 1; i <= n; i++) {
for (j = n + 1; j <= 2 * n; j++) {
if (b[i] > b[j]) {
// printf("(i%d,j%d)%d,%d\n", i, j, b[i], b[j]);
g2++;
}
}
}
// printf("g1%lld,g2%lld\n", g1, g2);
g1 %= mod, g2 %= mod;
long long ans = g1 * k + (k * (k - 1) % mod) * g2 % mod;
cout << ans << endl;
}
|
#include <bits/stdc++.h>
#define MAX_INT 2100000000
#define rep(i, n) for (i = 1; i <= (n); ++i)
using namespace std;
typedef long long int ll;
#ifdef COMPILE_IN_VCPP
#include <windows.h>
HWND GetConsoleHwnd(void) {
#define MY_BUFSIZE 1024 // Buffer size for console window titles.
HWND hwndFound; // This is what is returned to the caller.
char pszNewWindowTitle[MY_BUFSIZE]; // Contains fabricated// WindowTitle.
char pszOldWindowTitle[MY_BUFSIZE]; // Contains original// WindowTitle.
ULARGE_INTEGER nt;
nt.QuadPart = GetTickCount64();
GetConsoleTitle(pszOldWindowTitle, MY_BUFSIZE);
wsprintf(pszNewWindowTitle, "%d%d/%d", nt.HighPart, nt.LowPart,
GetCurrentProcessId());
SetConsoleTitle(pszNewWindowTitle);
Sleep(40);
hwndFound = FindWindow(NULL, pszNewWindowTitle);
SetConsoleTitle(pszOldWindowTitle);
return (hwndFound);
}
#endif
ll mod = 1e9 + 7;
int main() {
static ll n, k, a[2010], b[4020], i, j, l;
ll g1 = 0, g2 = 0;
cin >> n >> k;
for (i = 1; i <= n; i++) {
cin >> a[i];
b[i] = b[i + n] = a[i];
}
// puts("グループ1");
for (i = 1; i < n; i++) {
for (j = i + 1; j <= n; j++) {
if (i < j && a[i] > a[j]) {
// printf("(i%d,j%d)%d,%d\n",i,j, a[i], a[j]);
g1++;
}
}
}
// puts("グループ1と2");
for (i = 1; i <= n; i++) {
for (j = n + 1; j <= 2 * n; j++) {
if (b[i] > b[j]) {
// printf("(i%d,j%d)%d,%d\n", i, j, b[i], b[j]);
g2++;
}
}
}
// printf("g1%lld,g2%lld\n", g1, g2);
g1 %= mod, g2 %= mod;
long long ans = g1 * k + (k * (k - 1) / 2 % mod) * g2;
ans %= mod;
cout << ans << endl;
}
|
[
"literal.number.change",
"variable_declaration.array_dimensions.change",
"expression.operation.binary.change",
"assignment.change"
] | 731,811
| 731,812
|
u697367509
|
cpp
|
p02928
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
ll n, k;
cin >> n >> k;
vector<ll> a(n);
map<ll, ll> index;
for (int i = 0; i < n; ++i) {
cin >> a[i];
// count[a[i]]++;
}
vector<pair<ll, ll>> v(n), temp1(n);
vector<ll> temp(n);
temp = a;
sort(temp.begin(), temp.end());
// temp.erase(unique(temp.begin(), temp.end()), temp.end());
// for(int i = 0 ; i < temp.size(); i++)
// {
// temp1[i].first = temp[i];
// temp1[i].second = i;
// }
for (int i = temp.size() - 1; i >= 0; i--) {
index[temp[i]] = i;
}
// sort(v.begin(), v.end());
// temp1=v;
// temp1.erase(unique(temp1.begin(), temp1.end()), temp1.end());
// for(int i = 0; i < temp1.size(); i++)
// {
// cout<<temp1[i].first<<" "<<temp1[i].second<<endl;
// }
vector<ll> ans(n, 0);
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (a[i] > a[j]) {
ans[i]++;
}
}
}
// for(int i = 0; i < n; i++)
// {
// cout<<ans[i]<<endl;
// }
ll f_ans = 0, mod = 1000000007;
for (int i = 0; i < n; i++) {
// cout<<
// ll t = (k%mod)*((2*
// ans[i]%mod)+(((k-1+mod)%mod)*(index[a[i]]%mod)%mod)%mod)%mod;
ll z = ((k * (k - 1 + mod)) / 2) % mod;
ll t =
((k % mod * ans[i] % mod) % mod + (z % mod * index[a[i]] % mod) % mod) %
mod;
// t/=2;
// cout<<"t "<<t<<endl;
f_ans = (t % mod + f_ans % mod) % mod;
// f_ans/=2;
}
cout << f_ans % mod << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
ll n, k;
cin >> n >> k;
vector<ll> a(n);
map<ll, ll> index;
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
vector<pair<ll, ll>> v(n), temp1(n);
vector<ll> temp(n);
temp = a;
sort(temp.begin(), temp.end());
for (int i = temp.size() - 1; i >= 0; i--) {
index[temp[i]] = i;
}
vector<ll> ans(n, 0);
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (a[i] > a[j]) {
ans[i]++;
}
}
}
ll f_ans = 0, mod = 1000000007;
for (int i = 0; i < n; i++) {
ll z = ((k * (k - 1)) / 2) % mod;
ll t =
((k % mod * ans[i] % mod) % mod + (z % mod * index[a[i]] % mod) % mod) %
mod;
f_ans = (t % mod + f_ans % mod) % mod;
}
cout << f_ans % mod << endl;
}
|
[
"expression.operation.binary.remove"
] | 731,818
| 731,819
|
u644164234
|
cpp
|
p02928
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
ll n, k;
cin >> n >> k;
vector<ll> a(n);
map<ll, ll> index;
for (int i = 0; i < n; ++i) {
cin >> a[i];
// count[a[i]]++;
}
vector<pair<ll, ll>> v(n), temp1(n);
vector<ll> temp(n);
temp = a;
sort(temp.begin(), temp.end());
// temp.erase(unique(temp.begin(), temp.end()), temp.end());
// for(int i = 0 ; i < temp.size(); i++)
// {
// temp1[i].first = temp[i];
// temp1[i].second = i;
// }
for (int i = temp.size() - 1; i >= 0; i--) {
index[temp[i]] = i;
}
// sort(v.begin(), v.end());
// temp1=v;
// temp1.erase(unique(temp1.begin(), temp1.end()), temp1.end());
// for(int i = 0; i < temp1.size(); i++)
// {
// cout<<temp1[i].first<<" "<<temp1[i].second<<endl;
// }
vector<ll> ans(n, 0);
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (a[i] > a[j]) {
ans[i]++;
}
}
}
// for(int i = 0; i < n; i++)
// {
// cout<<ans[i]<<endl;
// }
ll f_ans = 0, mod = 1000000007;
for (int i = 0; i < n; i++) {
// cout<<
// ll t = (k%mod)*((2*
// ans[i]%mod)+(((k-1+mod)%mod)*(index[a[i]]%mod)%mod)%mod)%mod;
ll z = (k * (k - 1 + mod) / 2) % mod;
ll t =
((k % mod * ans[i] % mod) % mod + (z % mod * index[a[i]] % mod) % mod) %
mod;
// t/=2;
// cout<<"t "<<t<<endl;
f_ans = (t % mod + f_ans % mod) % mod;
// f_ans/=2;
}
cout << f_ans % mod << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
ll n, k;
cin >> n >> k;
vector<ll> a(n);
map<ll, ll> index;
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
vector<pair<ll, ll>> v(n), temp1(n);
vector<ll> temp(n);
temp = a;
sort(temp.begin(), temp.end());
for (int i = temp.size() - 1; i >= 0; i--) {
index[temp[i]] = i;
}
vector<ll> ans(n, 0);
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (a[i] > a[j]) {
ans[i]++;
}
}
}
ll f_ans = 0, mod = 1000000007;
for (int i = 0; i < n; i++) {
ll z = ((k * (k - 1)) / 2) % mod;
ll t =
((k % mod * ans[i] % mod) % mod + (z % mod * index[a[i]] % mod) % mod) %
mod;
f_ans = (t % mod + f_ans % mod) % mod;
}
cout << f_ans % mod << endl;
}
|
[
"expression.operation.binary.change"
] | 731,820
| 731,819
|
u644164234
|
cpp
|
p02928
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
ll n, k;
cin >> n >> k;
vector<ll> a(n);
map<ll, ll> index;
for (int i = 0; i < n; ++i) {
cin >> a[i];
// count[a[i]]++;
}
vector<pair<ll, ll>> v(n), temp1(n);
vector<ll> temp(n);
temp = a;
sort(temp.begin(), temp.end());
// temp.erase(unique(temp.begin(), temp.end()), temp.end());
// for(int i = 0 ; i < temp.size(); i++)
// {
// temp1[i].first = temp[i];
// temp1[i].second = i;
// }
for (int i = temp.size() - 1; i >= 0; i--) {
index[temp[i]] = i;
}
// sort(v.begin(), v.end());
// temp1=v;
// temp1.erase(unique(temp1.begin(), temp1.end()), temp1.end());
// for(int i = 0; i < temp1.size(); i++)
// {
// cout<<temp1[i].first<<" "<<temp1[i].second<<endl;
// }
vector<ll> ans(n, 0);
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (a[i] > a[j]) {
ans[i]++;
}
}
}
// for(int i = 0; i < n; i++)
// {
// cout<<ans[i]<<endl;
// }
ll f_ans = 0, mod = 1000000007;
for (int i = 0; i < n; i++) {
// cout<<
// ll t = (k%mod)*((2*
// ans[i]%mod)+(((k-1+mod)%mod)*(index[a[i]]%mod)%mod)%mod)%mod;
ll z = (k * (k - 1 + mod) / 2) % mod;
ll t =
((k % mod * ans[i] % mod) % mod + (z % mod * index[a[i]] % mod) % mod) %
mod;
// t/=2;
// cout<<"t "<<t<<endl;
f_ans = (t % mod + f_ans % mod) % mod;
// f_ans/=2;
}
cout << f_ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
ll n, k;
cin >> n >> k;
vector<ll> a(n);
map<ll, ll> index;
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
vector<pair<ll, ll>> v(n), temp1(n);
vector<ll> temp(n);
temp = a;
sort(temp.begin(), temp.end());
for (int i = temp.size() - 1; i >= 0; i--) {
index[temp[i]] = i;
}
vector<ll> ans(n, 0);
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (a[i] > a[j]) {
ans[i]++;
}
}
}
ll f_ans = 0, mod = 1000000007;
for (int i = 0; i < n; i++) {
ll z = ((k * (k - 1)) / 2) % mod;
ll t =
((k % mod * ans[i] % mod) % mod + (z % mod * index[a[i]] % mod) % mod) %
mod;
f_ans = (t % mod + f_ans % mod) % mod;
}
cout << f_ans % mod << endl;
}
|
[
"expression.operation.binary.change"
] | 731,821
| 731,819
|
u644164234
|
cpp
|
p02928
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
ll n, k;
cin >> n >> k;
vector<ll> a(n);
map<ll, ll> index;
for (int i = 0; i < n; ++i) {
cin >> a[i];
// count[a[i]]++;
}
// vector<pair<ll, ll> > v(n), temp1(n);
vector<ll> temp(n);
temp = a;
sort(temp.begin(), temp.end());
// temp.erase(unique(temp.begin(), temp.end()), temp.end());
// for(int i = 0 ; i < temp.size(); i++)
// {
// temp1[i].first = temp[i];
// temp1[i].second = i;
// }
for (int i = temp.size() - 1; i >= 0; i--) {
index[temp[i]] = i;
}
// sort(v.begin(), v.end());
// temp1=v;
// temp1.erase(unique(temp1.begin(), temp1.end()), temp1.end());
// for(int i = 0; i < temp1.size(); i++)
// {
// cout<<temp1[i].first<<" "<<temp1[i].second<<endl;
// }
vector<ll> ans(n, 0);
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (a[i] > a[j]) {
ans[i]++;
}
}
}
// for(int i = 0; i < n; i++)
// {
// cout<<ans[i]<<endl;
// }
ll f_ans = 0, mod = 1000000007;
for (int i = 0; i < n; i++) {
// cout<<
// ll t = (k%mod)*((2*
// ans[i]%mod)+(((k-1+mod)%mod)*(index[a[i]]%mod)%mod)%mod)%mod;
ll z = ((k * (k - 1 + mod)) / 2) % mod;
ll t =
((k % mod * ans[i] % mod) % mod + (z % mod * index[a[i]] % mod) % mod) %
mod;
// t/=2;
// cout<<"t "<<t<<endl;
f_ans = (t % mod + f_ans % mod) % mod;
// f_ans/=2;
}
cout << f_ans % mod << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
ll n, k;
cin >> n >> k;
vector<ll> a(n);
map<ll, ll> index;
for (int i = 0; i < n; ++i) {
cin >> a[i];
// count[a[i]]++;
}
// vector<pair<ll, ll> > v(n), temp1(n);
vector<ll> temp(n);
temp = a;
sort(temp.begin(), temp.end());
// temp.erase(unique(temp.begin(), temp.end()), temp.end());
// for(int i = 0 ; i < temp.size(); i++)
// {
// temp1[i].first = temp[i];
// temp1[i].second = i;
// }
for (int i = temp.size() - 1; i >= 0; i--) {
index[temp[i]] = i;
}
// sort(v.begin(), v.end());
// temp1=v;
// temp1.erase(unique(temp1.begin(), temp1.end()), temp1.end());
// for(int i = 0; i < temp1.size(); i++)
// {
// cout<<temp1[i].first<<" "<<temp1[i].second<<endl;
// }
vector<ll> ans(n, 0);
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (a[i] > a[j]) {
ans[i]++;
}
}
}
// for(int i = 0; i < n; i++)
// {
// cout<<ans[i]<<endl;
// }
ll f_ans = 0, mod = 1000000007;
for (int i = 0; i < n; i++) {
// cout<<
// ll t = (k%mod)*((2*
// ans[i]%mod)+(((k-1+mod)%mod)*(index[a[i]]%mod)%mod)%mod)%mod;
ll z = ((k * (k - 1)) / 2) % mod;
ll t =
((k % mod * ans[i] % mod) % mod + (z % mod * index[a[i]] % mod) % mod) %
mod;
// t/=2;
// cout<<"t "<<t<<endl;
f_ans = (t % mod + f_ans % mod) % mod;
// f_ans/=2;
}
cout << f_ans % mod << endl;
}
|
[
"expression.operation.binary.remove"
] | 731,822
| 731,823
|
u644164234
|
cpp
|
p02928
|
#include "bits/stdc++.h"
#define REP(i, n, N) for (ll i = (n); i < (N); i++)
#define RREP(i, n, N) for (ll i = (N - 1); i >= (n); i--)
#define LREP(lst, itr) for (auto itr = lst.begin(); itr != lst.end(); ++itr)
#define CK(n, a, b) ((a) <= (n) && (n) < (b))
#define ALL(v) (v).begin(), (v).end()
#define MCP(a, b) memcpy(b, a, sizeof(b))
#define P(s) cout << (s) << endl
#define P2(a, b) cout << (a) << " " << (b) << endl
#define V2(T) vector<vector<T>>
typedef long long ll;
using namespace std;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
ll mood(ll a) { return a % MOD; }
ll modinv(ll a) {
ll b = MOD, u = 1, v = 0;
while (b) {
ll t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
u %= MOD;
if (u < 0)
u += MOD;
return u;
}
ll kaisa(ll a1, ll a2, ll diff, ll n) {
return mood(a1 + mood(mood((a2 - diff) * (n - 1)) +
mood(diff * (mood(n * (n - 1)) * modinv(2)))));
}
ll check(vector<int> &seq, int n) {
ll res = 0;
ll len = seq.size();
REP(i, 0, len * n) {
REP(j, i, len * n) {
if (seq[i % len] > seq[j % len]) {
res++;
}
}
}
return res;
}
int main() {
ll N, K;
cin >> N >> K;
vector<int> seq(N);
REP(i, 0, N) { cin >> seq[i]; }
int a, b, c, d, e, f;
a = check(seq, 1);
b = check(seq, 2);
c = check(seq, 3);
d = b - a;
e = c - b;
f = e - d;
ll ans = kaisa(a, d, f, K);
P(ans);
}
|
#include "bits/stdc++.h"
#define REP(i, n, N) for (ll i = (n); i < (N); i++)
#define RREP(i, n, N) for (ll i = (N - 1); i >= (n); i--)
#define LREP(lst, itr) for (auto itr = lst.begin(); itr != lst.end(); ++itr)
#define CK(n, a, b) ((a) <= (n) && (n) < (b))
#define ALL(v) (v).begin(), (v).end()
#define MCP(a, b) memcpy(b, a, sizeof(b))
#define P(s) cout << (s) << endl
#define P2(a, b) cout << (a) << " " << (b) << endl
#define V2(T) vector<vector<T>>
typedef long long ll;
using namespace std;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
ll mood(ll a) { return a % MOD; }
ll modinv(ll a) {
ll b = MOD, u = 1, v = 0;
while (b) {
ll t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
u %= MOD;
if (u < 0)
u += MOD;
return u;
}
ll kaisa(ll a1, ll a2, ll diff, ll n) {
return mood(a1 + mood(mood((a2 - diff) * (n - 1)) +
mood(diff * mood(mood(n * (n - 1)) * modinv(2)))));
}
ll check(vector<int> &seq, int n) {
ll res = 0;
ll len = seq.size();
REP(i, 0, len * n) {
REP(j, i, len * n) {
if (seq[i % len] > seq[j % len]) {
res++;
}
}
}
return res;
}
int main() {
ll N, K;
cin >> N >> K;
vector<int> seq(N);
REP(i, 0, N) { cin >> seq[i]; }
int a, b, c, d, e, f;
a = check(seq, 1);
b = check(seq, 2);
c = check(seq, 3);
d = b - a;
e = c - b;
f = e - d;
ll ans = kaisa(a, d, f, K);
P(ans);
}
|
[
"call.add",
"call.arguments.change",
"function.return_value.change"
] | 731,824
| 731,825
|
u379951749
|
cpp
|
p02928
|
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, _s, n) for (int i = _s, i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
// vector
template <typename T> istream &operator>>(istream &is, vector<T> &vec) {
for (T &x : vec)
is >> x;
return is;
}
// pair
template <typename T, typename U>
ostream &operator<<(ostream &os, pair<T, U> &pair_var) {
os << "(" << pair_var.first << ", " << pair_var.second << ")";
return os;
}
// vector
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
os << "{";
for (int i = 0; i < vec.size(); i++) {
os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
}
os << "}\n ";
return os;
}
// map
template <typename T, typename U>
ostream &operator<<(ostream &os, map<T, U> &map_var) {
os << "{";
repi(itr, map_var) {
os << *itr;
itr++;
if (itr != map_var.end())
os << ", ";
itr--;
}
os << "}";
return os;
}
// set
template <typename T> ostream &operator<<(ostream &os, set<T> &set_var) {
os << "{";
repi(itr, set_var) {
os << *itr;
itr++;
if (itr != set_var.end())
os << ", ";
itr--;
}
os << "}";
return os;
}
#define DUMPOUT cerr
void dump_func() { DUMPOUT << endl; }
template <class Head, class... Tail>
void dump_func(Head &&head, Tail &&...tail) {
DUMPOUT << head;
if (sizeof...(Tail) > 0) {
DUMPOUT << ", ";
}
dump_func(std::move(tail)...);
}
#ifdef DEBUG_
#define DEB
#define dump(...) \
DUMPOUT << " " << string(#__VA_ARGS__) << ": " \
<< "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" << endl \
<< " ", \
dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif
typedef long long int ll;
const ll MOD = 1e9 + 7;
const int INF = 1e9;
int main() {
ll N, K;
cin >> N >> K;
auto A = vector<ll>(2001);
REP(i, N) cin >> A[i];
// REP(i, 2000) { A[i] = 2000 - i; }
auto left = vector<ll>(2001, 0);
auto right = vector<ll>(2001, 0);
REP(i, N) {
REP(j, N) {
if (A[j] > A[i] && j > i) {
left[A[j]]++;
} else if (A[j] > A[i] && i > j) {
right[A[j]]++;
}
}
}
ll sum = 0;
REP(i, N + 1) {
ll rs = 0;
rs += (K + 1) * K / 2;
rs %= MOD;
rs *= right[i];
rs %= MOD;
ll ls = 0;
ls += (K - 1) * K / 2;
ls %= MOD;
ls *= left[i];
ls %= MOD;
sum += rs;
sum %= MOD;
sum += ls;
sum %= MOD;
}
std::cout << sum << endl;
}
|
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, _s, n) for (int i = _s, i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
// vector
template <typename T> istream &operator>>(istream &is, vector<T> &vec) {
for (T &x : vec)
is >> x;
return is;
}
// pair
template <typename T, typename U>
ostream &operator<<(ostream &os, pair<T, U> &pair_var) {
os << "(" << pair_var.first << ", " << pair_var.second << ")";
return os;
}
// vector
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
os << "{";
for (int i = 0; i < vec.size(); i++) {
os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
}
os << "}\n ";
return os;
}
// map
template <typename T, typename U>
ostream &operator<<(ostream &os, map<T, U> &map_var) {
os << "{";
repi(itr, map_var) {
os << *itr;
itr++;
if (itr != map_var.end())
os << ", ";
itr--;
}
os << "}";
return os;
}
// set
template <typename T> ostream &operator<<(ostream &os, set<T> &set_var) {
os << "{";
repi(itr, set_var) {
os << *itr;
itr++;
if (itr != set_var.end())
os << ", ";
itr--;
}
os << "}";
return os;
}
#define DUMPOUT cerr
void dump_func() { DUMPOUT << endl; }
template <class Head, class... Tail>
void dump_func(Head &&head, Tail &&...tail) {
DUMPOUT << head;
if (sizeof...(Tail) > 0) {
DUMPOUT << ", ";
}
dump_func(std::move(tail)...);
}
#ifdef DEBUG_
#define DEB
#define dump(...) \
DUMPOUT << " " << string(#__VA_ARGS__) << ": " \
<< "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" << endl \
<< " ", \
dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif
typedef long long int ll;
const ll MOD = 1e9 + 7;
const int INF = 1e9;
int main() {
ll N, K;
cin >> N >> K;
auto A = vector<ll>(2001);
REP(i, N) cin >> A[i];
// REP(i, 2000) { A[i] = 2000 - i; }
auto left = vector<ll>(2001, 0);
auto right = vector<ll>(2001, 0);
REP(i, N) {
REP(j, N) {
if (A[j] > A[i] && j > i) {
left[A[j]]++;
} else if (A[j] > A[i] && i > j) {
right[A[j]]++;
}
}
}
ll sum = 0;
REP(i, 2001) {
ll rs = 0;
rs += (K + 1) * K / 2;
rs %= MOD;
rs *= right[i];
rs %= MOD;
ll ls = 0;
ls += (K - 1) * K / 2;
ls %= MOD;
ls *= left[i];
ls %= MOD;
sum += rs;
sum %= MOD;
sum += ls;
sum %= MOD;
}
std::cout << sum << endl;
}
|
[
"identifier.replace.remove",
"literal.replace.add",
"call.arguments.change",
"expression.operation.binary.change",
"expression.operation.binary.remove"
] | 731,830
| 731,831
|
u743229067
|
cpp
|
p02928
|
#include "bits/stdc++.h"
using namespace std;
// vector<long long> factors;
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define _ << '\n'
#define __ << ' '
#define all(x) (x).begin(), (x).end()
#define gcd __gcd
int IT_MAX = 1 << 17;
int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x0f3f3f3f3f3f3f3f;
const double PI = acos(-1);
const double ERR = 1e-10;
#define szz(x) (int)(x).size()
#define IOS \
ios_base::sync_with_stdio(false); \
cout.tie(0); \
cin.tie(0);
#define flush fflush(stdout)
ll mod(ll a, ll m) { return (a + (abs(a) / m) * m + m) % m; }
//****************************don't use int!!!!!!!****************************//
//***************************code starts here!!!!!****************************//
int main() {
ll n, k;
cin >> n >> k;
vector<ll> a(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
vector<ll> sorted_a = a;
sort(all(sorted_a));
ll ans = 0;
for (int i = 0; i < n; ++i) {
ll more_cnt = 0;
for (int j = i + 1; j < n; ++j) {
if (a[i] > a[j]) {
++more_cnt;
}
}
ll total_cnt = sorted_a.end() - upper_bound(all(sorted_a), a[i]);
ans += total_cnt * ((k - 1) * k / 2) % MOD + more_cnt * k;
ans %= MOD;
}
cout << ans;
return 0;
}
|
#include "bits/stdc++.h"
using namespace std;
// vector<long long> factors;
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define _ << '\n'
#define __ << ' '
#define all(x) (x).begin(), (x).end()
#define gcd __gcd
int IT_MAX = 1 << 17;
int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x0f3f3f3f3f3f3f3f;
const double PI = acos(-1);
const double ERR = 1e-10;
#define szz(x) (int)(x).size()
#define IOS \
ios_base::sync_with_stdio(false); \
cout.tie(0); \
cin.tie(0);
#define flush fflush(stdout)
ll mod(ll a, ll m) { return (a + (abs(a) / m) * m + m) % m; }
//****************************don't use int!!!!!!!****************************//
//***************************code starts here!!!!!****************************//
int main() {
ll n, k;
cin >> n >> k;
vector<ll> a(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
vector<ll> sorted_a = a;
sort(all(sorted_a));
ll ans = 0;
for (int i = 0; i < n; ++i) {
ll more_cnt = 0;
for (int j = i + 1; j < n; ++j) {
if (a[i] > a[j]) {
++more_cnt;
}
}
ll total_cnt = sorted_a.end() - upper_bound(all(sorted_a), a[i]);
ans += total_cnt * (((k - 1) * k / 2) % MOD) + more_cnt * k;
ans %= MOD;
}
cout << ans;
return 0;
}
|
[] | 731,836
| 731,837
|
u559507546
|
cpp
|
p02928
|
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <ciso646>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)
#define inf 0x3f3f3f3f3f3f3f3f
#define ALL(a) (a).begin(), (a).end()
#define DEBUG(x) // cerr<<#x<<": "<<x<<endl
#define ll long long
#define ull unsigned long long
using pii = pair<ll, ll>;
#define eps 1e-14
#define SETUP \
cin.tie(0), ios::sync_with_stdio(false), \
cout << setprecision(15) << std::fixed;
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
template <class T> using vec2 = std::vector<vector<T>>;
//// bit ////
#ifdef _MSC_VER
#ifdef _WIN32
inline unsigned int __builtin_ctz(unsigned int x) {
unsigned long r;
_BitScanForward(&r, x);
return r;
}
inline unsigned int __builtin_clz(unsigned int x) {
unsigned long r;
_BitScanReverse(&r, x);
return 31 - r;
}
inline unsigned int __builtin_ffs(unsigned int x) {
unsigned long r;
return _BitScanForward(&r, x) ? r + 1 : 0;
}
// inline unsigned int __builtin_popcount(unsigned int x){ return __popcnt(x); }
#ifdef _WIN64
inline unsigned long long __builtin_ctzll(unsigned long long x) {
unsigned long r;
_BitScanForward64(&r, x);
return r;
}
inline unsigned long long __builtin_clzll(unsigned long long x) {
unsigned long r;
_BitScanReverse64(&r, x);
return 63 - r;
}
inline unsigned long long __builtin_ffsll(unsigned long long x) {
unsigned long r;
return _BitScanForward64(&r, x) ? r + 1 : 0;
}
inline unsigned long long __builtin_popcountll(unsigned long long x) {
return __popcnt64(x);
}
#else
inline unsigned int hidword(unsigned long long x) {
return static_cast<unsigned int>(x >> 32);
}
inline unsigned int lodword(unsigned long long x) {
return static_cast<unsigned int>(x & 0xFFFFFFFF);
}
inline unsigned long long __builtin_ctzll(unsigned long long x) {
return lodword(x) ? __builtin_ctz(lodword(x))
: __builtin_ctz(hidword(x)) + 32;
}
inline unsigned long long __builtin_clzll(unsigned long long x) {
return hidword(x) ? __builtin_clz(hidword(x))
: __builtin_clz(lodword(x)) + 32;
}
inline unsigned long long __builtin_ffsll(unsigned long long x) {
return lodword(x) ? __builtin_ffs(lodword(x))
: hidword(x) ? __builtin_ffs(hidword(x)) + 32
: 0;
}
// inline unsigned long long __builtin_popcountll(unsigned long long x) { return
// __builtin_popcount(lodword(x)) + __builtin_popcount(hidword(x)); }
#endif // _WIN64
#endif // _WIN32
#endif // _MSC_VER
namespace {
struct input_returnner {
ll N;
input_returnner(ll N_ = 0) : N(N_) {}
template <typename T> operator vector<T>() const {
vector<T> res(N);
for (auto &a : res)
cin >> a;
return std::move(res);
}
template <typename T> operator T() const {
T res;
cin >> res;
return res;
}
template <typename T> T operator-(T right) {
return T(input_returnner()) - right;
}
template <typename T> T operator+(T right) {
return T(input_returnner()) + right;
}
template <typename T> T operator*(T right) {
return T(input_returnner()) * right;
}
template <typename T> T operator/(T right) {
return T(input_returnner()) / right;
}
template <typename T> T operator<<(T right) {
return T(input_returnner()) << right;
}
template <typename T> T operator>>(T right) {
return T(input_returnner()) >> right;
}
};
template <typename T> input_returnner in() { return in<T>(); }
input_returnner in() { return input_returnner(); }
input_returnner in(ll N) { return std::move(input_returnner(N)); }
} // namespace
template <typename T> istream &operator>>(istream &is, vector<T> &vec) {
for (T &x : vec)
is >> x;
return is;
}
template <typename T> struct is_vector : std::false_type {};
template <typename T> struct is_vector<std::vector<T>> : std::true_type {};
template <typename T> constexpr bool is_vector_v = is_vector<T>::value;
template <typename T>
std::ostream &operator<<(std::ostream &out, const std::vector<T> &v) {
if (!v.empty()) {
for (int i = 0; i < v.size(); ++i) {
out << v[i] << (i == v.size() - 1 ? "\n" : (is_vector_v<T> ? "" : ", "));
}
}
return out;
}
namespace std {
// ref:
// https://stackoverflow.com/questions/7110301/generic-hash-for-tuples-in-unordered-map-unordered-set
template <class T> inline void hash_combine(std::size_t &seed, T const &v) {
seed ^= std::hash<T>()(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
}
// Recursive template code derived from Matthieu M.
template <class Tuple, size_t Index = std::tuple_size<Tuple>::value - 1>
struct HashValueImpl {
static void apply(size_t &seed, Tuple const &tuple) {
HashValueImpl<Tuple, Index - 1>::apply(seed, tuple);
hash_combine(seed, std::get<Index>(tuple));
}
};
template <class Tuple> struct HashValueImpl<Tuple, 0> {
static void apply(size_t &seed, Tuple const &tuple) {
hash_combine(seed, std::get<0>(tuple));
}
};
template <typename... TT> struct hash<std::tuple<TT...>> {
size_t operator()(std::tuple<TT...> const &tt) const {
size_t seed = 0;
HashValueImpl<std::tuple<TT...>>::apply(seed, tt);
return seed;
}
};
template <class T, class U> class hash<std::pair<T, U>> {
public:
size_t operator()(const std::pair<T, U> &x) const {
return hash<std::tuple<T, U>>()(std::tie(x.first, x.second));
}
};
} // namespace std
// ref: https://stackoverflow.com/questions/6245735/pretty-print-stdtuple
namespace aux {
template <std::size_t...> struct seq {};
template <std::size_t N, std::size_t... Is>
struct gen_seq : gen_seq<N - 1, N - 1, Is...> {};
template <std::size_t... Is> struct gen_seq<0, Is...> : seq<Is...> {};
template <class Ch, class Tr, class Tuple, std::size_t... Is>
void print_tuple(std::basic_ostream<Ch, Tr> &os, Tuple const &t, seq<Is...>) {
using swallow = int[];
(void)swallow{0,
(void(os << (Is == 0 ? "" : ", ") << std::get<Is>(t)), 0)...};
}
} // namespace aux
template <class Ch, class Tr, class... Args>
auto operator<<(std::basic_ostream<Ch, Tr> &os, std::tuple<Args...> const &t)
-> std::basic_ostream<Ch, Tr> & {
os << "(";
aux::print_tuple(os, t, aux::gen_seq<sizeof...(Args)>());
return os << ")";
}
template <class S, class T>
std::ostream &operator<<(std::ostream &os, const std::pair<S, T> &p) {
return os << "(" << p.first << ", " << p.second << ")";
}
// ref:
// https://stackoverflow.com/questions/8542591/c11-reverse-range-based-for-loo�Fp
template <typename T> struct reversion_wrapper { T &iterable; };
template <typename T> auto begin(reversion_wrapper<T> w) {
return std::rbegin(w.iterable);
}
template <typename T> auto end(reversion_wrapper<T> w) {
return std::rend(w.iterable);
}
template <typename T> reversion_wrapper<T> REV(T &&iterable) {
return {iterable};
}
template <class T> bool inside(T left, T val, T right) {
return left <= val and val < right;
}
template <class T> T bitCount(T num) {
T res = 0;
while (num > 0) {
if (num & 1)
++res;
num >>= 1;
}
return res;
}
ll MOD = 1e9 + 7;
// ll MOD = 998244353;
void solve();
signed main() {
SETUP;
#ifdef _DEBUG
while (true) {
#endif
solve();
#ifdef _DEBUG
cout << "-------" << endl;
}
#endif
#ifdef _DEBUG
system("pause");
#endif
return 0;
}
#define int ll
struct mint {
int64_t value;
mint() : value(0) {}
mint(int64_t value_) : value(value_ % MOD) {}
inline mint &operator+=(const mint &rhs) {
value += rhs.value;
if (value >= MOD) {
value -= MOD;
}
return *this;
}
inline mint &operator-=(const mint &rhs) {
value -= rhs.value;
if (value < 0) {
value += MOD;
}
return *this;
}
inline mint &operator*=(const mint &rhs) {
value *= rhs.value;
value %= MOD;
return *this;
}
inline mint &operator%=(const mint &rhs) { return *this; }
};
inline mint operator+(const mint &lhs, const mint &rhs) {
mint res = lhs;
res += rhs;
return res;
}
inline mint operator-(const mint &lhs, const mint &rhs) {
mint res = lhs;
res -= rhs;
return res;
}
inline mint operator*(const mint &lhs, const mint &rhs) {
mint res = lhs;
res *= rhs;
return res;
}
inline mint operator%(const mint &lhs, const uint64_t &rhs) { return lhs; }
ostream &operator<<(ostream &out, mint n) { return out << n.value; }
// count invitation. O(NlogN)
template <class T> int invitation_count(vector<T> &a) {
int count = 0;
int n = a.size();
if (n > 1) {
vector<T> b(a.begin(), a.begin() + n / 2);
vector<T> c(a.begin() + n / 2, a.end());
count += invitation_count(b);
count += invitation_count(c);
for (int i = 0, j = 0, k = 0; i < n; ++i)
if (k == c.size())
a[i] = b[j++];
else if (j == b.size())
a[i] = c[k++];
// invitation_count: i < j and a_i > a_j
// this case: j < k and b[j] > c[k]
else if (b[j] > c[k]) {
a[i] = c[k++];
count += n / 2 - j;
} else {
a[i] = b[j++];
}
}
return count;
}
// x^n % mod
// O(log n)
mint mod_pow(mint x, uint64_t n) {
mint res = 1;
while (n > 0) {
if (n & 1)
res = res * x;
x = x * x;
n >>= 1;
}
return res;
}
void solve() {
int N, K;
cin >> N >> K;
vector<int> A(N);
for (auto &a : A)
cin >> a;
// REP(j, K-1) {
// REP(i, N) {
// A.push_back(A[i]);
// }
//}
mint res = invitation_count(A);
mint c = 0;
mint memo = 0;
mint temp = (1 + (K - 1)) * (K - 1) / 2;
int prev = -1;
REP(i, N) {
int a = A[i];
if (prev != a) {
c += memo;
memo = 0;
}
res += c * temp;
prev = a;
memo = memo + 1;
}
cout << res << endl;
}
|
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <ciso646>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)
#define inf 0x3f3f3f3f3f3f3f3f
#define ALL(a) (a).begin(), (a).end()
#define DEBUG(x) // cerr<<#x<<": "<<x<<endl
#define ll long long
#define ull unsigned long long
using pii = pair<ll, ll>;
#define eps 1e-14
#define SETUP \
cin.tie(0), ios::sync_with_stdio(false), \
cout << setprecision(15) << std::fixed;
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
template <class T> using vec2 = std::vector<vector<T>>;
//// bit ////
#ifdef _MSC_VER
#ifdef _WIN32
inline unsigned int __builtin_ctz(unsigned int x) {
unsigned long r;
_BitScanForward(&r, x);
return r;
}
inline unsigned int __builtin_clz(unsigned int x) {
unsigned long r;
_BitScanReverse(&r, x);
return 31 - r;
}
inline unsigned int __builtin_ffs(unsigned int x) {
unsigned long r;
return _BitScanForward(&r, x) ? r + 1 : 0;
}
// inline unsigned int __builtin_popcount(unsigned int x){ return __popcnt(x); }
#ifdef _WIN64
inline unsigned long long __builtin_ctzll(unsigned long long x) {
unsigned long r;
_BitScanForward64(&r, x);
return r;
}
inline unsigned long long __builtin_clzll(unsigned long long x) {
unsigned long r;
_BitScanReverse64(&r, x);
return 63 - r;
}
inline unsigned long long __builtin_ffsll(unsigned long long x) {
unsigned long r;
return _BitScanForward64(&r, x) ? r + 1 : 0;
}
inline unsigned long long __builtin_popcountll(unsigned long long x) {
return __popcnt64(x);
}
#else
inline unsigned int hidword(unsigned long long x) {
return static_cast<unsigned int>(x >> 32);
}
inline unsigned int lodword(unsigned long long x) {
return static_cast<unsigned int>(x & 0xFFFFFFFF);
}
inline unsigned long long __builtin_ctzll(unsigned long long x) {
return lodword(x) ? __builtin_ctz(lodword(x))
: __builtin_ctz(hidword(x)) + 32;
}
inline unsigned long long __builtin_clzll(unsigned long long x) {
return hidword(x) ? __builtin_clz(hidword(x))
: __builtin_clz(lodword(x)) + 32;
}
inline unsigned long long __builtin_ffsll(unsigned long long x) {
return lodword(x) ? __builtin_ffs(lodword(x))
: hidword(x) ? __builtin_ffs(hidword(x)) + 32
: 0;
}
// inline unsigned long long __builtin_popcountll(unsigned long long x) { return
// __builtin_popcount(lodword(x)) + __builtin_popcount(hidword(x)); }
#endif // _WIN64
#endif // _WIN32
#endif // _MSC_VER
namespace {
struct input_returnner {
ll N;
input_returnner(ll N_ = 0) : N(N_) {}
template <typename T> operator vector<T>() const {
vector<T> res(N);
for (auto &a : res)
cin >> a;
return std::move(res);
}
template <typename T> operator T() const {
T res;
cin >> res;
return res;
}
template <typename T> T operator-(T right) {
return T(input_returnner()) - right;
}
template <typename T> T operator+(T right) {
return T(input_returnner()) + right;
}
template <typename T> T operator*(T right) {
return T(input_returnner()) * right;
}
template <typename T> T operator/(T right) {
return T(input_returnner()) / right;
}
template <typename T> T operator<<(T right) {
return T(input_returnner()) << right;
}
template <typename T> T operator>>(T right) {
return T(input_returnner()) >> right;
}
};
template <typename T> input_returnner in() { return in<T>(); }
input_returnner in() { return input_returnner(); }
input_returnner in(ll N) { return std::move(input_returnner(N)); }
} // namespace
template <typename T> istream &operator>>(istream &is, vector<T> &vec) {
for (T &x : vec)
is >> x;
return is;
}
template <typename T> struct is_vector : std::false_type {};
template <typename T> struct is_vector<std::vector<T>> : std::true_type {};
template <typename T> constexpr bool is_vector_v = is_vector<T>::value;
template <typename T>
std::ostream &operator<<(std::ostream &out, const std::vector<T> &v) {
if (!v.empty()) {
for (int i = 0; i < v.size(); ++i) {
out << v[i] << (i == v.size() - 1 ? "\n" : (is_vector_v<T> ? "" : ", "));
}
}
return out;
}
namespace std {
// ref:
// https://stackoverflow.com/questions/7110301/generic-hash-for-tuples-in-unordered-map-unordered-set
template <class T> inline void hash_combine(std::size_t &seed, T const &v) {
seed ^= std::hash<T>()(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
}
// Recursive template code derived from Matthieu M.
template <class Tuple, size_t Index = std::tuple_size<Tuple>::value - 1>
struct HashValueImpl {
static void apply(size_t &seed, Tuple const &tuple) {
HashValueImpl<Tuple, Index - 1>::apply(seed, tuple);
hash_combine(seed, std::get<Index>(tuple));
}
};
template <class Tuple> struct HashValueImpl<Tuple, 0> {
static void apply(size_t &seed, Tuple const &tuple) {
hash_combine(seed, std::get<0>(tuple));
}
};
template <typename... TT> struct hash<std::tuple<TT...>> {
size_t operator()(std::tuple<TT...> const &tt) const {
size_t seed = 0;
HashValueImpl<std::tuple<TT...>>::apply(seed, tt);
return seed;
}
};
template <class T, class U> class hash<std::pair<T, U>> {
public:
size_t operator()(const std::pair<T, U> &x) const {
return hash<std::tuple<T, U>>()(std::tie(x.first, x.second));
}
};
} // namespace std
// ref: https://stackoverflow.com/questions/6245735/pretty-print-stdtuple
namespace aux {
template <std::size_t...> struct seq {};
template <std::size_t N, std::size_t... Is>
struct gen_seq : gen_seq<N - 1, N - 1, Is...> {};
template <std::size_t... Is> struct gen_seq<0, Is...> : seq<Is...> {};
template <class Ch, class Tr, class Tuple, std::size_t... Is>
void print_tuple(std::basic_ostream<Ch, Tr> &os, Tuple const &t, seq<Is...>) {
using swallow = int[];
(void)swallow{0,
(void(os << (Is == 0 ? "" : ", ") << std::get<Is>(t)), 0)...};
}
} // namespace aux
template <class Ch, class Tr, class... Args>
auto operator<<(std::basic_ostream<Ch, Tr> &os, std::tuple<Args...> const &t)
-> std::basic_ostream<Ch, Tr> & {
os << "(";
aux::print_tuple(os, t, aux::gen_seq<sizeof...(Args)>());
return os << ")";
}
template <class S, class T>
std::ostream &operator<<(std::ostream &os, const std::pair<S, T> &p) {
return os << "(" << p.first << ", " << p.second << ")";
}
// ref:
// https://stackoverflow.com/questions/8542591/c11-reverse-range-based-for-loo�Fp
template <typename T> struct reversion_wrapper { T &iterable; };
template <typename T> auto begin(reversion_wrapper<T> w) {
return std::rbegin(w.iterable);
}
template <typename T> auto end(reversion_wrapper<T> w) {
return std::rend(w.iterable);
}
template <typename T> reversion_wrapper<T> REV(T &&iterable) {
return {iterable};
}
template <class T> bool inside(T left, T val, T right) {
return left <= val and val < right;
}
template <class T> T bitCount(T num) {
T res = 0;
while (num > 0) {
if (num & 1)
++res;
num >>= 1;
}
return res;
}
ll MOD = 1e9 + 7;
// ll MOD = 998244353;
void solve();
signed main() {
SETUP;
#ifdef _DEBUG
while (true) {
#endif
solve();
#ifdef _DEBUG
cout << "-------" << endl;
}
#endif
#ifdef _DEBUG
system("pause");
#endif
return 0;
}
#define int ll
struct mint {
int64_t value;
mint() : value(0) {}
mint(int64_t value_) : value(value_ % MOD) {}
inline mint &operator+=(const mint &rhs) {
value += rhs.value;
if (value >= MOD) {
value -= MOD;
}
return *this;
}
inline mint &operator-=(const mint &rhs) {
value -= rhs.value;
if (value < 0) {
value += MOD;
}
return *this;
}
inline mint &operator*=(const mint &rhs) {
value *= rhs.value;
value %= MOD;
return *this;
}
inline mint &operator%=(const mint &rhs) { return *this; }
};
inline mint operator+(const mint &lhs, const mint &rhs) {
mint res = lhs;
res += rhs;
return res;
}
inline mint operator-(const mint &lhs, const mint &rhs) {
mint res = lhs;
res -= rhs;
return res;
}
inline mint operator*(const mint &lhs, const mint &rhs) {
mint res = lhs;
res *= rhs;
return res;
}
inline mint operator%(const mint &lhs, const uint64_t &rhs) { return lhs; }
ostream &operator<<(ostream &out, mint n) { return out << n.value; }
// count invitation. O(NlogN)
template <class T> int invitation_count(vector<T> &a) {
int count = 0;
int n = a.size();
if (n > 1) {
vector<T> b(a.begin(), a.begin() + n / 2);
vector<T> c(a.begin() + n / 2, a.end());
count += invitation_count(b);
count += invitation_count(c);
for (int i = 0, j = 0, k = 0; i < n; ++i)
if (k == c.size())
a[i] = b[j++];
else if (j == b.size())
a[i] = c[k++];
// invitation_count: i < j and a_i > a_j
// this case: j < k and b[j] > c[k]
else if (b[j] > c[k]) {
a[i] = c[k++];
count += n / 2 - j;
} else {
a[i] = b[j++];
}
}
return count;
}
// x^n % mod
// O(log n)
mint mod_pow(mint x, uint64_t n) {
mint res = 1;
while (n > 0) {
if (n & 1)
res = res * x;
x = x * x;
n >>= 1;
}
return res;
}
void solve() {
int N, K;
cin >> N >> K;
vector<int> A(N);
for (auto &a : A)
cin >> a;
// REP(j, K-1) {
// REP(i, N) {
// A.push_back(A[i]);
// }
//}
mint res = invitation_count(A) * K;
mint c = 0;
mint memo = 0;
mint temp = (1 + (K - 1)) * (K - 1) / 2;
int prev = -1;
REP(i, N) {
int a = A[i];
if (prev != a) {
c += memo;
memo = 0;
}
res += c * temp;
prev = a;
memo = memo + 1;
}
cout << res << endl;
}
|
[
"assignment.change"
] | 731,840
| 731,841
|
u579875569
|
cpp
|
p02928
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int(i) = 0; (i) < (n); ++i)
#define rrep(i, n) for (int(i) = (n)-1; (i) >= 0; --i)
#define rep1(i, n) for (int(i) = 1; (i) <= (n); ++i)
#define rrep1(i, n) for (int(i) = (n); (i) >= 1; --i)
#define pb push_back
#define fr first
#define sc second
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> LP;
typedef double db;
using namespace std;
ll N, K;
ll A[2000];
ll th[2000];
ll th_right[2000];
ll ans = 0;
ll mod = 1000000007;
int main() {
cin >> N >> K;
rep(i, N) cin >> A[i];
rep(i, N) {
rep(j, N) {
if (A[i] > A[j]) {
th[i]++;
if (i < j)
th_right[i]++;
}
}
}
rep(i, N) {
// cout<<th[i]<<" "<<th_right[i]<<endl;
ans += (th_right[i] * K) % mod;
ans %= mod;
ans += th[i] * ((K * (K - 1)) / 2) % mod;
ans %= mod;
}
cout << ans << endl;
}
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int(i) = 0; (i) < (n); ++i)
#define rrep(i, n) for (int(i) = (n)-1; (i) >= 0; --i)
#define rep1(i, n) for (int(i) = 1; (i) <= (n); ++i)
#define rrep1(i, n) for (int(i) = (n); (i) >= 1; --i)
#define pb push_back
#define fr first
#define sc second
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> LP;
typedef double db;
using namespace std;
ll N, K;
ll A[2000];
ll th[2000];
ll th_right[2000];
ll ans = 0;
ll mod = 1000000007;
int main() {
cin >> N >> K;
rep(i, N) cin >> A[i];
rep(i, N) {
rep(j, N) {
if (A[i] > A[j]) {
th[i]++;
if (i < j)
th_right[i]++;
}
}
}
rep(i, N) {
// cout<<th[i]<<" "<<th_right[i]<<endl;
ans += (th_right[i] * K) % mod;
ans %= mod;
ans += (th[i] * (((K * (K - 1)) / 2) % mod)) % mod;
ans %= mod;
}
cout << ans << endl;
}
|
[
"assignment.change"
] | 731,852
| 731,853
|
u094718623
|
cpp
|
p02928
|
#include <bits/stdc++.h>
using namespace std;
long long N, K;
long long a[2001];
long long sa[2001];
const int M = int(1e9) + 7;
int main() {
cin >> N >> K;
for (int i = 0; i < N; i++) {
cin >> a[i];
sa[i] = a[i];
}
//
sort(sa, sa + N);
//
long long ans = 0;
for (int i = 0; i < N; i++) {
long long subans = 0;
for (int j = i + 1; j < N; j++) {
subans += (a[i] > a[j]);
}
ans += (subans * K);
ans %= M;
//
for (int j = 0; j < N; j++) {
if (sa[j] == a[i]) {
ans += ((K - 1) * (K) / 2 * (j));
ans %= M;
break;
}
}
}
//
cout << ans;
}
|
#include <bits/stdc++.h>
using namespace std;
long long N, K;
long long a[2001];
long long sa[2001];
const int M = int(1e9) + 7;
int main() {
cin >> N >> K;
for (int i = 0; i < N; i++) {
cin >> a[i];
sa[i] = a[i];
}
//
sort(sa, sa + N);
//
long long ans = 0;
for (int i = 0; i < N; i++) {
long long subans = 0;
for (int j = i + 1; j < N; j++) {
subans += (a[i] > a[j]);
}
ans += (subans * K);
ans %= M;
//
for (int j = 0; j < N; j++) {
if (sa[j] == a[i]) {
ans += ((K - 1) * (K) / 2 % M * (j) % M);
ans %= M;
break;
}
}
}
//
cout << ans;
}
|
[
"assignment.change"
] | 731,856
| 731,857
|
u206133536
|
cpp
|
p02928
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1000000007;
int main() {
ll N, K;
cin >> N >> K;
vector<ll> A(N + 10);
for (int i = 0; i < N; i++)
cin >> A[i];
ll ans = 0;
for (int i = 0; i < N; i++) {
ll cnt = 0, cnt2 = 0;
for (int j = 0; j < N; j++) {
if (A[i] > A[j]) {
cnt++;
}
if (A[i] > A[j] && i < j)
cnt2++;
}
ll memo = (cnt * (K - 1) * K / 2 % mod + K * cnt2 % mod) % mod;
ans = (ans + memo) % mod;
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1000000007;
int main() {
ll N, K;
cin >> N >> K;
vector<ll> A(N + 10);
for (int i = 0; i < N; i++)
cin >> A[i];
ll ans = 0;
for (int i = 0; i < N; i++) {
ll cnt = 0, cnt2 = 0;
for (int j = 0; j < N; j++) {
if (A[i] > A[j]) {
cnt++;
}
if (A[i] > A[j] && i < j)
cnt2++;
}
ll memo = ((K - 1) * K / 2 % mod * cnt % mod + K * cnt2 % mod) % mod;
ans = (ans + memo) % mod;
}
cout << ans << endl;
}
|
[
"expression.operation.binary.remove"
] | 731,860
| 731,861
|
u302870145
|
cpp
|
p02928
|
//
// main.cpp
// upgranet
//
// Created by Dong Truong on 7/5/19.
// Copyright © 2019 Dong Truong. All rights reserved.
//
#include <algorithm>
#include <fstream>
#include <iostream>
#include <queue>
#include <stdio.h>
#include <vector>
using namespace std;
#define maxn 1000005
#define gh 1005
#define long long long
const long cm = 1e9 + 7;
long n, k, a[maxn];
void nhap() {
cin >> n >> k;
long sl = 0, kq = 0;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
for (int j = 1; j < i; ++j)
if (a[i] < a[j])
sl = (sl + 1) % cm;
}
kq = (sl * k) % cm;
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= n; ++j)
if (a[j] < a[i]) {
long o = (k * (k - 1)) % cm;
kq = kq + o / 2;
// if (i>j) --kq;
kq = kq % cm;
}
cout << kq;
}
int main(int argc, const char *argv[]) {
// freopen("a.inp","r",stdin);
nhap();
return 0;
}
|
//
// main.cpp
// upgranet
//
// Created by Dong Truong on 7/5/19.
// Copyright © 2019 Dong Truong. All rights reserved.
//
#include <algorithm>
#include <fstream>
#include <iostream>
#include <queue>
#include <stdio.h>
#include <vector>
using namespace std;
#define maxn 1000005
#define gh 1005
#define long long long
const long cm = 1e9 + 7;
long n, k, a[maxn];
void nhap() {
cin >> n >> k;
long sl = 0, kq = 0;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
for (int j = 1; j < i; ++j)
if (a[i] < a[j])
sl = (sl + 1) % cm;
}
kq = (sl * k) % cm;
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= n; ++j)
if (a[j] < a[i]) {
long o = (k * (k - 1) / 2) % cm;
kq = kq + o;
kq = kq % cm;
}
cout << kq;
}
int main(int argc, const char *argv[]) {
// freopen("a.inp","r",stdin);
nhap();
return 0;
}
|
[
"expression.operation.binary.remove"
] | 731,862
| 731,863
|
u224557577
|
cpp
|
p02928
|
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"
#include "ext/rope"
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); ++i)
#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define f first
#define s second
template <class T>
using Tree =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM =
chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
const ll MOD = 1e9 + 7;
ll n, k;
vector<ll> a, t, p;
int main() {
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> k;
a.assign(n, 0);
t.assign(n, 0);
p.assign(n, 0);
F0R(i, n) cin >> a[i];
F0R(i, n) {
FOR(j, i + 1, n) {
if (a[j] < a[i])
t[j]++;
}
}
F0R(i, n) F0R(j, n) if (a[j] > a[i]) p[i]++;
ll res = 0;
F0R(i, n) {
res += t[i] * (k) + p[i] * ((k - 1) * k) / 2;
res %= MOD;
}
cout << res;
return 0;
}
|
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"
#include "ext/rope"
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); ++i)
#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define f first
#define s second
template <class T>
using Tree =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM =
chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
const ll MOD = 1e9 + 7;
ll n, k;
vector<ll> a, t, p;
int main() {
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> k;
a.assign(n, 0);
t.assign(n, 0);
p.assign(n, 0);
F0R(i, n) cin >> a[i];
F0R(i, n) {
FOR(j, i + 1, n) {
if (a[j] < a[i])
t[j]++;
}
}
F0R(i, n) F0R(j, n) if (a[j] > a[i]) p[i]++;
ll res = 0;
F0R(i, n) {
res += t[i] * (k) + p[i] * ((((k - 1) * k) / 2) % MOD);
res %= MOD;
}
cout << res;
return 0;
}
|
[] | 731,864
| 731,865
|
u712630284
|
cpp
|
p02928
|
#define _CRT_SECURE_NO_WARNINGS
using namespace std;
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int arr[100000];
long long MOD = 1000000007;
int main() {
long long N, K;
cin >> N >> K;
for (int i = 0; i < N; i++) {
cin >> arr[i];
}
long long ans = 0;
for (int i = 0; i < N; i++) {
long long less_inv = 0, gre_inv = 0;
for (int j = 0; j < N; j++) {
if (j < i && arr[i] > arr[j])
less_inv++;
if (j > i && arr[i] > arr[j])
gre_inv++;
}
ans += (less_inv * (K * (K - 1) / 2) % MOD) % MOD;
ans %= MOD;
ans += (gre_inv * ((K * (K + 1)) / 2) % MOD) % MOD;
ans %= MOD;
}
cout << ans;
}
|
#define _CRT_SECURE_NO_WARNINGS
using namespace std;
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int arr[100000];
long long MOD = 1000000007;
int main() {
long long N, K;
cin >> N >> K;
for (int i = 0; i < N; i++) {
cin >> arr[i];
}
long long ans = 0;
for (int i = 0; i < N; i++) {
long long less_inv = 0, gre_inv = 0;
for (int j = 0; j < N; j++) {
if (j < i && arr[i] > arr[j])
less_inv++;
if (j > i && arr[i] > arr[j])
gre_inv++;
}
ans += (less_inv * ((K * (K - 1) / 2) % MOD)) % MOD;
ans %= MOD;
ans += (gre_inv * ((K * (K + 1) / 2) % MOD)) % MOD;
ans %= MOD;
}
cout << ans;
}
|
[] | 731,868
| 731,869
|
u734321328
|
cpp
|
p02928
|
#include <iostream>
#include <vector>
using namespace std;
int main() {
long long n, k;
cin >> n >> k;
vector<long long> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
vector<long long> cnt_a(n, 0), cnt_s(n, 0);
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (a[i] > a[j]) {
cnt_a[i]++;
if (i < j) {
cnt_s[i]++;
}
}
}
}
long long res = 0;
for (int i = 0; i < n; i++) {
res += k * (k - 1) / 2 * cnt_a[i];
res %= 1000000007;
res += k * cnt_s[i];
res %= 1000000007;
}
cout << res << endl;
}
|
#include <iostream>
#include <vector>
using namespace std;
int main() {
long long n, k;
cin >> n >> k;
vector<long long> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
vector<long long> cnt_a(n, 0), cnt_s(n, 0);
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (a[i] > a[j]) {
cnt_a[i]++;
if (i < j) {
cnt_s[i]++;
}
}
}
}
long long res = 0;
for (int i = 0; i < n; i++) {
res += ((k * (k - 1) / 2) % 1000000007) * cnt_a[i];
res %= 1000000007;
res += k * cnt_s[i];
res %= 1000000007;
}
cout << res << endl;
}
|
[] | 731,878
| 731,879
|
u185690073
|
cpp
|
p02928
|
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i, s, e) for (i64(i) = (s); (i) < (e); (i)++)
#define all(x) x.begin(), x.end()
#define let auto const
int main() {
i64 N, K;
cin >> N >> K;
vector<i64> A(N);
rep(i, 0, N) cin >> A[i];
i64 mod = 1e9 + 7;
i64 AA = 0;
map<i64, i64> mp;
rep(i, 0, N) { mp[A[i]]++; }
rep(i, 0, N) {
rep(j, 0, i) {
if (A[i] < A[j]) {
AA++;
}
}
}
i64 BB = 0;
i64 added = 0;
for (auto p : mp) {
i64 a = p.first;
i64 cnt = p.second;
i64 c = added * (K * (K - 1) / 2 % mod) % mod;
i64 d = cnt * d % mod;
BB = (BB + d) % mod;
added += cnt;
}
cout << ((AA * K) % mod + BB) % mod << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i, s, e) for (i64(i) = (s); (i) < (e); (i)++)
#define all(x) x.begin(), x.end()
#define let auto const
int main() {
i64 N, K;
cin >> N >> K;
vector<i64> A(N);
rep(i, 0, N) cin >> A[i];
i64 mod = 1e9 + 7;
i64 AA = 0;
map<i64, i64> mp;
rep(i, 0, N) { mp[A[i]]++; }
rep(i, 0, N) {
rep(j, 0, i) {
if (A[i] < A[j]) {
AA++;
}
}
}
i64 BB = 0;
i64 added = 0;
for (auto p : mp) {
i64 a = p.first;
i64 cnt = p.second;
i64 c = added * (K * (K - 1) / 2 % mod) % mod;
i64 d = cnt * c % mod;
BB = (BB + d) % mod;
added += cnt;
}
cout << ((AA * K) % mod + BB) % mod << endl;
}
|
[
"identifier.change",
"expression.operation.binary.change"
] | 731,882
| 731,883
|
u852585808
|
cpp
|
p02928
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define mod 1000000007
int main() {
ll N, K;
cin >> N >> K;
vector<int> A(N);
for (int i = 0; i < N; ++i) {
cin >> A[i];
}
vector<ll> v1(N, 0);
for (int i = 0; i < N; ++i) {
for (int j = i + 1; j < N; ++j) {
if (A[i] > A[j])
v1[i]++;
}
}
vector<ll> v2(N, 0);
for (int i = 0; i < N; ++i) {
for (int j = 0; j < N; ++j) {
if (A[i] > A[j])
v2[i]++;
}
}
ll ans = 0;
ll temp = 0;
for (int i = 0; i < N; ++i) {
temp += v1[i];
}
temp = temp * K % mod;
ans += temp;
if (K == 1) {
cout << ans;
return 0;
}
ll s = K * (K - 1) / 2;
for (int i = 0; i < N; ++i) {
ans += s * v2[i];
ans %= mod;
}
cout << ans;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define mod 1000000007
int main() {
ll N, K;
cin >> N >> K;
vector<int> A(N);
for (int i = 0; i < N; ++i) {
cin >> A[i];
}
vector<ll> v1(N, 0);
for (int i = 0; i < N; ++i) {
for (int j = i + 1; j < N; ++j) {
if (A[i] > A[j])
v1[i]++;
}
}
vector<ll> v2(N, 0);
for (int i = 0; i < N; ++i) {
for (int j = 0; j < N; ++j) {
if (A[i] > A[j])
v2[i]++;
}
}
ll ans = 0;
ll temp = 0;
for (int i = 0; i < N; ++i) {
temp += v1[i];
}
temp = temp * K % mod;
ans += temp;
if (K == 1) {
cout << ans;
return 0;
}
ll s = K * (K - 1) / 2;
s %= mod;
for (int i = 0; i < N; ++i) {
ans += s * v2[i];
ans %= mod;
}
cout << ans;
return 0;
}
|
[
"assignment.add"
] | 731,884
| 731,885
|
u590088474
|
cpp
|
p02928
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
#define endl "\n"
const ll INF = 1e15;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
const double PI = acos(-1.0);
const int N = 2005;
ll n, k, a[N];
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL), cout.tie(NULL);
cin >> n >> k;
for (int i = 0; i < n; ++i)
cin >> a[i];
ll ans = 0, sum = 0;
for (int i = 0; i < n; ++i) {
ll g = 0;
for (int j = 0; j < n; ++j)
if (a[j] < a[i])
++g;
(ans += max((k * (k - 1) / 2) * g, 0ll)) %= MOD;
for (int j = i + 1; j < n; ++j)
if (a[j] < a[i])
(ans += k) %= MOD;
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
#define endl "\n"
const ll INF = 1e15;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
const double PI = acos(-1.0);
const int N = 2005;
ll n, k, a[N];
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL), cout.tie(NULL);
cin >> n >> k;
for (int i = 0; i < n; ++i)
cin >> a[i];
ll ans = 0, sum = 0;
for (int i = 0; i < n; ++i) {
ll g = 0;
for (int j = 0; j < n; ++j)
if (a[j] < a[i])
++g;
(ans += max(((k * (k - 1) / 2) % MOD) * g, 0ll)) %= MOD;
for (int j = i + 1; j < n; ++j)
if (a[j] < a[i])
(ans += k) %= MOD;
}
cout << ans << endl;
}
|
[
"call.arguments.change"
] | 731,886
| 731,887
|
u824402098
|
cpp
|
p02928
|
// B - Kleene Inversion
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
int main(int argc, char *argv[]) {
long long n, k;
cin >> n >> k;
vector<int> a(n);
for (int i = 0; i < n; i++)
cin >> a[i];
vector<long long> c(n), d(n);
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++)
if (a[i] > a[j])
c[i]++;
for (int j = i + 1; j < n; j++)
if (a[i] > a[j])
d[i]++;
}
long long ans = 0;
for (int i = 0; i < n; i++) {
ans = (ans + d[i] * k % MOD) % MOD;
ans = (ans + c[i] * (k * (k - 1) / 2) % MOD) % MOD;
}
cout << ans << endl;
return 0;
}
|
// B - Kleene Inversion
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
int main(int argc, char *argv[]) {
long long n, k;
cin >> n >> k;
vector<int> a(n);
for (int i = 0; i < n; i++)
cin >> a[i];
vector<long long> c(n), d(n);
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++)
if (a[i] > a[j])
c[i]++;
for (int j = i + 1; j < n; j++)
if (a[i] > a[j])
d[i]++;
}
long long ans = 0;
for (int i = 0; i < n; i++) {
ans = (ans + d[i] * k % MOD) % MOD;
ans = (ans + c[i] * ((k * (k - 1) / 2) % MOD) % MOD) % MOD;
}
cout << ans << endl;
return 0;
}
|
[
"assignment.change"
] | 731,895
| 731,896
|
u839953699
|
cpp
|
p02928
|
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
typedef char SINT8;
typedef short SINT16;
typedef int SINT32;
typedef long long SINT64;
typedef double DOUBLE;
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define ABS(a) ((a) > (0) ? (a) : -(a))
#define rep(i, a, b) for (SINT64(i) = SINT64(a); (i) < SINT64(b); (i)++)
#define rrep(i, a, b) for (SINT64(i) = SINT64(a); (i) >= SINT64(b); (i)--)
#define put(a) cout << (a) << endl
#define puts(a) cout << (a) << " "
#define INF 1000000001
#define MOD 1000000007
#define INF64 1000000000000000001
#define F first
#define S second
#define Pii pair<SINT32, SINT32>
#define Pll pair<SINT64, SINT64>
#define Piii pair<SINT32, pair<SINT32, SINT32>>
#define Plll pair<SINT64, pair<SINT64, SINT64>>
#define Vll(a, b, c) vector<vector<SINT64>> (a)((b),vector<SINT64>((c))
#define Vlll(a, b, c, d) vector<vector<vector<SINT64>>> (a)((b),vector<vector<SINT64>>((c),vector<SINT64>((d)))
using namespace std;
int main() {
SINT64 N;
cin >> N;
SINT64 M;
cin >> M;
vector<SINT64> data(N);
vector<SINT64> cnt(N, 0);
vector<SINT64> cnt2(N, 0);
SINT64 ans = 0;
rep(i, 0, N) {
cin >> data[i];
rep(j, 0, i) {
if (data[j] > data[i]) {
cnt[j]++;
}
}
}
rep(i, 0, N) {
rep(j, 0, N) {
if (data[j] < data[i]) {
cnt2[i]++;
}
}
}
/*
rep(i,0,N) {
puts(cnt[i]);
} cout << endl;
rep(i,0,N) {
puts(cnt2[i]);
} cout << endl;
*/
SINT64 buf;
M--;
if ((M % 2) == 0) {
buf = (M + 1) * (M / 2);
} else {
buf = M + (M - 1) * ((M - 1) / 2);
}
buf %= MOD;
rep(i, 0, N) {
ans += cnt[i] * (M + 1);
ans %= MOD;
ans += cnt2[i] * (buf);
ans %= MOD;
}
put(ans);
return 0;
}
// vector<vector<SINT64>> data(N,vector<SINT32>(3));
////2次元配列 vector<vector<vector<SINT64>>>
//data(N,vector<vector<SINT64>>(3,vector<SINT64>(3))); //3次元配列
// Vll(data,N,N); //2次元配列
// Vlll(data,N,N,N); //3次元配列
// sort(data.begin(),data.end());
// sort(data.begin(),data.end(),std::greater<SINT64>());
// __gcd(A,B);
/* 複数条件ソート
bool sortcompare(Pll A, Pll B) {
if(A.F == B.F){
return A.S > B.S;
} else {
return A.F < B.F;
}
}
sort(data.begin(),data.end(),sortcompare);
*/
// タプル
// vector<tuple<SINT64,SINT64,SINT64>> edges;
// edges.emplace_back(a,b,c);
// cout << get<0>(edges[i]);
// cout << get<1>(edges[i]);
// cout << get<2>(edges[i]);
// data.emplace_back(BUF); //後ろに追加
// data.erase(std::unique(data.begin(), data.end()), data.end());
// //ソート後に使用 同じ値を消す
// data.insert(data.begin() + X, 0); //X番目の要素に0を挿入
// 隣接リスト
// vector<vector<SINT64>> data(N);
// data[ A ].emplace_back( B );
/*
vector<Pll> data(N);
rep(i,0,N) {
cin >> data[i].F;
cin >> data[i].S;
}
sort(data.begin(),data.end());
*/
/*
vector<Plll> data(N);
rep(i,0,N) {
cin >> data[i].F;
cin >> data[i].S.F;
cin >> data[i].S.S;
}
sort(data.begin(),data.end());
*/
// lower_boundは値がなければ最大値(.size())を返す
// posi = lower_bound(data.begin(),data.end(), X) - data.begin();
// // X以上を探す posi = lower_bound(data.begin(),data.end(),make_pair(X,0)) -
// data.begin(); //pair
/* 文字列回転
string N;
cin >> N;
N = N[N.length()-1] + N.substr(0,N.length()-1);
s = to_string(i); //ストリング変換
*/
/* 文字列合成
string N,M;
cin >> N >> M;
SINT64 ans = 0;
ans = stoi(N+M);
*/
/*
//ワーシャルフロイド
vector<vector<SINT32>> dist(N,vector<SINT32>(N));
rep(i,0,N) {
rep(j,0,N) {
if (i != j) {
dist[i][j] = INF;
}
}
}
rep(k,0,N) {
rep(i,0,N) {
rep(j,0,N) {
dist[i][j] = MIN(dist[i][j], dist[i][k]+dist[k][j]);
}
}
}
*/
/* 優先度付きキュー
priority_queue<SINT64, vector<SINT64>, greater<SINT64>> bufq;
//小さいほうから取り出せる priority_queue<SINT64, vector<SINT64>> bufq;
//大きいほうから取り出せる
bufq.push(X); //X を挿入
bufq.top(); //先頭データ読み
bufq.pop(); //先頭データ削除
*/
/* キュー
queue<SINT64> bufq; //宣言
bufq.push(0); //挿入
bufq.front(); //先頭データ読み
bufq.pop(); //先頭データ削除
*/
/* SET コンテナ
set<SINT64> data;
data.insert(X); //X を挿入
data.erase(data.begin()); //先頭を削除
data.erase(--data.end()); //末尾を削除
*data.begin(); //先頭要素にアクセス
*data.rbegin(); //末尾要素にアクセス
//全表示
set<SINT64>::iterator it; //イテレータを用意
for(it = data.begin(); it != data.end(); it++) {
cout << *it << " ";
}
cout << endl;
//N番目を一部表示
set<SINT64>::iterator it; // イテレータを用意
it = data.begin();
rep (i,0,N) {
it++;
}
cout << *it << endl;
*/
/* map
map<string,SINT32> mp;
SINT32 N = 0;
SINT32 mx = 0;
cin >> N;
for (SINT32 i = 0; i < N; i++) {
string s;
cin >> s;
mp[s]++;
}
for(auto it=mp.begin();it!=mp.end();it++) {
mx=max(mx,it->second);
}
*/
/*
//順列全表示
//sortしてからでないと全列挙にならない
sort(data.begin(),data.end());
do {
cout << buf << endl;
rep(i,0,R) {
cout << data[i] << " ";
}
cout << endl;
} while (next_permutation(data.begin(),data.end()));
*/
// 桁指定表示
// ans = ans * M_PI;
// cout << setprecision(15) << ans << endl;
// 逆元 コンビネーション
/*
SINT64 modpow(SINT64 a, SINT64 p) {
if (p == 0) return 1;
if (p % 2 == 0) {
//pが偶数の時
SINT64 halfP = p / 2;
SINT64 half = modpow(a, halfP);
//a^(p/2) をhalfとして、half*halfを計算
return half * half % MOD;
} else {
//pが奇数の時は、偶数にするために1減らす
return a * modpow(a, p - 1) % MOD;
}
}
SINT64 calcComb(SINT64 a, SINT64 b) {
SINT64 Mul = 1;
SINT64 Div = 1;
SINT64 ans = 0;
if (b > a - b) {
return calcComb(a, a - b);
}
rep(i,0,b) {
Mul *= (a - i);
Div *= (i + 1);
Mul %= MOD;
Div %= MOD;
}
ans = Mul * modpow(Div, MOD - 2) % MOD;
return ans;
}
*/
/* UNION FIND
class UnionFind {
public:
vector<SINT64> parent;
UnionFind(SINT64 N) {
parent = vector<SINT64>(N+10, -1); //少し多めに
}
SINT64 root(SINT64 A) {
if (parent[A] < 0) {
return A;
} else {
parent[A] = root(parent[A]);
return parent[A];
}
}
SINT64 size(SINT64 A) {
return parent[root(A)] * (-1);
}
bool judge(SINT64 A, SINT64 B) {
A = root(A);
B = root(B);
if (A == B) {
return true; //同じグループ
} else {
return false; //違うグループ
}
}
void connect(SINT64 A, SINT64 B) {
A = root(A);
B = root(B);
if (A != B) {
if (size(A) < size(B)) {
swap(A, B);
}
parent[A] += parent[B];
parent[B] = A;
}
}
};
UnionFind uni(N);
*/
|
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
typedef char SINT8;
typedef short SINT16;
typedef int SINT32;
typedef long long SINT64;
typedef double DOUBLE;
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define ABS(a) ((a) > (0) ? (a) : -(a))
#define rep(i, a, b) for (SINT64(i) = SINT64(a); (i) < SINT64(b); (i)++)
#define rrep(i, a, b) for (SINT64(i) = SINT64(a); (i) >= SINT64(b); (i)--)
#define put(a) cout << (a) << endl
#define puts(a) cout << (a) << " "
#define INF 1000000001
#define MOD 1000000007
#define INF64 1000000000000000001
#define F first
#define S second
#define Pii pair<SINT32, SINT32>
#define Pll pair<SINT64, SINT64>
#define Piii pair<SINT32, pair<SINT32, SINT32>>
#define Plll pair<SINT64, pair<SINT64, SINT64>>
#define Vll(a, b, c) vector<vector<SINT64>> (a)((b),vector<SINT64>((c))
#define Vlll(a, b, c, d) vector<vector<vector<SINT64>>> (a)((b),vector<vector<SINT64>>((c),vector<SINT64>((d)))
using namespace std;
int main() {
SINT64 N;
cin >> N;
SINT64 M;
cin >> M;
vector<SINT64> data(N);
vector<SINT64> cnt(N, 0);
vector<SINT64> cnt2(N, 0);
SINT64 ans = 0;
rep(i, 0, N) {
cin >> data[i];
rep(j, 0, i) {
if (data[j] > data[i]) {
cnt[j]++;
}
}
}
rep(i, 0, N) {
rep(j, 0, N) {
if (data[j] < data[i]) {
cnt2[i]++;
}
}
}
/*
rep(i,0,N) {
puts(cnt[i]);
} cout << endl;
rep(i,0,N) {
puts(cnt2[i]);
} cout << endl;
*/
SINT64 buf;
M--;
if ((M % 2) == 0) {
buf = (M + 1) * (M / 2);
} else {
buf = M + (M) * ((M - 1) / 2);
}
buf %= MOD;
rep(i, 0, N) {
ans += cnt[i] * (M + 1);
ans %= MOD;
ans += cnt2[i] * (buf);
ans %= MOD;
}
put(ans);
return 0;
}
// vector<vector<SINT64>> data(N,vector<SINT32>(3));
////2次元配列 vector<vector<vector<SINT64>>>
//data(N,vector<vector<SINT64>>(3,vector<SINT64>(3))); //3次元配列
// Vll(data,N,N); //2次元配列
// Vlll(data,N,N,N); //3次元配列
// sort(data.begin(),data.end());
// sort(data.begin(),data.end(),std::greater<SINT64>());
// __gcd(A,B);
/* 複数条件ソート
bool sortcompare(Pll A, Pll B) {
if(A.F == B.F){
return A.S > B.S;
} else {
return A.F < B.F;
}
}
sort(data.begin(),data.end(),sortcompare);
*/
// タプル
// vector<tuple<SINT64,SINT64,SINT64>> edges;
// edges.emplace_back(a,b,c);
// cout << get<0>(edges[i]);
// cout << get<1>(edges[i]);
// cout << get<2>(edges[i]);
// data.emplace_back(BUF); //後ろに追加
// data.erase(std::unique(data.begin(), data.end()), data.end());
// //ソート後に使用 同じ値を消す
// data.insert(data.begin() + X, 0); //X番目の要素に0を挿入
// 隣接リスト
// vector<vector<SINT64>> data(N);
// data[ A ].emplace_back( B );
/*
vector<Pll> data(N);
rep(i,0,N) {
cin >> data[i].F;
cin >> data[i].S;
}
sort(data.begin(),data.end());
*/
/*
vector<Plll> data(N);
rep(i,0,N) {
cin >> data[i].F;
cin >> data[i].S.F;
cin >> data[i].S.S;
}
sort(data.begin(),data.end());
*/
// lower_boundは値がなければ最大値(.size())を返す
// posi = lower_bound(data.begin(),data.end(), X) - data.begin();
// // X以上を探す posi = lower_bound(data.begin(),data.end(),make_pair(X,0)) -
// data.begin(); //pair
/* 文字列回転
string N;
cin >> N;
N = N[N.length()-1] + N.substr(0,N.length()-1);
s = to_string(i); //ストリング変換
*/
/* 文字列合成
string N,M;
cin >> N >> M;
SINT64 ans = 0;
ans = stoi(N+M);
*/
/*
//ワーシャルフロイド
vector<vector<SINT32>> dist(N,vector<SINT32>(N));
rep(i,0,N) {
rep(j,0,N) {
if (i != j) {
dist[i][j] = INF;
}
}
}
rep(k,0,N) {
rep(i,0,N) {
rep(j,0,N) {
dist[i][j] = MIN(dist[i][j], dist[i][k]+dist[k][j]);
}
}
}
*/
/* 優先度付きキュー
priority_queue<SINT64, vector<SINT64>, greater<SINT64>> bufq;
//小さいほうから取り出せる priority_queue<SINT64, vector<SINT64>> bufq;
//大きいほうから取り出せる
bufq.push(X); //X を挿入
bufq.top(); //先頭データ読み
bufq.pop(); //先頭データ削除
*/
/* キュー
queue<SINT64> bufq; //宣言
bufq.push(0); //挿入
bufq.front(); //先頭データ読み
bufq.pop(); //先頭データ削除
*/
/* SET コンテナ
set<SINT64> data;
data.insert(X); //X を挿入
data.erase(data.begin()); //先頭を削除
data.erase(--data.end()); //末尾を削除
*data.begin(); //先頭要素にアクセス
*data.rbegin(); //末尾要素にアクセス
//全表示
set<SINT64>::iterator it; //イテレータを用意
for(it = data.begin(); it != data.end(); it++) {
cout << *it << " ";
}
cout << endl;
//N番目を一部表示
set<SINT64>::iterator it; // イテレータを用意
it = data.begin();
rep (i,0,N) {
it++;
}
cout << *it << endl;
*/
/* map
map<string,SINT32> mp;
SINT32 N = 0;
SINT32 mx = 0;
cin >> N;
for (SINT32 i = 0; i < N; i++) {
string s;
cin >> s;
mp[s]++;
}
for(auto it=mp.begin();it!=mp.end();it++) {
mx=max(mx,it->second);
}
*/
/*
//順列全表示
//sortしてからでないと全列挙にならない
sort(data.begin(),data.end());
do {
cout << buf << endl;
rep(i,0,R) {
cout << data[i] << " ";
}
cout << endl;
} while (next_permutation(data.begin(),data.end()));
*/
// 桁指定表示
// ans = ans * M_PI;
// cout << setprecision(15) << ans << endl;
// 逆元 コンビネーション
/*
SINT64 modpow(SINT64 a, SINT64 p) {
if (p == 0) return 1;
if (p % 2 == 0) {
//pが偶数の時
SINT64 halfP = p / 2;
SINT64 half = modpow(a, halfP);
//a^(p/2) をhalfとして、half*halfを計算
return half * half % MOD;
} else {
//pが奇数の時は、偶数にするために1減らす
return a * modpow(a, p - 1) % MOD;
}
}
SINT64 calcComb(SINT64 a, SINT64 b) {
SINT64 Mul = 1;
SINT64 Div = 1;
SINT64 ans = 0;
if (b > a - b) {
return calcComb(a, a - b);
}
rep(i,0,b) {
Mul *= (a - i);
Div *= (i + 1);
Mul %= MOD;
Div %= MOD;
}
ans = Mul * modpow(Div, MOD - 2) % MOD;
return ans;
}
*/
/* UNION FIND
class UnionFind {
public:
vector<SINT64> parent;
UnionFind(SINT64 N) {
parent = vector<SINT64>(N+10, -1); //少し多めに
}
SINT64 root(SINT64 A) {
if (parent[A] < 0) {
return A;
} else {
parent[A] = root(parent[A]);
return parent[A];
}
}
SINT64 size(SINT64 A) {
return parent[root(A)] * (-1);
}
bool judge(SINT64 A, SINT64 B) {
A = root(A);
B = root(B);
if (A == B) {
return true; //同じグループ
} else {
return false; //違うグループ
}
}
void connect(SINT64 A, SINT64 B) {
A = root(A);
B = root(B);
if (A != B) {
if (size(A) < size(B)) {
swap(A, B);
}
parent[A] += parent[B];
parent[B] = A;
}
}
};
UnionFind uni(N);
*/
|
[
"expression.operation.binary.remove"
] | 731,899
| 731,900
|
u824905100
|
cpp
|
p02928
|
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdint>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
using ull = unsigned long long;
constexpr ll INF = 1'000'000'000'000'000'000;
namespace utils {
#define ALL(x) begin(x), end(x)
#define rALL(x) rbegin(x), rend(x)
template <class T, class Compare>
using p_queue = priority_queue<T, vector<T>, Compare>;
template <class T> using min_queue = p_queue<T, greater<T>>;
template <class T> using max_queue = p_queue<T, less<T>>;
template <class T> bool min_update(T &X, const T &A) {
if (X > A) {
X = A;
return true;
}
return false;
}
template <class T> bool max_update(T &X, const T &A) {
if (X < A) {
X = A;
return true;
}
return false;
}
using V_Set = unordered_set<int>;
using E_Set = unordered_map<int, V_Set>;
ll operator"" _64(unsigned long long x) { return ll(x); }
ull operator"" _64u(unsigned long long x) { return ull(x); }
template <class T> vector<T> make_vector(int n, T t) { return vector<T>(n, t); }
template <class... Ts> auto make_vector(int n, Ts... ts) {
return vector<decltype(make_vector(ts...))>(n, make_vector(ts...));
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
for (auto &&x : v) {
os << x << ' ';
}
cout << endl;
return os;
}
} // namespace utils
using namespace utils;
// Residue Class Ring
namespace xelmh_RCR {
class RCR {
// Residue Class Ring
static constexpr ll NIL = -1;
ll val;
public:
static int64_t MOD;
RCR(ll x) : val(x >= 0 ? x % MOD : MOD - (-x) % MOD) {}
RCR(signed x) : val(x >= 0 ? x % MOD : MOD - (-x) % MOD) {}
RCR(ull x) : val(x % MOD) {}
RCR(unsigned x) : val(x % MOD) {}
RCR() : val{NIL} {}
bool is_nil() { return val == NIL; }
RCR pow(ll n) const {
ll r = 1, a = val;
while (n) {
if (n & 1) {
r *= a;
r %= MOD;
}
a *= a;
a %= MOD;
n /= 2;
}
return {n};
}
RCR inv() const { /* return Inverse */
assert(val != 0);
return this->pow(MOD - 2);
}
void operator+=(const RCR &a) {
val += a.val;
if (val >= MOD)
val -= MOD;
}
void operator-=(const RCR &a) {
val -= a.val;
if (val < 0)
val += MOD;
}
void operator*=(const RCR &a) {
val *= a.val;
val %= MOD;
}
void operator/=(const RCR &a) {
val *= a.inv().val;
val %= MOD;
}
RCR operator+(const RCR &x) const {
ll v = val + x.val;
return {v};
}
RCR operator-(const RCR &x) const {
ll v = val - x.val;
return {v};
}
RCR operator*(const RCR &x) const {
ll v = val * x.val;
return {v};
}
RCR operator/(const RCR &x) const {
ll v = val * x.inv().val;
return {v};
}
bool operator==(const RCR &x) const { return x.val == val; }
bool operator!=(const RCR &x) const { return x.val != val; }
friend istream &operator>>(istream &is, RCR &r) {
ll tmp;
is >> tmp;
r = tmp;
return is;
}
friend ostream &operator<<(ostream &os, const RCR &r) { return os << r.val; }
};
RCR fact(ll N) {
/* N -> N! */
static vector<RCR> cal(1, RCR{1});
assert(N >= 0);
if (cal.size() > N)
return cal[N];
else {
RCR nm = fact(N - 1);
assert(cal.size() == N);
cal.push_back(nm * N);
return cal.back();
}
}
/* N, k -> N C k */
RCR choice(ll N, ll k) {
// N! / k!(N-k!)
RCR ans = fact(N) / (fact(k) * fact(N - k));
return ans;
}
RCR operator"" _mod(unsigned long long x) { return RCR{x}; }
} // namespace xelmh_RCR
using namespace xelmh_RCR;
int64_t RCR::MOD = 1'000'000'007;
// int64_t RCR::MOD = 998'244'353;
class solver {
istream &is;
ostream &os;
public:
solver(istream &I, ostream &O) : is(I), os(O) {}
void run() {
ll N, K;
is >> N >> K;
if (!is)
return;
ll count = 0;
auto A = make_vector(N, 0);
map<ll, ll> B;
for (auto &&a : A) {
is >> a;
B[a]++;
} // end a
for (int i = 0; i < N; ++i) {
for (int j = i + 1; j < N; ++j) {
if (A[i] > A[j])
count++;
} // end j
} // end i
ll sum = 0;
RCR d = 0;
for (auto &&b : B) {
d += sum;
sum += b.second;
} // end b
RCR ans = count * K;
RCR ch = (K - 1) * K / 2;
ans += d * ch;
cout << ans << endl;
}
};
int main(int argc, char *argv[]) {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << setprecision(16) << scientific;
#ifdef DEBUG
string test_cases = "test_B.txt";
cerr << test_cases << " -->" << endl;
auto fs = fstream(test_cases, fstream::in);
int loop = 0;
while (fs) {
loop++;
cout << '#' << loop << "#------\n";
solver(fs, cout).run();
}
if (loop <= 1) {
cout << "===" << endl;
while (cin)
solver(cin, cout).run();
}
#else
solver(cin, cout).run();
#endif
return 0;
}
|
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdint>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
using ull = unsigned long long;
constexpr ll INF = 1'000'000'000'000'000'000;
namespace utils {
#define ALL(x) begin(x), end(x)
#define rALL(x) rbegin(x), rend(x)
template <class T, class Compare>
using p_queue = priority_queue<T, vector<T>, Compare>;
template <class T> using min_queue = p_queue<T, greater<T>>;
template <class T> using max_queue = p_queue<T, less<T>>;
template <class T> bool min_update(T &X, const T &A) {
if (X > A) {
X = A;
return true;
}
return false;
}
template <class T> bool max_update(T &X, const T &A) {
if (X < A) {
X = A;
return true;
}
return false;
}
using V_Set = unordered_set<int>;
using E_Set = unordered_map<int, V_Set>;
ll operator"" _64(unsigned long long x) { return ll(x); }
ull operator"" _64u(unsigned long long x) { return ull(x); }
template <class T> vector<T> make_vector(int n, T t) { return vector<T>(n, t); }
template <class... Ts> auto make_vector(int n, Ts... ts) {
return vector<decltype(make_vector(ts...))>(n, make_vector(ts...));
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
for (auto &&x : v) {
os << x << ' ';
}
cout << endl;
return os;
}
} // namespace utils
using namespace utils;
// Residue Class Ring
namespace xelmh_RCR {
class RCR {
// Residue Class Ring
static constexpr ll NIL = -1;
ll val;
public:
static int64_t MOD;
RCR(ll x) : val(x >= 0 ? x % MOD : MOD - (-x) % MOD) {}
RCR(signed x) : val(x >= 0 ? x % MOD : MOD - (-x) % MOD) {}
RCR(ull x) : val(x % MOD) {}
RCR(unsigned x) : val(x % MOD) {}
RCR() : val{NIL} {}
bool is_nil() { return val == NIL; }
RCR pow(ll n) const {
ll r = 1, a = val;
while (n) {
if (n & 1) {
r *= a;
r %= MOD;
}
a *= a;
a %= MOD;
n /= 2;
}
return {n};
}
RCR inv() const { /* return Inverse */
assert(val != 0);
return this->pow(MOD - 2);
}
void operator+=(const RCR &a) {
val += a.val;
if (val >= MOD)
val -= MOD;
}
void operator-=(const RCR &a) {
val -= a.val;
if (val < 0)
val += MOD;
}
void operator*=(const RCR &a) {
val *= a.val;
val %= MOD;
}
void operator/=(const RCR &a) {
val *= a.inv().val;
val %= MOD;
}
RCR operator+(const RCR &x) const {
ll v = val + x.val;
return {v};
}
RCR operator-(const RCR &x) const {
ll v = val - x.val;
return {v};
}
RCR operator*(const RCR &x) const {
ll v = val * x.val;
return {v};
}
RCR operator/(const RCR &x) const {
ll v = val * x.inv().val;
return {v};
}
bool operator==(const RCR &x) const { return x.val == val; }
bool operator!=(const RCR &x) const { return x.val != val; }
friend istream &operator>>(istream &is, RCR &r) {
ll tmp;
is >> tmp;
r = tmp;
return is;
}
friend ostream &operator<<(ostream &os, const RCR &r) { return os << r.val; }
};
RCR fact(ll N) {
/* N -> N! */
static vector<RCR> cal(1, RCR{1});
assert(N >= 0);
if (cal.size() > N)
return cal[N];
else {
RCR nm = fact(N - 1);
assert(cal.size() == N);
cal.push_back(nm * N);
return cal.back();
}
}
/* N, k -> N C k */
RCR choice(ll N, ll k) {
// N! / k!(N-k!)
RCR ans = fact(N) / (fact(k) * fact(N - k));
return ans;
}
RCR operator"" _mod(unsigned long long x) { return RCR{x}; }
} // namespace xelmh_RCR
using namespace xelmh_RCR;
int64_t RCR::MOD = 1'000'000'007;
// int64_t RCR::MOD = 998'244'353;
class solver {
istream &is;
ostream &os;
public:
solver(istream &I, ostream &O) : is(I), os(O) {}
void run() {
ll N, K;
is >> N >> K;
if (!is)
return;
ll count = 0;
auto A = make_vector(N, 0);
map<ll, ll> B;
for (auto &&a : A) {
is >> a;
B[a]++;
} // end a
for (int i = 0; i < N; ++i) {
for (int j = i + 1; j < N; ++j) {
if (A[i] > A[j])
count++;
} // end j
} // end i
ll sum = 0;
RCR d = 0;
for (auto &&b : B) {
d += sum * b.second;
sum += b.second;
} // end b
RCR ans = count * K;
RCR ch = (K - 1) * K / 2;
ans += d * ch;
cout << ans << endl;
}
};
int main(int argc, char *argv[]) {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << setprecision(16) << scientific;
#ifdef DEBUG
string test_cases = "test_B.txt";
cerr << test_cases << " -->" << endl;
auto fs = fstream(test_cases, fstream::in);
int loop = 0;
while (fs) {
loop++;
cout << '#' << loop << "#------\n";
solver(fs, cout).run();
}
if (loop <= 1) {
cout << "===" << endl;
while (cin)
solver(cin, cout).run();
}
#else
solver(cin, cout).run();
#endif
return 0;
}
|
[
"assignment.change"
] | 731,901
| 731,902
|
u896838289
|
cpp
|
p02928
|
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
int main() {
long long N, K;
cin >> N >> K;
vector<long long> A(N);
for (int i = 0; i < N; i++) {
cin >> A.at(i);
}
vector<pair<long long, long long>> num(N);
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
if (i < j && A.at(i) > A.at(j))
num.at(i).first++;
if (A.at(i) > A.at(j))
num.at(i).second++;
}
}
long long ans = 0;
for (int i = 0; i < N; i++) {
ans += K * num.at(i).first;
ans %= MOD;
ans += K * (K - 1) / 2 * num.at(i).second;
ans %= MOD;
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
int main() {
long long N, K;
cin >> N >> K;
vector<long long> A(N);
for (int i = 0; i < N; i++) {
cin >> A.at(i);
}
vector<pair<long long, long long>> num(N);
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
if (i < j && A.at(i) > A.at(j))
num.at(i).first++;
if (A.at(i) > A.at(j))
num.at(i).second++;
}
}
long long ans = 0;
for (int i = 0; i < N; i++) {
ans += K * num.at(i).first;
ans %= MOD;
ans += (K * (K - 1) / 2) % MOD * num.at(i).second;
ans %= MOD;
}
cout << ans << endl;
}
|
[
"assignment.change"
] | 731,907
| 731,908
|
u372299304
|
cpp
|
p02928
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
int T;
const int maxN = 2e3 + 8;
const ll INF = 1e15 + 7;
const int MOD = 1e9 + 7;
int n;
int k;
int a[maxN];
int main() {
int n, k;
scanf("%d %d", &n, &k);
ll cnt = 0;
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
ll ans = 0;
for (int i = 1; i <= n; i++) {
for (int j = i + 1; j <= n; j++) {
if (a[i] > a[j]) {
cnt++;
}
}
}
for (int i = 1; i <= n; i++) {
int tmp = 0;
for (int j = 1; j <= n; j++) {
if (a[j] < a[i] && i != j) {
tmp++;
}
}
ans += (ll)k * (k - 1) / 2 * tmp % MOD;
ans %= MOD;
}
ans += cnt * k % MOD;
ans %= MOD;
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
int T;
const int maxN = 2e3 + 8;
const ll INF = 1e15 + 7;
const int MOD = 1e9 + 7;
int n;
int k;
int a[maxN];
int main() {
int n, k;
scanf("%d %d", &n, &k);
ll cnt = 0;
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
ll ans = 0;
for (int i = 1; i <= n; i++) {
for (int j = i + 1; j <= n; j++) {
if (a[i] > a[j]) {
cnt++;
}
}
}
for (int i = 1; i <= n; i++) {
int tmp = 0;
for (int j = 1; j <= n; j++) {
if (a[j] < a[i] && i != j) {
tmp++;
}
}
ans += (ll)k * (k - 1) / 2 % MOD * tmp % MOD;
ans %= MOD;
}
ans += cnt * k % MOD;
ans %= MOD;
cout << ans << endl;
return 0;
}
|
[
"assignment.change"
] | 731,909
| 731,910
|
u807919574
|
cpp
|
p02928
|
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, k, n) for (int i = k; i <= n; ++i)
#define REPR(i, k, n) for (int i = k; i >= n; --i)
#define pb push_back
#define F first
#define S second
#define I insert
#define mp make_pair
#define sz(a) (int)((a).size())
#define all(a) (a).begin(), (a).end()
#define debug1(a) cout << " " << #a << " : " << a << "\n"
#define debug2(a, b) \
cout << " " << #a << " : " << a << " " << #b << " : " << b << "\n"
#define debug3(a, b, c) \
cout << " " << #a << " : " << a << " " << #b << " : " << b << " " << #c \
<< " : " << c << "\n"
#define debug4(a, b, c, d) \
cout << " " << #a << " : " << a << " " << #b << " : " << b << " " << #c \
<< " : " << c << " " << #d << " : " << d << "\n"
// #define M 421412341324321
#define MOD 1000000007
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n, k;
cin >> n >> k;
int a[n];
rep(i, n) { cin >> a[i]; }
int y[n], x[n];
rep(i, n) {
int c = 0;
REP(j, 0, n - 1) {
if (a[j] < a[i])
c++;
}
y[i] = c;
// debug2(a[i],y[i]);
}
rep(i, n) {
int c = 0;
REP(j, i + 1, n - 1) {
if (a[i] > a[j])
c++;
}
x[i] = c;
// debug2(a[i],c);
}
int ans = 0;
rep(i, n) {
ans = ans + (k * x[i]) % MOD + (((k * (k - 1)) / 2) * y[i]) % MOD;
ans %= MOD;
// debug1(ans);
}
cout << ans;
}
|
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, k, n) for (int i = k; i <= n; ++i)
#define REPR(i, k, n) for (int i = k; i >= n; --i)
#define pb push_back
#define F first
#define S second
#define I insert
#define mp make_pair
#define sz(a) (int)((a).size())
#define all(a) (a).begin(), (a).end()
#define debug1(a) cout << " " << #a << " : " << a << "\n"
#define debug2(a, b) \
cout << " " << #a << " : " << a << " " << #b << " : " << b << "\n"
#define debug3(a, b, c) \
cout << " " << #a << " : " << a << " " << #b << " : " << b << " " << #c \
<< " : " << c << "\n"
#define debug4(a, b, c, d) \
cout << " " << #a << " : " << a << " " << #b << " : " << b << " " << #c \
<< " : " << c << " " << #d << " : " << d << "\n"
// #define M 421412341324321
#define MOD 1000000007
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n, k;
cin >> n >> k;
int a[n];
rep(i, n) { cin >> a[i]; }
int y[n], x[n];
rep(i, n) {
int c = 0;
REP(j, 0, n - 1) {
if (a[j] < a[i])
c++;
}
y[i] = c;
// debug2(a[i],y[int]);
}
rep(i, n) {
int c = 0;
REP(j, i + 1, n - 1) {
if (a[i] > a[j])
c++;
}
x[i] = c;
// debug2(a[i],c);
}
int ans = 0;
rep(i, n) {
ans = ans + (k * x[i]) % MOD + ((((k * (k - 1)) / 2) % MOD) * y[i]) % MOD;
ans %= MOD;
// debug1(ans);
}
cout << ans;
}
|
[] | 731,918
| 731,919
|
u680850076
|
cpp
|
p02928
|
#include <bits/stdc++.h>
#define MSET(x, y) memset(x, y, sizeof(x))
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define SZ size()
#define M 100005
#define ll long long
#define ld long double
#define INF 1e18
#define endl "\n"
#define fastio \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
using namespace std;
ll MOD = pow(10, 9) + 7;
string yes = "YES\n";
string no = "NO\n";
#define PI 3.1415926535
int main() {
fastio;
ll n, k;
cin >> n >> k;
vector<ll> a;
vector<ll> wt(n, 0), vr(n, 0);
for (ll i = 0; i < n; i++) {
ll cd;
cin >> cd;
for (ll j = 0; j < a.size(); j++) {
if (a[j] > cd)
wt[j]++;
}
a.PB(cd);
}
for (ll i = 0; i < n; i++) {
for (ll j = 0; j < n; j++) {
if (a[j] < a[i])
vr[i]++;
}
}
ll ans = 0;
for (auto itr : wt) {
ans = (ans + (itr * k) % MOD) % MOD;
}
for (auto itr : vr) {
ans = (ans + (itr * (k) * (k - 1) / 2 % MOD) % MOD) % MOD;
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
#define MSET(x, y) memset(x, y, sizeof(x))
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define SZ size()
#define M 100005
#define ll long long
#define ld long double
#define INF 1e18
#define endl "\n"
#define fastio \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
using namespace std;
ll MOD = pow(10, 9) + 7;
string yes = "YES\n";
string no = "NO\n";
#define PI 3.1415926535
int main() {
fastio;
ll n, k;
cin >> n >> k;
vector<ll> a;
vector<ll> wt(n, 0), vr(n, 0);
for (ll i = 0; i < n; i++) {
ll cd;
cin >> cd;
for (ll j = 0; j < a.size(); j++) {
if (a[j] > cd)
wt[j]++;
}
a.PB(cd);
}
for (ll i = 0; i < n; i++) {
for (ll j = 0; j < n; j++) {
if (a[j] < a[i])
vr[i]++;
}
}
ll ans = 0;
for (auto itr : wt) {
ans = (ans + (itr * k) % MOD) % MOD;
}
for (auto itr : vr) {
ans = (ans + (itr * ((k) * (k - 1) / 2 % MOD)) % MOD) % MOD;
}
cout << ans << endl;
}
|
[] | 731,924
| 731,925
|
u053638061
|
cpp
|
p02928
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
ll n;
ll k;
cin >> n >> k;
vector<ll> v(n), cnt(n, 0), cn(n, 0);
for (ll i = 0; i < n; i++)
cin >> v[i];
for (ll i = 0; i < n; i++) {
for (ll j = 0; j < n; j++) {
if (v[i] > v[j]) {
cn[i]++;
if (i < j)
cnt[i]++;
}
}
}
ll ans = 0;
for (ll i = 0; i < n; i++) {
ans += k * cnt[i];
ans %= 1000000007;
ans += k * (k - 1) / 2 * cn[i];
ans %= 1000000007;
}
cout << ans;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
ll n;
ll k;
cin >> n >> k;
vector<ll> v(n), cnt(n, 0), cn(n, 0);
for (ll i = 0; i < n; i++)
cin >> v[i];
for (ll i = 0; i < n; i++) {
for (ll j = 0; j < n; j++) {
if (v[i] > v[j]) {
cn[i]++;
if (i < j)
cnt[i]++;
}
}
}
ll ans = 0;
for (ll i = 0; i < n; i++) {
ans += k * cnt[i];
ans %= 1000000007;
ans += ((k * (k - 1) / 2) % 1000000007) * cn[i];
ans %= 1000000007;
}
cout << ans;
return 0;
}
|
[] | 731,929
| 731,930
|
u664207511
|
cpp
|
p02928
|
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctype.h>
#include <deque>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <unordered_map>
#include <utility>
#include <vector>
#define _USE_MATH_DEFINES
#include <iostream>
#include <math.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, char> pic;
#define bit(x, v) ((ll)x << v)
const ll INF = 1000000007;
const int MAX = 210000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 二項係数計算
long long COM(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
int pr[100010];
void uini(int n) {
for (size_t i = 0; i <= n; i++) {
pr[i] = i;
}
}
int parent(int x) {
if (x == pr[x])
return x;
return pr[x] = parent(pr[x]);
}
bool unit(int x, int y) {
int px = parent(x);
int py = parent(y);
if (px == py)
return false;
if (px < py) {
pr[py] = px;
} else {
pr[px] = py;
}
return true;
}
ll bit[200010];
int max_n = 200000;
int pm = 0;
void add(int x) {
while (max_n >= x) {
bit[x]++;
x += x & -x;
}
}
void sub(int x) {
while (max_n >= x) {
bit[x]--;
x += x & -x;
}
}
ll merge(ll *a, int left, int mid, int right) {
ll n1 = mid - left;
ll n2 = right - mid;
vector<int> L(n1 + 1);
vector<int> R(n2 + 1);
for (size_t i = 0; i < n1; i++) {
L[i] = a[left + i];
}
for (size_t i = 0; i < n2; i++) {
R[i] = a[mid + i];
}
L[n1] = INF;
R[n2] = INF;
ll i = 0;
ll j = 0;
ll r = 0;
for (size_t k = left; k < right; k++) {
if (L[i] <= R[j]) {
a[k] = L[i];
i++;
} else {
a[k] = R[j];
r += n1 - i;
j++;
}
}
return r;
}
ll merge2(pair<int, char> *a, int left, int mid, int right) {
ll n1 = mid - left;
ll n2 = right - mid;
vector<pair<int, char>> L(n1 + 1);
vector<pair<int, char>> R(n2 + 1);
for (size_t i = 0; i < n1; i++) {
L[i] = a[left + i];
}
for (size_t i = 0; i < n2; i++) {
R[i] = a[mid + i];
}
L[n1] = make_pair(INF, ' ');
R[n2] = make_pair(INF, ' ');
ll i = 0;
ll j = 0;
ll r = 0;
for (size_t k = left; k < right; k++) {
if (L[i].first <= R[j].first) {
a[k] = L[i];
i++;
} else {
a[k] = R[j];
r += n1 - i;
j++;
}
}
return r;
}
ll mergeSort2(pair<int, char> *a, int left, int right) {
ll res = 0;
if (left + 1 < right) {
int mid = (left + right) / 2;
res = mergeSort2(a, left, mid);
res += mergeSort2(a, mid, right);
res += merge2(a, left, mid, right);
}
return res;
}
ll mergeSort(ll *a, int left, int right) {
ll res = 0;
if (left + 1 < right) {
int mid = (left + right) / 2;
res = mergeSort(a, left, mid);
res += mergeSort(a, mid, right);
res += merge(a, left, mid, right);
}
return res;
}
int partition(pair<int, char> *a, int p, int r) {
pair<int, char> x = a[r];
int i = p - 1;
for (size_t j = p; j < r; j++) {
if (a[j].first <= x.first) {
i++;
swap(a[i], a[j]);
}
}
swap(a[i + 1], a[r]);
return i + 1;
}
void quick(pair<int, char> *a, int p, int r) {
if (p < r) {
int q = partition(a, p, r);
quick(a, p, q - 1);
quick(a, q + 1, r);
}
}
ll n;
vector<pii> es[100010];
int ci = 0;
ll P[1000010];
struct Node {
int key;
int priority;
Node *parent, *left, *right;
Node(int key, int priority);
Node() {}
};
Node NIL;
Node::Node(int key, int priority) : key(key), priority(priority) {
left = &NIL;
right = &NIL;
}
Node *root = new Node();
void cenrec(Node *k) {
if (k->key == NIL.key)
return;
cenrec(k->left);
cout << " " << k->key;
cenrec(k->right);
}
void fastrec(Node *k) {
if (k->key == NIL.key)
return;
cout << " " << k->key;
fastrec(k->left);
fastrec(k->right);
}
void insert(Node *v) {
Node *y = &NIL;
Node *x = root;
while (x->key != NIL.key) {
y = x;
if (v->key < x->key) {
x = x->left;
} else {
x = x->right;
}
}
v->parent = y;
if (y->key == NIL.key) {
root = v;
} else if (v->key < y->key) {
y->left = v;
} else {
y->right = v;
}
}
Node *find(Node *k, ll v) {
if (k->key == NIL.key)
return &NIL;
if (k->key == v)
return k;
if (v < k->key)
return find(k->left, v);
return find(k->right, v);
}
void delp12(Node *x) {
if (x->key == NIL.key)
return;
Node *l = x->left;
Node *r = x->right;
Node *pr = x->parent;
if (l->key == NIL.key && r->key == NIL.key) {
if (pr->left == x) {
pr->left = &NIL;
} else
pr->right = &NIL;
} else if (l->key != NIL.key) {
if (pr->left == x) {
pr->left = l;
} else
pr->right = l;
l->parent = pr;
} else if (r->key != NIL.key) {
if (pr->left == x) {
pr->left = r;
} else
pr->right = r;
r->parent = pr;
}
}
Node *get_next(Node *k) {
if (k->key == NIL.key)
return &NIL;
Node *res = get_next(k->left);
if (res->key != NIL.key)
return res;
return k;
}
void del(Node *x) {
if (x->key == NIL.key)
return;
Node *l = x->left;
Node *r = x->right;
Node *pr = x->parent;
if (l->key != NIL.key && r->key != NIL.key) {
Node *nex = get_next(r);
x->key = nex->key;
delp12(nex);
} else {
delp12(x);
}
}
Node *rightRotate(Node *t) {
Node *s = t->left;
t->left = s->right;
s->right = t;
return s;
}
Node *leftRotate(Node *t) {
Node *s = t->right;
t->right = s->left;
s->left = t;
return s;
}
Node *_insert(Node *t, int key, int priority) {
if (t->key == NIL.key) {
return new Node(key, priority);
}
if (key == t->key) {
return t;
}
if (key < t->key) {
t->left = _insert(t->left, key, priority);
if (t->priority < t->left->priority) {
t = rightRotate(t);
}
} else {
t->right = _insert(t->right, key, priority);
if (t->priority < t->right->priority) {
t = leftRotate(t);
}
}
return t;
}
Node *delete1(Node *t, int key);
Node *_delete(Node *t, int key) {
if (t->left->key == NIL.key && t->right->key == NIL.key) {
return &NIL;
} else if (t->left->key == NIL.key) {
t = leftRotate(t);
} else if (t->right->key == NIL.key) {
t = rightRotate(t);
} else {
if (t->left->priority > t->right->priority) {
t = rightRotate(t);
} else
t = leftRotate(t);
}
return delete1(t, key);
}
Node *delete1(Node *t, int key) {
if (t->key == NIL.key) {
return &NIL;
}
if (key < t->key) {
t->left = delete1(t->left, key);
} else if (key > t->key) {
t->right = delete1(t->right, key);
} else
return _delete(t, key);
return t;
}
int H;
int left(int i) { return i * 2 + 1; }
int right(int i) { return i * 2 + 2; }
ll heap[2000010];
void maxHeapify(int i) {
int l = left(i);
int r = right(i);
int largest = 0;
if (l < H && heap[l] > heap[i])
largest = l;
else
largest = i;
if (r < H && heap[r] > heap[largest])
largest = r;
if (largest != i) {
swap(heap[i], heap[largest]);
maxHeapify(largest);
}
}
int pare(int i) { return (i - 1) / 2; }
void raise(int i) {
int l = pare(i);
if (l < 0)
return;
if (heap[l] < heap[i]) {
swap(heap[i], heap[l]);
raise(l);
}
}
void minHeapify(int i) {
int l = left(i);
int r = right(i);
int minimam = 0;
if (l < H && heap[l] < heap[i])
minimam = l;
else
minimam = i;
if (r < H && heap[r] < heap[minimam])
minimam = r;
if (minimam != i) {
swap(heap[i], heap[minimam]);
minHeapify(minimam);
}
}
void buildMaxHeap() {
for (int i = H / 2; i >= 0; i--) {
maxHeapify(i);
}
}
void solv() {
ll n, k;
cin >> n >> k;
ll a[2010];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
ll res = 0;
for (int i = n - 1; i >= 0; i--) {
ll cf = 0;
for (int j = 0; j < i; j++) {
if (a[j] > a[i])
cf++;
}
ll p1 = 0;
for (int j = i; j < n; j++) {
if (a[j] > a[i])
p1++;
}
ll al = cf + p1;
res += al * (((k - 1LL) * k) / 2LL);
res %= INF;
res += (cf * k);
res %= INF;
}
cout << res << endl;
}
int main() {
// COMinit();
solv();
return 0;
}
|
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctype.h>
#include <deque>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <unordered_map>
#include <utility>
#include <vector>
#define _USE_MATH_DEFINES
#include <iostream>
#include <math.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, char> pic;
#define bit(x, v) ((ll)x << v)
const ll INF = 1000000007;
const int MAX = 210000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 二項係数計算
long long COM(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
int pr[100010];
void uini(int n) {
for (size_t i = 0; i <= n; i++) {
pr[i] = i;
}
}
int parent(int x) {
if (x == pr[x])
return x;
return pr[x] = parent(pr[x]);
}
bool unit(int x, int y) {
int px = parent(x);
int py = parent(y);
if (px == py)
return false;
if (px < py) {
pr[py] = px;
} else {
pr[px] = py;
}
return true;
}
ll bit[200010];
int max_n = 200000;
int pm = 0;
void add(int x) {
while (max_n >= x) {
bit[x]++;
x += x & -x;
}
}
void sub(int x) {
while (max_n >= x) {
bit[x]--;
x += x & -x;
}
}
ll merge(ll *a, int left, int mid, int right) {
ll n1 = mid - left;
ll n2 = right - mid;
vector<int> L(n1 + 1);
vector<int> R(n2 + 1);
for (size_t i = 0; i < n1; i++) {
L[i] = a[left + i];
}
for (size_t i = 0; i < n2; i++) {
R[i] = a[mid + i];
}
L[n1] = INF;
R[n2] = INF;
ll i = 0;
ll j = 0;
ll r = 0;
for (size_t k = left; k < right; k++) {
if (L[i] <= R[j]) {
a[k] = L[i];
i++;
} else {
a[k] = R[j];
r += n1 - i;
j++;
}
}
return r;
}
ll merge2(pair<int, char> *a, int left, int mid, int right) {
ll n1 = mid - left;
ll n2 = right - mid;
vector<pair<int, char>> L(n1 + 1);
vector<pair<int, char>> R(n2 + 1);
for (size_t i = 0; i < n1; i++) {
L[i] = a[left + i];
}
for (size_t i = 0; i < n2; i++) {
R[i] = a[mid + i];
}
L[n1] = make_pair(INF, ' ');
R[n2] = make_pair(INF, ' ');
ll i = 0;
ll j = 0;
ll r = 0;
for (size_t k = left; k < right; k++) {
if (L[i].first <= R[j].first) {
a[k] = L[i];
i++;
} else {
a[k] = R[j];
r += n1 - i;
j++;
}
}
return r;
}
ll mergeSort2(pair<int, char> *a, int left, int right) {
ll res = 0;
if (left + 1 < right) {
int mid = (left + right) / 2;
res = mergeSort2(a, left, mid);
res += mergeSort2(a, mid, right);
res += merge2(a, left, mid, right);
}
return res;
}
ll mergeSort(ll *a, int left, int right) {
ll res = 0;
if (left + 1 < right) {
int mid = (left + right) / 2;
res = mergeSort(a, left, mid);
res += mergeSort(a, mid, right);
res += merge(a, left, mid, right);
}
return res;
}
int partition(pair<int, char> *a, int p, int r) {
pair<int, char> x = a[r];
int i = p - 1;
for (size_t j = p; j < r; j++) {
if (a[j].first <= x.first) {
i++;
swap(a[i], a[j]);
}
}
swap(a[i + 1], a[r]);
return i + 1;
}
void quick(pair<int, char> *a, int p, int r) {
if (p < r) {
int q = partition(a, p, r);
quick(a, p, q - 1);
quick(a, q + 1, r);
}
}
ll n;
vector<pii> es[100010];
int ci = 0;
ll P[1000010];
struct Node {
int key;
int priority;
Node *parent, *left, *right;
Node(int key, int priority);
Node() {}
};
Node NIL;
Node::Node(int key, int priority) : key(key), priority(priority) {
left = &NIL;
right = &NIL;
}
Node *root = new Node();
void cenrec(Node *k) {
if (k->key == NIL.key)
return;
cenrec(k->left);
cout << " " << k->key;
cenrec(k->right);
}
void fastrec(Node *k) {
if (k->key == NIL.key)
return;
cout << " " << k->key;
fastrec(k->left);
fastrec(k->right);
}
void insert(Node *v) {
Node *y = &NIL;
Node *x = root;
while (x->key != NIL.key) {
y = x;
if (v->key < x->key) {
x = x->left;
} else {
x = x->right;
}
}
v->parent = y;
if (y->key == NIL.key) {
root = v;
} else if (v->key < y->key) {
y->left = v;
} else {
y->right = v;
}
}
Node *find(Node *k, ll v) {
if (k->key == NIL.key)
return &NIL;
if (k->key == v)
return k;
if (v < k->key)
return find(k->left, v);
return find(k->right, v);
}
void delp12(Node *x) {
if (x->key == NIL.key)
return;
Node *l = x->left;
Node *r = x->right;
Node *pr = x->parent;
if (l->key == NIL.key && r->key == NIL.key) {
if (pr->left == x) {
pr->left = &NIL;
} else
pr->right = &NIL;
} else if (l->key != NIL.key) {
if (pr->left == x) {
pr->left = l;
} else
pr->right = l;
l->parent = pr;
} else if (r->key != NIL.key) {
if (pr->left == x) {
pr->left = r;
} else
pr->right = r;
r->parent = pr;
}
}
Node *get_next(Node *k) {
if (k->key == NIL.key)
return &NIL;
Node *res = get_next(k->left);
if (res->key != NIL.key)
return res;
return k;
}
void del(Node *x) {
if (x->key == NIL.key)
return;
Node *l = x->left;
Node *r = x->right;
Node *pr = x->parent;
if (l->key != NIL.key && r->key != NIL.key) {
Node *nex = get_next(r);
x->key = nex->key;
delp12(nex);
} else {
delp12(x);
}
}
Node *rightRotate(Node *t) {
Node *s = t->left;
t->left = s->right;
s->right = t;
return s;
}
Node *leftRotate(Node *t) {
Node *s = t->right;
t->right = s->left;
s->left = t;
return s;
}
Node *_insert(Node *t, int key, int priority) {
if (t->key == NIL.key) {
return new Node(key, priority);
}
if (key == t->key) {
return t;
}
if (key < t->key) {
t->left = _insert(t->left, key, priority);
if (t->priority < t->left->priority) {
t = rightRotate(t);
}
} else {
t->right = _insert(t->right, key, priority);
if (t->priority < t->right->priority) {
t = leftRotate(t);
}
}
return t;
}
Node *delete1(Node *t, int key);
Node *_delete(Node *t, int key) {
if (t->left->key == NIL.key && t->right->key == NIL.key) {
return &NIL;
} else if (t->left->key == NIL.key) {
t = leftRotate(t);
} else if (t->right->key == NIL.key) {
t = rightRotate(t);
} else {
if (t->left->priority > t->right->priority) {
t = rightRotate(t);
} else
t = leftRotate(t);
}
return delete1(t, key);
}
Node *delete1(Node *t, int key) {
if (t->key == NIL.key) {
return &NIL;
}
if (key < t->key) {
t->left = delete1(t->left, key);
} else if (key > t->key) {
t->right = delete1(t->right, key);
} else
return _delete(t, key);
return t;
}
int H;
int left(int i) { return i * 2 + 1; }
int right(int i) { return i * 2 + 2; }
ll heap[2000010];
void maxHeapify(int i) {
int l = left(i);
int r = right(i);
int largest = 0;
if (l < H && heap[l] > heap[i])
largest = l;
else
largest = i;
if (r < H && heap[r] > heap[largest])
largest = r;
if (largest != i) {
swap(heap[i], heap[largest]);
maxHeapify(largest);
}
}
int pare(int i) { return (i - 1) / 2; }
void raise(int i) {
int l = pare(i);
if (l < 0)
return;
if (heap[l] < heap[i]) {
swap(heap[i], heap[l]);
raise(l);
}
}
void minHeapify(int i) {
int l = left(i);
int r = right(i);
int minimam = 0;
if (l < H && heap[l] < heap[i])
minimam = l;
else
minimam = i;
if (r < H && heap[r] < heap[minimam])
minimam = r;
if (minimam != i) {
swap(heap[i], heap[minimam]);
minHeapify(minimam);
}
}
void buildMaxHeap() {
for (int i = H / 2; i >= 0; i--) {
maxHeapify(i);
}
}
void solv() {
ll n, k;
cin >> n >> k;
ll a[2010];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
ll res = 0;
for (int i = n - 1; i >= 0; i--) {
ll cf = 0;
for (int j = 0; j < i; j++) {
if (a[j] > a[i])
cf++;
}
ll p1 = 0;
for (int j = i; j < n; j++) {
if (a[j] > a[i])
p1++;
}
ll v = cf + p1;
res += v * ((((k - 1LL) * k) / 2LL) % INF);
res %= INF;
res += (cf * k);
res %= INF;
}
cout << res << endl;
}
int main() {
// COMinit();
solv();
return 0;
}
|
[
"variable_declaration.name.change",
"identifier.change",
"assignment.value.change",
"expression.operation.binary.change"
] | 731,931
| 731,932
|
u224756887
|
cpp
|
p02928
|
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define fs first
#define se second
#define pi 2 * acos(0)
#define PI 3.14159265358979323846264338
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int N = 100010;
const int MX = 123456;
const int mod = (int)1e9 + 7;
const int base = 1023456789;
const ull BS1 = 10000019ULL;
const int INF = (1 << 29);
template <class T> inline void fastScan(T &x) {
register char c = getchar();
int neg = 0;
x = 0;
for (; (c < 48 || c > 57) && (c != '-'); c = getchar())
;
if (c == '-') {
neg = 1;
c = getchar();
}
for (; c > 47 && c < 58; c = getchar()) {
x = (x << 1) + (x << 3) + c - 48;
}
if (neg)
x = -x;
}
// OrderedSet
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// template < typename T > using ordered_set = tree < T, null_type, greater < T
// >, rb_tree_tag, tree_order_statistics_node_update >;
int n, k;
int inp[N];
ll f(int p, int q) {
ll ret = 1ll * k * q % mod;
ll sum = (1ll * (k - 1) * k) / 2ll;
sum = 1ll * sum * p % mod;
ret += sum;
return ret % mod;
}
int main() {
fastScan(n);
fastScan(k);
for (int i = 1; i <= n; i++) {
fastScan(inp[i]);
}
ll ans = 0;
for (int i = 1; i <= n; i++) {
int p = 0, q = 0;
for (int j = 1; j <= n; j++) {
if (inp[i] < inp[j]) {
p++;
}
if (i > j) {
if (inp[i] < inp[j]) {
q++;
}
}
}
ans += f(p, q);
ans %= mod;
}
printf("%lld\n", ans);
}
|
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define fs first
#define se second
#define pi 2 * acos(0)
#define PI 3.14159265358979323846264338
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int N = 100010;
const int MX = 123456;
const int mod = (int)1e9 + 7;
const int base = 1023456789;
const ull BS1 = 10000019ULL;
const int INF = (1 << 29);
template <class T> inline void fastScan(T &x) {
register char c = getchar();
int neg = 0;
x = 0;
for (; (c < 48 || c > 57) && (c != '-'); c = getchar())
;
if (c == '-') {
neg = 1;
c = getchar();
}
for (; c > 47 && c < 58; c = getchar()) {
x = (x << 1) + (x << 3) + c - 48;
}
if (neg)
x = -x;
}
// OrderedSet
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// template < typename T > using ordered_set = tree < T, null_type, greater < T
// >, rb_tree_tag, tree_order_statistics_node_update >;
int n, k;
int inp[N];
ll f(int p, int q) {
ll ret = 1ll * k * q % mod;
ll sum = (1ll * (k - 1) * k) / 2ll;
sum %= mod;
sum = 1ll * sum * p % mod;
ret += sum;
return ret % mod;
}
int main() {
fastScan(n);
fastScan(k);
for (int i = 1; i <= n; i++) {
fastScan(inp[i]);
}
ll ans = 0;
for (int i = 1; i <= n; i++) {
int p = 0, q = 0;
for (int j = 1; j <= n; j++) {
if (inp[i] < inp[j]) {
p++;
}
if (i > j) {
if (inp[i] < inp[j]) {
q++;
}
}
}
ans += f(p, q);
ans %= mod;
}
printf("%lld\n", ans);
}
|
[
"assignment.add"
] | 731,933
| 731,934
|
u487769730
|
cpp
|
p02928
|
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;
// ====================================================================
int main() {
ll n, k;
cin >> n >> k;
vector<ll> v(n);
for (int i = 0; i < n; i++)
cin >> v[i];
ll ans = 0;
for (int i = 0; i < n; i++) {
ll migi = 0, zentai = 0;
for (int j = i; j < n; j++)
if (v[i] > v[j])
migi++;
for (int j = 0; j < n; j++)
if (v[i] > v[j])
zentai++;
ans += migi * k;
ans %= MOD;
ans += (k - 1) * k / 2 * zentai % MOD;
ans %= MOD;
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;
// ====================================================================
int main() {
ll n, k;
cin >> n >> k;
vector<ll> v(n);
for (int i = 0; i < n; i++)
cin >> v[i];
ll ans = 0;
for (int i = 0; i < n; i++) {
ll migi = 0, zentai = 0;
for (int j = i; j < n; j++)
if (v[i] > v[j])
migi++;
for (int j = 0; j < n; j++)
if (v[i] > v[j])
zentai++;
ans += migi * k % MOD;
ans %= MOD;
ans += (k - 1) * k / 2 % MOD * zentai % MOD;
ans %= MOD;
}
cout << ans << endl;
}
|
[
"assignment.change"
] | 731,935
| 731,936
|
u561186440
|
cpp
|
p02928
|
#include <iostream>
using namespace std;
const int max_n = (2e3) + 5;
const long long mod = (1e9) + 7;
int n, k;
int a[max_n];
int geng[max_n] = {0}, eg[max_n] = {0};
long long inv = 0;
int main() {
cin >> n >> k;
for (int i = 0; i < n; ++i)
cin >> a[i];
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if (a[j] > a[i])
++geng[i];
}
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < i; ++j) {
if (a[j] > a[i])
++eg[i];
}
}
for (int i = 0; i < n; ++i)
inv =
(inv + ((1ll) * k * eg[i]) + ((((1ll) * (k - 1) * k) / 2) * geng[i])) %
mod;
cout << inv << endl;
return 0;
}
|
#include <iostream>
using namespace std;
const int max_n = (2e3) + 5;
const long long mod = (1e9) + 7;
int n, k;
int a[max_n];
int geng[max_n] = {0}, eg[max_n] = {0};
long long inv = 0;
int main() {
cin >> n >> k;
for (int i = 0; i < n; ++i)
cin >> a[i];
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if (a[j] > a[i])
++geng[i];
}
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < i; ++j) {
if (a[j] > a[i])
++eg[i];
}
}
for (int i = 0; i < n; ++i)
inv = (inv + ((1ll) * k * eg[i]) +
(((((1ll) * (k - 1) * k) / 2) % mod) * geng[i])) %
mod;
cout << inv << endl;
return 0;
}
|
[] | 731,937
| 731,938
|
u743294402
|
cpp
|
p02928
|
#include <cstdio>
#define Int register int
const int N = 2000, mod = 1e9 + 7;
typedef long long LL;
static inline char Get_Char() {
static char buffer[100000], *S = buffer, *T = buffer;
if (S == T) {
T = (S = buffer) + fread(buffer, 1, 100000, stdin);
if (S == T)
return EOF;
}
return *S++;
}
//#define Get_Char() getchar()
static inline int Read() {
int f = 1, x = 0;
register char sign = Get_Char();
for (; sign > '9' || sign < '0'; sign = Get_Char())
if (sign == '-')
f = -1;
for (; sign >= '0' && sign <= '9'; sign = Get_Char())
x = (x << 3) + (x << 1) + (sign ^ 48);
return x * f;
}
int a[N + 1];
LL Rec[N + 1], Ans;
int main() {
int n = Read(), k = Read();
for (Int i = 1; i <= n; ++i) {
a[i] = Read();
}
/*
3 2
3 2 1
*/
for (Int i = 1; i <= n; ++i) {
for (Int j = 1; j < i; ++j) {
if (a[j] > a[i])
++Ans;
}
}
for (Int i = 1; i <= n; ++i) {
for (Int j = 1; j <= n; ++j) {
if (a[i] > a[j])
++Rec[i];
}
}
Ans = Ans * k % mod;
for (Int i = 1; i <= n; ++i) {
Ans = (Ans + Rec[i] * (1ll * (1 + k - 1) * (k - 1) / 2) % mod % mod) % mod;
}
printf("%lld\n", Ans);
return 0;
}
|
#include <cstdio>
#define Int register int
const int N = 2000, mod = 1e9 + 7;
typedef long long LL;
static inline char Get_Char() {
static char buffer[100000], *S = buffer, *T = buffer;
if (S == T) {
T = (S = buffer) + fread(buffer, 1, 100000, stdin);
if (S == T)
return EOF;
}
return *S++;
}
//#define Get_Char() getchar()
static inline int Read() {
int f = 1, x = 0;
register char sign = Get_Char();
for (; sign > '9' || sign < '0'; sign = Get_Char())
if (sign == '-')
f = -1;
for (; sign >= '0' && sign <= '9'; sign = Get_Char())
x = (x << 3) + (x << 1) + (sign ^ 48);
return x * f;
}
int a[N + 1];
LL Rec[N + 1], Ans;
int main() {
int n = Read(), k = Read();
for (Int i = 1; i <= n; ++i) {
a[i] = Read();
}
/*
3 2
3 2 1
*/
for (Int i = 1; i <= n; ++i) {
for (Int j = 1; j < i; ++j) {
if (a[j] > a[i])
++Ans;
}
}
for (Int i = 1; i <= n; ++i) {
for (Int j = 1; j <= n; ++j) {
if (a[i] > a[j])
++Rec[i];
}
}
Ans = Ans * k % mod;
for (Int i = 1; i <= n; ++i) {
Ans = (Ans + Rec[i] * ((1ll * (1 + k - 1) * (k - 1) / 2) % mod)) % mod;
}
printf("%lld\n", Ans);
return 0;
}
|
[
"assignment.value.change",
"expression.operation.binary.change"
] | 731,943
| 731,944
|
u067894715
|
cpp
|
p02928
|
#include <bits/stdc++.h>
namespace shl {
typedef long long ll;
const ll mod = 1e9 + 7;
inline ll read() {
ll ret = 0, op = 1;
char c = getchar();
while (!isdigit(c)) {
if (c == '-')
op = -1;
c = getchar();
}
while (isdigit(c)) {
ret = (ret << 3) + (ret << 1) + c - '0';
c = getchar();
}
return ret * op;
}
ll n, k;
ll ans;
ll all[2010];
int a[2010];
int main() {
n = read();
k = read();
for (register int i = 1; i <= n; ++i)
a[i] = read();
for (register int i = 1; i <= n; ++i)
for (register int j = 1; j <= n; ++j)
if (a[i] > a[j]) {
all[i]++;
if (i < j)
ans++;
}
ans = ans * k % mod;
for (register int i = 1; i <= n; ++i) {
ll sum = all[i] * (k * (k - 1) % mod) / 2 % mod;
ans = (ans + sum) % mod;
}
printf("%lld\n", ans % mod);
return 0;
}
} // namespace shl
int main() {
shl ::main();
return 0;
}
|
#include <bits/stdc++.h>
namespace shl {
typedef long long ll;
const ll mod = 1e9 + 7;
inline ll read() {
ll ret = 0, op = 1;
char c = getchar();
while (!isdigit(c)) {
if (c == '-')
op = -1;
c = getchar();
}
while (isdigit(c)) {
ret = (ret << 3) + (ret << 1) + c - '0';
c = getchar();
}
return ret * op;
}
ll n, k;
ll ans;
ll all[2010];
int a[2010];
int main() {
n = read();
k = read();
for (register int i = 1; i <= n; ++i)
a[i] = read();
for (register int i = 1; i <= n; ++i)
for (register int j = 1; j <= n; ++j)
if (a[i] > a[j]) {
all[i]++;
if (i < j)
ans++;
}
ans = ans * k % mod;
for (register int i = 1; i <= n; ++i) {
ll sum = all[i] * (k * (k - 1) / 2 % mod) % mod;
ans = (ans + sum) % mod;
}
printf("%lld\n", ans % mod);
return 0;
}
} // namespace shl
int main() {
shl ::main();
return 0;
}
|
[
"assignment.change"
] | 731,945
| 731,946
|
u419192203
|
cpp
|
p02928
|
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define int long long
#define x first
#define y second
#define all(aaa) (aaa).begin(), (aaa).end()
#define REP(i, sss, eee) for (int i = sss; i <= eee; ++i)
#define pb push_back
#define pii pair<int, int>
#define vi vector<int>
#define speed \
ios_base::sync_with_stdio(0); \
cin.tie(0);
#define N 1000000007
#define inf 1000000000000000000
using namespace __gnu_pbds;
using namespace std;
template <class T> T MAX(T a, T b) { return ((a > b) ? a : b); }
template <class T> T MIN(T a, T b) { return ((a < b) ? a : b); }
template <class T> T MOD(T a) { return ((a >= 0) ? a : (-1 * a)); }
template <class T> void SWAP(T &a, T &b) {
T temp = a;
a = b;
b = temp;
}
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_set; // for multiset use less_equal above
signed main() {
int n, k;
cin >> n >> k;
std::vector<int> inp(n), sor;
for (int i = 0; i < n; ++i) {
cin >> inp[i];
}
sor = inp;
std::vector<int> forw(n), tot(n);
sort(sor.begin(), sor.end());
ordered_set st;
int ct = n - 1;
int ans = 0;
int fact = ((k * (k - 1)) / 2);
fact %= N;
for (auto it = inp.rbegin(); it != inp.rend(); ++it) {
forw[ct] = st.order_of_key(*it);
tot[ct] = (lower_bound(sor.begin(), sor.end(), *it) - sor.begin());
ans += (forw[ct] * k);
ans %= N;
ans += (fact * tot[ct]);
ans %= N;
--ct;
st.insert(*it);
}
cout << ans << "\n";
}
|
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define int long long
#define x first
#define y second
#define all(aaa) (aaa).begin(), (aaa).end()
#define REP(i, sss, eee) for (int i = sss; i <= eee; ++i)
#define pb push_back
#define pii pair<int, int>
#define vi vector<int>
#define speed \
ios_base::sync_with_stdio(0); \
cin.tie(0);
#define N 1000000007
#define inf 1000000000000000000
using namespace __gnu_pbds;
using namespace std;
template <class T> T MAX(T a, T b) { return ((a > b) ? a : b); }
template <class T> T MIN(T a, T b) { return ((a < b) ? a : b); }
template <class T> T MOD(T a) { return ((a >= 0) ? a : (-1 * a)); }
template <class T> void SWAP(T &a, T &b) {
T temp = a;
a = b;
b = temp;
}
typedef tree<int, null_type, less_equal<int>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_set; // for multiset use less_equal above
signed main() {
int n, k;
cin >> n >> k;
std::vector<int> inp(n), sor;
for (int i = 0; i < n; ++i) {
cin >> inp[i];
}
sor = inp;
std::vector<int> forw(n), tot(n);
sort(sor.begin(), sor.end());
ordered_set st;
int ct = n - 1;
int ans = 0;
int fact = ((k * (k - 1)) / 2);
fact %= N;
for (auto it = inp.rbegin(); it != inp.rend(); ++it) {
forw[ct] = st.order_of_key(*it);
tot[ct] = (lower_bound(sor.begin(), sor.end(), *it) - sor.begin());
ans += (forw[ct] * k);
ans %= N;
ans += (fact * tot[ct]);
ans %= N;
--ct;
st.insert(*it);
}
cout << ans << "\n";
}
|
[] | 731,951
| 731,952
|
u930089439
|
cpp
|
p02928
|
#include <bits/stdc++.h>
#define int long long
#define ALL(v) (v).begin(), (v).end()
#define Vi vector<int>
#define pb push_back
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repr(i, a, b) for (int i = a; i > b; i--)
#define leng(n) (int)(log10(n) + 1)
#define INF 9000000000000000000
using namespace std;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } // 最大公約数gcd
int lcm(int a, int b) { return a / gcd(a, b) * b; } // 最小公倍数lcm
signed main() {
int P = 1000000007;
int n, k;
cin >> n >> k;
vector<int> a(n);
vector<pair<int, int>> b(n);
rep(i, 0, n) cin >> a[i];
int f, s;
rep(i, 0, n) {
f = 0;
s = 0;
rep(j, 1, n - i) {
if (a[i] > a[i + j])
f++;
}
rep(j, 0, n) {
if (a[i] > a[j])
s++;
}
b[i] = make_pair(f, s);
}
int ans = 0;
rep(i, 0, n) {
ans += (b[i].first * k) % P;
ans += (((k * (k - 1)) / 2) * b[i].second) % P;
}
cout << ans % P << endl;
}
|
#include <bits/stdc++.h>
#define int long long
#define ALL(v) (v).begin(), (v).end()
#define Vi vector<int>
#define pb push_back
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repr(i, a, b) for (int i = a; i > b; i--)
#define leng(n) (int)(log10(n) + 1)
#define INF 9000000000000000000
using namespace std;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } // 最大公約数gcd
int lcm(int a, int b) { return a / gcd(a, b) * b; } // 最小公倍数lcm
signed main() {
int P = 1000000007;
int n, k;
cin >> n >> k;
vector<int> a(n);
vector<pair<int, int>> b(n);
rep(i, 0, n) cin >> a[i];
int f, s;
rep(i, 0, n) {
f = 0;
s = 0;
rep(j, 1, n - i) {
if (a[i] > a[i + j])
f++;
}
rep(j, 0, n) {
if (a[i] > a[j])
s++;
}
b[i] = make_pair(f, s);
}
int ans = 0;
rep(i, 0, n) {
ans += (b[i].first * k) % P;
ans += ((((k * (k - 1)) / 2) % P) * b[i].second) % P;
}
cout << ans % P << endl;
}
|
[] | 731,953
| 731,954
|
u095453583
|
cpp
|
p02928
|
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int mod = 1e9 + 7;
signed main() {
int n, k;
cin >> n >> k;
vector<int> a(n);
for (int i = 0; i < n; ++i)
cin >> a[i];
vector<int> incnt(n, 0);
vector<int> outcnt(n, 0);
for (int i = 0; i < n; ++i) {
for (int j = i + 1; j < n; ++j) {
if (a[i] > a[j])
++incnt[i];
}
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if (a[i] > a[j])
++outcnt[i];
}
}
int ans = 0;
for (int i = 0; i < n; ++i) {
ans += outcnt[i];
ans %= mod;
}
ans *= k * (k - 1) / 2;
ans %= mod;
for (int i = 0; i < n; ++i) {
ans += k * incnt[i];
ans %= mod;
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int mod = 1e9 + 7;
signed main() {
int n, k;
cin >> n >> k;
vector<int> a(n);
for (int i = 0; i < n; ++i)
cin >> a[i];
vector<int> incnt(n, 0);
vector<int> outcnt(n, 0);
for (int i = 0; i < n; ++i) {
for (int j = i + 1; j < n; ++j) {
if (a[i] > a[j])
++incnt[i];
}
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if (a[i] > a[j])
++outcnt[i];
}
}
int ans = 0;
for (int i = 0; i < n; ++i) {
ans += outcnt[i];
ans %= mod;
}
ans *= (k * (k - 1) / 2) % mod;
ans %= mod;
for (int i = 0; i < n; ++i) {
ans += k * incnt[i];
ans %= mod;
}
cout << ans << endl;
}
|
[
"assignment.change"
] | 731,962
| 731,963
|
u698760125
|
cpp
|
p02928
|
#include <algorithm>
#include <chrono>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
using lli = long long int;
using Vint = std::vector<int>;
using Vlli = std::vector<lli>;
using Wint = std::vector<Vint>;
using Wlli = std::vector<Vlli>;
using Vbool = std::vector<bool>;
using Wbool = std::vector<Vbool>;
using pii = std::pair<int, int>;
using pll = std::pair<lli, lli>;
template <class T> using Vec = std::vector<T>;
template <class T> using Wec = Vec<Vec<T>>;
constexpr int MOD = 1e9 + 7;
constexpr int INFi = 2e9 + 1;
constexpr lli INFl = (lli)(9e18) + 1;
const std::vector<std::pair<int, int>> DXDY = {
{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
constexpr char BR = '\n';
#define DEBUG(x) std::cerr << #x << " = " << x << '\n';
#define FOR(i, a, b) for (int(i) = (a); (i) < (b); ++(i))
#define FOReq(i, a, b) for (int(i) = (a); (i) <= (b); ++(i))
#define rFOR(i, a, b) for (int(i) = (b); (i) >= (a); --(i))
#define FORstep(i, a, b, step) for (int(i) = (a); i < (b); i += (step))
#define REP(i, n) FOR(i, 0, n)
#define rREP(i, n) rFOR(i, 0, (n - 1))
#define vREP(ele, vec) for (auto &(ele) : (vec))
#define vREPcopy(ele, vec) for (auto(ele) : (vec))
#define SORT(A) std::sort((A).begin(), (A).end())
#define RSORT(A) std::sort((A).rbegin(), (A).rend())
#define ALL(A) (A).begin(), (A).end()
// 座標圧縮 (for vector) : ソートしてから使うのが一般的 ; SORT(A) =>
// COORDINATE_COMPRESSION(A)
#define COORDINATE_COMPRESSION(A) \
(A).erase(unique((A).begin(), (A).end()), (A).end())
template <class T> inline int argmin(std::vector<T> &vec) {
return min_element(vec.begin(), vec.end()) - vec.begin();
}
template <class T> inline int argmax(std::vector<T> &vec) {
return max_element(vec.begin(), vec.end()) - vec.begin();
}
template <class T> inline T &chmin(T &a, T b) { return (a > b) ? a = b : a; }
template <class T> inline T &chmax(T &a, T b) { return (a < b) ? a = b : a; }
template <class T> inline void reverseSORT(Vec<T> &Array) {
std::sort(Array.begin(), Array.end(), std::greater<T>());
}
inline int BitI(int k) { return 1 << k; }
inline lli BitL(int k) { return 1LL << k; }
inline void putsDouble(double d) { printf("%.16lf\n", d); }
template <class T> inline std::string toString(T n) {
if (n == 0)
return "0";
std::string res;
if (n < 0) {
n = -n;
while (n != 0) {
res += (char)(n % 10 + '0');
n /= 10;
}
std::reverse(res.begin(), res.end());
return '-' + res;
}
while (n != 0) {
res += (char)(n % 10 + '0');
n /= 10;
}
std::reverse(res.begin(), res.end());
return res;
}
namespace MyFunc {
using LLi = long long int;
using ULLi = unsigned long long int;
// GCD(a, b) ; a, bの最大公約数を求める関数
inline LLi gcd(LLi a, LLi b) {
while (b != 0) {
a %= b;
std::swap(a, b);
}
return a;
}
// LCM(a, b) ; a, bの最小公倍数を求める関数
inline LLi lcm(LLi a, LLi b) { return (a * b) / MyFunc::gcd(a, b); }
// 累乗を求める関数
inline LLi power(LLi a, LLi n) {
LLi res = 1LL, waiting = a;
while (n != 0LL) {
if ((n & 1LL) != 0LL)
res *= waiting;
waiting *= waiting;
n >>= 1;
}
return res;
}
// 累乗の余りを求める関数
inline LLi power_mod(LLi a, LLi n, LLi mod_number___ = 1e9 + 7) {
LLi res = 1LL, waiting = a;
while (n != 0LL) {
if ((n & 1LL) != 0LL) {
res *= waiting;
res %= mod_number___;
}
waiting *= waiting;
waiting %= mod_number___;
n >>= 1;
}
return res;
}
// Z/pZ上の逆元を求める関数 (フェルマーの小定理)
inline LLi inverse_mod(LLi a, LLi mod_number___ = 1e9 + 7) {
return MyFunc::power_mod(a, mod_number___ - 2);
}
inline LLi inverse_mod_euclid(LLi a, LLi mod_number___ = 1e9 + 7) {
LLi b = mod_number___, u = 1, v = 0;
while (b != 0) {
LLi t = a / b;
a -= t * b;
std::swap(a, b);
u -= t * v;
std::swap(u, v);
}
u %= mod_number___;
if (u < 0)
u += mod_number___;
return u;
}
// 素数であるかを判定する関数
template <typename Integer_type> inline bool isPrime(Integer_type n) {
if (n < 2)
return false;
if (n == 2)
return true;
if (n % 2 == 0)
return false;
for (Integer_type x = 3; x * x <= n; ++++x)
if (n % x == 0)
return false;
return true;
}
// 素数であるかの真偽表を返す : n ≥ 1
inline std::vector<bool> primeTable(int n) {
std::vector<bool> res(n + 1, true);
res[0] = false;
res[1] = false;
for (int x = 2; x * x <= n; ++x)
if (res[x]) {
for (int i = 2 * x; i <= n; i += x) {
res[i] = false;
}
}
return std::move(res);
}
// 素因数分解したベクトルを返す ; {素因数, 指数}
template <typename Integer_type>
inline std::vector<std::pair<Integer_type, int>>
prime_factorization(Integer_type n) {
std::vector<std::pair<Integer_type, int>> res(0);
if (n <= 0)
return std::move(res); // 例外処理 : nが 0 以下
if (n % 2 == 0) {
n /= 2;
int cnt = 1;
while (n % 2 == 0) {
n /= 2;
cnt++;
}
res.emplace_back(make_pair(2, cnt));
}
Integer_type x = 3;
while (x * x <= n) {
if (n % x == 0) {
n /= x;
int cnt = 1;
while (n % x == 0) {
n /= x;
cnt++;
}
res.emplace_back(make_pair(x, cnt));
}
++++x;
}
if (n > 1)
res.emplace_back(make_pair(n, 1));
return std::move(res);
}
// unsigned long 符号なし64bit整数で平方数かを判定する関数 O(log(N))
inline bool is_square_unsigned(ULLi n) {
// 0 は 平方数
if (n == 0)
return true;
// 平方数の可能性としては 2^32 - 1 が最大 : (2^32)^2 - 1
static ULLi MAX_LONG_SQRT__ = (1UL << 32) - 1;
if (MAX_LONG_SQRT__ * MAX_LONG_SQRT__ < n)
return false;
if (MAX_LONG_SQRT__ * MAX_LONG_SQRT__ == n)
return true;
// 二分探索
ULLi smaller = 0, bigger = MAX_LONG_SQRT__;
while (bigger - smaller > 1) {
ULLi m = (smaller + bigger) >> 1;
if (m * m == n)
return true;
if (m * m < n)
smaller = m;
else
bigger = m;
}
return false;
}
// 符号付き64bit整数で平方数か判定する関数
inline bool is_square(LLi n) {
if (n < 0)
return false;
// 平方数を4で割った余りは 0 か 1 に限る
if ((n & 0b11) > 0b01)
return false;
return is_square_unsigned(n);
}
} // namespace MyFunc
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Vint A, B, D;
std::vector<pii> C;
int main(void) {
int n, k;
scanf("%d%d", &n, &k);
A.resize(n);
REP(i, n) scanf("%d", &A[i]);
B.resize(n);
C.resize(n);
REP(i, n) C[i] = {A[i], i};
D.resize(n);
REP(i, n) {
D[i] = 0;
for (int j = i + 1; j < n; j++) {
if (A[i] > A[j])
D[i]++;
}
B[i] = 0;
REP(j, n) if (A[i] > A[j]) B[i]++;
}
lli L = k;
L *= (k - 1);
L /= 2;
L %= MOD;
lli res = 0;
REP(i, n) {
res += L * B[i] + k * D[i];
res %= MOD;
}
// REP(i, n) printf("%d ", B[i]); putchar(BR);
// REP(i, n) printf("%d ", D[i]); putchar(BR);
printf("%lld\n", res);
return 0;
}
|
#include <algorithm>
#include <chrono>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
using lli = long long int;
using Vint = std::vector<int>;
using Vlli = std::vector<lli>;
using Wint = std::vector<Vint>;
using Wlli = std::vector<Vlli>;
using Vbool = std::vector<bool>;
using Wbool = std::vector<Vbool>;
using pii = std::pair<int, int>;
using pll = std::pair<lli, lli>;
template <class T> using Vec = std::vector<T>;
template <class T> using Wec = Vec<Vec<T>>;
constexpr int MOD = 1e9 + 7;
constexpr int INFi = 2e9 + 1;
constexpr lli INFl = (lli)(9e18) + 1;
const std::vector<std::pair<int, int>> DXDY = {
{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
constexpr char BR = '\n';
#define DEBUG(x) std::cerr << #x << " = " << x << '\n';
#define FOR(i, a, b) for (int(i) = (a); (i) < (b); ++(i))
#define FOReq(i, a, b) for (int(i) = (a); (i) <= (b); ++(i))
#define rFOR(i, a, b) for (int(i) = (b); (i) >= (a); --(i))
#define FORstep(i, a, b, step) for (int(i) = (a); i < (b); i += (step))
#define REP(i, n) FOR(i, 0, n)
#define rREP(i, n) rFOR(i, 0, (n - 1))
#define vREP(ele, vec) for (auto &(ele) : (vec))
#define vREPcopy(ele, vec) for (auto(ele) : (vec))
#define SORT(A) std::sort((A).begin(), (A).end())
#define RSORT(A) std::sort((A).rbegin(), (A).rend())
#define ALL(A) (A).begin(), (A).end()
// 座標圧縮 (for vector) : ソートしてから使うのが一般的 ; SORT(A) =>
// COORDINATE_COMPRESSION(A)
#define COORDINATE_COMPRESSION(A) \
(A).erase(unique((A).begin(), (A).end()), (A).end())
template <class T> inline int argmin(std::vector<T> &vec) {
return min_element(vec.begin(), vec.end()) - vec.begin();
}
template <class T> inline int argmax(std::vector<T> &vec) {
return max_element(vec.begin(), vec.end()) - vec.begin();
}
template <class T> inline T &chmin(T &a, T b) { return (a > b) ? a = b : a; }
template <class T> inline T &chmax(T &a, T b) { return (a < b) ? a = b : a; }
template <class T> inline void reverseSORT(Vec<T> &Array) {
std::sort(Array.begin(), Array.end(), std::greater<T>());
}
inline int BitI(int k) { return 1 << k; }
inline lli BitL(int k) { return 1LL << k; }
inline void putsDouble(double d) { printf("%.16lf\n", d); }
template <class T> inline std::string toString(T n) {
if (n == 0)
return "0";
std::string res;
if (n < 0) {
n = -n;
while (n != 0) {
res += (char)(n % 10 + '0');
n /= 10;
}
std::reverse(res.begin(), res.end());
return '-' + res;
}
while (n != 0) {
res += (char)(n % 10 + '0');
n /= 10;
}
std::reverse(res.begin(), res.end());
return res;
}
namespace MyFunc {
using LLi = long long int;
using ULLi = unsigned long long int;
// GCD(a, b) ; a, bの最大公約数を求める関数
inline LLi gcd(LLi a, LLi b) {
while (b != 0) {
a %= b;
std::swap(a, b);
}
return a;
}
// LCM(a, b) ; a, bの最小公倍数を求める関数
inline LLi lcm(LLi a, LLi b) { return (a * b) / MyFunc::gcd(a, b); }
// 累乗を求める関数
inline LLi power(LLi a, LLi n) {
LLi res = 1LL, waiting = a;
while (n != 0LL) {
if ((n & 1LL) != 0LL)
res *= waiting;
waiting *= waiting;
n >>= 1;
}
return res;
}
// 累乗の余りを求める関数
inline LLi power_mod(LLi a, LLi n, LLi mod_number___ = 1e9 + 7) {
LLi res = 1LL, waiting = a;
while (n != 0LL) {
if ((n & 1LL) != 0LL) {
res *= waiting;
res %= mod_number___;
}
waiting *= waiting;
waiting %= mod_number___;
n >>= 1;
}
return res;
}
// Z/pZ上の逆元を求める関数 (フェルマーの小定理)
inline LLi inverse_mod(LLi a, LLi mod_number___ = 1e9 + 7) {
return MyFunc::power_mod(a, mod_number___ - 2);
}
inline LLi inverse_mod_euclid(LLi a, LLi mod_number___ = 1e9 + 7) {
LLi b = mod_number___, u = 1, v = 0;
while (b != 0) {
LLi t = a / b;
a -= t * b;
std::swap(a, b);
u -= t * v;
std::swap(u, v);
}
u %= mod_number___;
if (u < 0)
u += mod_number___;
return u;
}
// 素数であるかを判定する関数
template <typename Integer_type> inline bool isPrime(Integer_type n) {
if (n < 2)
return false;
if (n == 2)
return true;
if (n % 2 == 0)
return false;
for (Integer_type x = 3; x * x <= n; ++++x)
if (n % x == 0)
return false;
return true;
}
// 素数であるかの真偽表を返す : n ≥ 1
inline std::vector<bool> primeTable(int n) {
std::vector<bool> res(n + 1, true);
res[0] = false;
res[1] = false;
for (int x = 2; x * x <= n; ++x)
if (res[x]) {
for (int i = 2 * x; i <= n; i += x) {
res[i] = false;
}
}
return std::move(res);
}
// 素因数分解したベクトルを返す ; {素因数, 指数}
template <typename Integer_type>
inline std::vector<std::pair<Integer_type, int>>
prime_factorization(Integer_type n) {
std::vector<std::pair<Integer_type, int>> res(0);
if (n <= 0)
return std::move(res); // 例外処理 : nが 0 以下
if (n % 2 == 0) {
n /= 2;
int cnt = 1;
while (n % 2 == 0) {
n /= 2;
cnt++;
}
res.emplace_back(make_pair(2, cnt));
}
Integer_type x = 3;
while (x * x <= n) {
if (n % x == 0) {
n /= x;
int cnt = 1;
while (n % x == 0) {
n /= x;
cnt++;
}
res.emplace_back(make_pair(x, cnt));
}
++++x;
}
if (n > 1)
res.emplace_back(make_pair(n, 1));
return std::move(res);
}
// unsigned long 符号なし64bit整数で平方数かを判定する関数 O(log(N))
inline bool is_square_unsigned(ULLi n) {
// 0 は 平方数
if (n == 0)
return true;
// 平方数の可能性としては 2^32 - 1 が最大 : (2^32)^2 - 1
static ULLi MAX_LONG_SQRT__ = (1UL << 32) - 1;
if (MAX_LONG_SQRT__ * MAX_LONG_SQRT__ < n)
return false;
if (MAX_LONG_SQRT__ * MAX_LONG_SQRT__ == n)
return true;
// 二分探索
ULLi smaller = 0, bigger = MAX_LONG_SQRT__;
while (bigger - smaller > 1) {
ULLi m = (smaller + bigger) >> 1;
if (m * m == n)
return true;
if (m * m < n)
smaller = m;
else
bigger = m;
}
return false;
}
// 符号付き64bit整数で平方数か判定する関数
inline bool is_square(LLi n) {
if (n < 0)
return false;
// 平方数を4で割った余りは 0 か 1 に限る
if ((n & 0b11) > 0b01)
return false;
return is_square_unsigned(n);
}
} // namespace MyFunc
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Vint A, B, D;
std::vector<pii> C;
int main(void) {
int n;
lli k;
scanf("%d%lld", &n, &k);
A.resize(n);
REP(i, n) scanf("%d", &A[i]);
B.resize(n);
C.resize(n);
REP(i, n) C[i] = {A[i], i};
D.resize(n);
REP(i, n) {
D[i] = 0;
for (int j = i + 1; j < n; j++) {
if (A[i] > A[j])
D[i]++;
}
B[i] = 0;
REP(j, n) if (A[i] > A[j]) B[i]++;
}
lli L = k;
L *= (k - 1);
L /= 2;
L %= MOD;
lli res = 0;
REP(i, n) {
res += L * B[i] + k * D[i];
res %= MOD;
}
// REP(i, n) printf("%d ", B[i]); putchar(BR);
// REP(i, n) printf("%d ", D[i]); putchar(BR);
printf("%lld\n", res);
return 0;
}
|
[
"literal.string.change",
"call.arguments.change"
] | 731,964
| 731,965
|
u394853232
|
cpp
|
p02928
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define EPS (1e-7)
#define INF (3e9)
using namespace std;
typedef long long int ll;
typedef pair<int, int> PI;
typedef pair<ll, ll> PL;
typedef priority_queue<int> PQI;
typedef priority_queue<int, vector<int>, greater<int>> PQSI;
typedef priority_queue<ll> PQL;
typedef priority_queue<ll, vector<ll>, greater<ll>> PQSL;
const int MOD = 1000000007;
struct mint {
int n;
mint(int n_ = 0) : n(n_) {}
};
mint operator-(mint a) { return -a.n + MOD * (a.n != 0); }
mint operator+(mint a, mint b) {
int x = a.n + b.n;
return x - (x >= MOD) * MOD;
}
mint operator-(mint a, mint b) {
int x = a.n - b.n;
return x + (x < 0) * MOD;
}
mint operator*(mint a, mint b) { return (long long)a.n * b.n % MOD; }
mint &operator+=(mint &a, mint b) { return a = a + b; }
mint &operator-=(mint &a, mint b) { return a = a - b; }
mint &operator*=(mint &a, mint b) { return a = a * b; }
istream &operator>>(istream &i, mint &a) { return i >> a.n; }
ostream &operator<<(ostream &o, mint a) { return o << a.n; }
vector<mint> F_{1, 1}, R_{1, 1}, I_{0, 1};
void check_fact(int n) {
for (int i = I_.size(); i <= n; i++) {
I_.push_back(I_[MOD % i] * (MOD - MOD / i));
F_.push_back(F_[i - 1] * i);
R_.push_back(R_[i - 1] * I_[i]);
}
}
mint I(int n) {
check_fact(abs(n));
return n >= 0 ? I_[n] : -I_[n];
}
mint F(int n) {
check_fact(n);
return n < 0 ? 0 : F_[n];
}
mint R(int n) {
check_fact(n);
return n < 0 ? 0 : R_[n];
}
mint C(int n, int r) { return F(n) * R(n - r) * R(r); }
mint P(int n, int r) { return F(n) * R(n - r); }
mint H(int n, int r) { return n == 0 ? (r == 0) : C(n + r - 1, r); }
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <typename T> vector<T> enum_div(T n) {
vector<T> ret;
for (T i = 1; i * i <= n; i++) {
if (n % i == 0) {
ret.push_back(i);
if (i * i != n)
ret.push_back(n / i);
}
}
// sort(ret.begin(), ret.end());
return ret;
}
template <typename T> T gcd(T x, T y) {
if (y == 0)
return x;
else
return gcd(y, x % y);
}
template <typename T> T lcm(T x, T y) { return (x / gcd(x, y)) * y; }
int N;
ll K;
int A[2000];
ll F1[2000], F2[2000];
int main(void) {
cin >> N >> K;
rep(i, N) cin >> A[i];
for (int i = 0; i < N; i++) {
for (int j = i + 1; j < N; j++) {
if (A[i] > A[j])
F1[i]++;
}
for (int j = 0; j < N; j++) {
if (A[i] > A[j])
F2[i]++;
}
}
ll count = 0;
for (int i = 0; i < N; i++) {
count += (K * F1[i]) % 1000000007;
count += (F2[i] * ((K * (K - 1)) % 1000000007) / 2) % 1000000007;
count %= 1000000007;
}
cout << count << endl;
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define EPS (1e-7)
#define INF (3e9)
using namespace std;
typedef long long int ll;
typedef pair<int, int> PI;
typedef pair<ll, ll> PL;
typedef priority_queue<int> PQI;
typedef priority_queue<int, vector<int>, greater<int>> PQSI;
typedef priority_queue<ll> PQL;
typedef priority_queue<ll, vector<ll>, greater<ll>> PQSL;
const int MOD = 1000000007;
struct mint {
int n;
mint(int n_ = 0) : n(n_) {}
};
mint operator-(mint a) { return -a.n + MOD * (a.n != 0); }
mint operator+(mint a, mint b) {
int x = a.n + b.n;
return x - (x >= MOD) * MOD;
}
mint operator-(mint a, mint b) {
int x = a.n - b.n;
return x + (x < 0) * MOD;
}
mint operator*(mint a, mint b) { return (long long)a.n * b.n % MOD; }
mint &operator+=(mint &a, mint b) { return a = a + b; }
mint &operator-=(mint &a, mint b) { return a = a - b; }
mint &operator*=(mint &a, mint b) { return a = a * b; }
istream &operator>>(istream &i, mint &a) { return i >> a.n; }
ostream &operator<<(ostream &o, mint a) { return o << a.n; }
vector<mint> F_{1, 1}, R_{1, 1}, I_{0, 1};
void check_fact(int n) {
for (int i = I_.size(); i <= n; i++) {
I_.push_back(I_[MOD % i] * (MOD - MOD / i));
F_.push_back(F_[i - 1] * i);
R_.push_back(R_[i - 1] * I_[i]);
}
}
mint I(int n) {
check_fact(abs(n));
return n >= 0 ? I_[n] : -I_[n];
}
mint F(int n) {
check_fact(n);
return n < 0 ? 0 : F_[n];
}
mint R(int n) {
check_fact(n);
return n < 0 ? 0 : R_[n];
}
mint C(int n, int r) { return F(n) * R(n - r) * R(r); }
mint P(int n, int r) { return F(n) * R(n - r); }
mint H(int n, int r) { return n == 0 ? (r == 0) : C(n + r - 1, r); }
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <typename T> vector<T> enum_div(T n) {
vector<T> ret;
for (T i = 1; i * i <= n; i++) {
if (n % i == 0) {
ret.push_back(i);
if (i * i != n)
ret.push_back(n / i);
}
}
// sort(ret.begin(), ret.end());
return ret;
}
template <typename T> T gcd(T x, T y) {
if (y == 0)
return x;
else
return gcd(y, x % y);
}
template <typename T> T lcm(T x, T y) { return (x / gcd(x, y)) * y; }
int N;
ll K;
int A[2000];
ll F1[2000], F2[2000];
int main(void) {
cin >> N >> K;
rep(i, N) cin >> A[i];
for (int i = 0; i < N; i++) {
for (int j = i + 1; j < N; j++) {
if (A[i] > A[j])
F1[i]++;
}
for (int j = 0; j < N; j++) {
if (A[i] > A[j])
F2[i]++;
}
}
ll count = 0;
for (int i = 0; i < N; i++) {
count += (K * F1[i]) % 1000000007;
count += (F2[i] * ((K * (K - 1) / 2) % 1000000007)) % 1000000007;
count %= 1000000007;
}
cout << count << endl;
return 0;
}
|
[
"assignment.change"
] | 731,968
| 731,969
|
u097408484
|
cpp
|
p02928
|
#include <bits/stdc++.h>
using namespace std;
int s[2005];
long long modd = 1e9 + 7;
long long num1[2005];
long long num2[2005];
typedef long long ll;
ll qpow(ll a, ll n) //计算a^n % mod
{
ll re = 1;
while (n) {
if (n & 1) //判断n的最后一位是否为1
re = (re * a) % modd;
n >>= 1; //舍去n的最后一位
a = (a * a) % modd; //将a平方
}
return re % modd;
}
ll inv(ll x) { return qpow(x, modd - 2); }
int main() {
memset(num1, 0, sizeof(num1));
memset(num2, 0, sizeof(num2));
int n;
long long k;
scanf("%d%lld", &n, &k);
bool falg = false;
for (int i = 0; i < n; i++) {
scanf("%d", &s[i]);
}
long long ans = 0;
for (int i = 0; i < n - 1; i++) {
for (int j = i + 1; j < n; j++) {
if (s[i] > s[j])
num1[i]++;
}
}
for (int i = n - 1; i > 0; i--) {
for (int j = i - 1; j >= 0; j--) {
if (s[i] > s[j])
num2[i]++;
}
}
long long kk = 0;
kk = (((1 + k) * k % modd) / 2) % modd;
// cout << kk << endl;
for (int i = 0; i < n; i++) {
ans = (ans + num1[i] * kk % modd + num2[i] * (kk - k) % modd) % modd;
}
printf("%lld\n", ans);
return 0;
}
/*
*/
|
#include <bits/stdc++.h>
using namespace std;
int s[2005];
long long modd = 1e9 + 7;
long long num1[2005];
long long num2[2005];
typedef long long ll;
ll qpow(ll a, ll n) //计算a^n % mod
{
ll re = 1;
while (n) {
if (n & 1) //判断n的最后一位是否为1
re = (re * a) % modd;
n >>= 1; //舍去n的最后一位
a = (a * a) % modd; //将a平方
}
return re % modd;
}
ll inv(ll x) { return qpow(x, modd - 2); }
int main() {
memset(num1, 0, sizeof(num1));
memset(num2, 0, sizeof(num2));
int n;
long long k;
scanf("%d%lld", &n, &k);
bool falg = false;
for (int i = 0; i < n; i++) {
scanf("%d", &s[i]);
}
long long ans = 0;
for (int i = 0; i < n - 1; i++) {
for (int j = i + 1; j < n; j++) {
if (s[i] > s[j])
num1[i]++;
}
}
for (int i = n - 1; i > 0; i--) {
for (int j = i - 1; j >= 0; j--) {
if (s[i] > s[j])
num2[i]++;
}
}
long long kk = 0;
kk = ((((1 + k) * k)) / 2) % modd;
// cout << kk << endl;
for (int i = 0; i < n; i++) {
ans = (ans + num1[i] * kk % modd + num2[i] * (kk - k) % modd + modd) % modd;
}
printf("%lld\n", ans);
return 0;
}
/*
*/
|
[
"assignment.value.change",
"expression.operation.binary.change",
"assignment.change"
] | 731,974
| 731,975
|
u428618452
|
cpp
|
p02928
|
#include <bits/stdc++.h>
using namespace std;
int s[2005];
long long modd = 1e9 + 7;
long long num1[2005];
long long num2[2005];
typedef long long ll;
ll qpow(ll a, ll n) //计算a^n % mod
{
ll re = 1;
while (n) {
if (n & 1) //判断n的最后一位是否为1
re = (re * a) % modd;
n >>= 1; //舍去n的最后一位
a = (a * a) % modd; //将a平方
}
return re % modd;
}
ll inv(ll x) { return qpow(x, modd - 2); }
int main() {
memset(num1, 0, sizeof(num1));
memset(num2, 0, sizeof(num2));
int n;
long long k;
scanf("%d%lld", &n, &k);
bool falg = false;
for (int i = 0; i < n; i++) {
scanf("%d", &s[i]);
}
long long ans = 0;
for (int i = 0; i < n - 1; i++) {
for (int j = i + 1; j < n; j++) {
if (s[i] > s[j])
num1[i]++;
}
}
for (int i = n - 1; i > 0; i--) {
for (int j = i - 1; j >= 0; j--) {
if (s[i] > s[j])
num2[i]++;
}
}
long long kk = 0;
kk = (((1 + k) * k % modd) * inv(2)) % modd;
// cout << kk << endl;
for (int i = 0; i < n; i++) {
ans = (ans + num1[i] * kk % modd + num2[i] * (kk - k) % modd) % modd;
}
printf("%lld\n", ans);
return 0;
}
/*
*/
|
#include <bits/stdc++.h>
using namespace std;
int s[2005];
long long modd = 1e9 + 7;
long long num1[2005];
long long num2[2005];
typedef long long ll;
ll qpow(ll a, ll n) //计算a^n % mod
{
ll re = 1;
while (n) {
if (n & 1) //判断n的最后一位是否为1
re = (re * a) % modd;
n >>= 1; //舍去n的最后一位
a = (a * a) % modd; //将a平方
}
return re % modd;
}
ll inv(ll x) { return qpow(x, modd - 2); }
int main() {
memset(num1, 0, sizeof(num1));
memset(num2, 0, sizeof(num2));
int n;
long long k;
scanf("%d%lld", &n, &k);
bool falg = false;
for (int i = 0; i < n; i++) {
scanf("%d", &s[i]);
}
long long ans = 0;
for (int i = 0; i < n - 1; i++) {
for (int j = i + 1; j < n; j++) {
if (s[i] > s[j])
num1[i]++;
}
}
for (int i = n - 1; i > 0; i--) {
for (int j = i - 1; j >= 0; j--) {
if (s[i] > s[j])
num2[i]++;
}
}
long long kk = 0;
kk = ((((1 + k) * k) % modd) * inv(2)) % modd;
// cout << kk << endl;
for (int i = 0; i < n; i++) {
ans = (ans + num1[i] * kk % modd + num2[i] * (kk - k) % modd + modd) % modd;
}
printf("%lld\n", ans);
return 0;
}
/*
*/
|
[
"assignment.change"
] | 731,976
| 731,977
|
u428618452
|
cpp
|
p02928
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i, a, b) for (int i = a; i <= b; i++)
#define mm (1e16)
ll Mod = (1e9 + 7);
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
ll n, k;
cin >> n >> k;
vector<int> v(n);
for (int i = 0; i < n; i++)
cin >> v[i];
vector<int> a(2020, 0), b(2020, -1);
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (v[j] < v[i]) {
a[v[i]]++;
}
}
}
sort(v.begin(), v.end());
for (int i = 0; i < n; i++) {
if (b[v[i]] == -1)
b[v[i]] = i;
}
ll ans = 0;
for (int i = 0; i < n; i++) {
ans = (ans + (k * a[v[i]]) % Mod +
(b[v[i]] * ((k * (k - 1) / 2) % Mod)) % Mod) %
Mod;
}
cout << ans;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i, a, b) for (int i = a; i <= b; i++)
#define mm (1e16)
ll Mod = (1e9 + 7);
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
ll n, k;
cin >> n >> k;
vector<int> v(n);
for (int i = 0; i < n; i++)
cin >> v[i];
vector<int> a(2020, 0), b(2020, -1);
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (v[j] < v[i]) {
a[i]++;
}
}
}
sort(v.begin(), v.end());
for (int i = 0; i < n; i++) {
if (b[v[i]] == -1)
b[v[i]] = i;
}
ll ans = 0;
for (int i = 0; i < n; i++) {
ans =
(ans + (k * a[i]) % Mod + (b[v[i]] * ((k * (k - 1) / 2) % Mod)) % Mod) %
Mod;
}
cout << ans;
return 0;
}
|
[] | 731,980
| 731,981
|
u158165654
|
cpp
|
p02928
|
#include <bits/stdc++.h>
#define int long long
#define uint unsigned int
#define ld long double
#define showoff \
ios::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
#define pb push_back
#define pii pair<int, int>
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define RFOR(i, a, b) for (int i = a; i > b; --i)
#define f first
#define se second
#define maxn 200005
#define all(v) v.begin(), v.end()
#define sz(x) (int)x.size()
#define mod 1000000007
#define pqueue priority_queue<int>
#define pdqueue priority_queue<int, vector<int>, greater<int>>
using namespace std;
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int power(int a, int n) {
a %= mod;
if (n == 1)
return a;
if (n == 0)
return 1;
if (n % 2)
return (a * (power((a * a) % mod, n / 2) % mod)) % mod;
return power((a * a) % mod, n / 2) % mod;
}
const int inf = (int)1e18;
int inverse(int x) {
return power(x, mod - 2) % mod; // little fermat....
}
signed main() {
showoff;
int n, k, ans = 0;
cin >> n >> k;
vector<int> v(n + 5);
FOR(i, 1, n + 1) cin >> v[i];
FOR(i, 1, n + 1) {
int v1 = 0, v2 = 0;
FOR(j, i + 1, n + 1) if (v[j] < v[i])++ v1;
FOR(j, 1, n + 1) if (v[j] < v[i])++ v2;
ans += ((v1 * k) % mod + (v2 * (k * (k - 1) / 2) % mod) % mod) % mod;
ans %= mod;
}
cout << ans;
return 0;
}
//*->for large size of matrix take int not long long if possible......
//*->always take maximum as inf for safer side ...
|
#include <bits/stdc++.h>
#define int long long
#define uint unsigned int
#define ld long double
#define showoff \
ios::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
#define pb push_back
#define pii pair<int, int>
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define RFOR(i, a, b) for (int i = a; i > b; --i)
#define f first
#define se second
#define maxn 200005
#define all(v) v.begin(), v.end()
#define sz(x) (int)x.size()
#define mod 1000000007
#define pqueue priority_queue<int>
#define pdqueue priority_queue<int, vector<int>, greater<int>>
using namespace std;
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int power(int a, int n) {
a %= mod;
if (n == 1)
return a;
if (n == 0)
return 1;
if (n % 2)
return (a * (power((a * a) % mod, n / 2) % mod)) % mod;
return power((a * a) % mod, n / 2) % mod;
}
const int inf = (int)1e18;
int inverse(int x) {
return power(x, mod - 2) % mod; // little fermat....
}
signed main() {
showoff;
int n, k, ans = 0;
cin >> n >> k;
vector<int> v(n + 5);
FOR(i, 1, n + 1) cin >> v[i];
FOR(i, 1, n + 1) {
int v1 = 0, v2 = 0;
FOR(j, i + 1, n + 1) if (v[j] < v[i])++ v1;
FOR(j, 1, n + 1) if (v[j] < v[i])++ v2;
ans += ((v1 * k) % mod + (v2 * ((k * (k - 1) / 2) % mod)) % mod) % mod;
ans %= mod;
}
cout << ans;
return 0;
}
//*->for large size of matrix take int not long long if possible......
//*->always take maximum as inf for safer side ...
|
[] | 731,982
| 731,983
|
u578751202
|
cpp
|
p02928
|
#include <algorithm>
#include <iostream>
#include <list>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int gcd(int a, int b) {
int c = a % b;
while (c != 0) {
a = b;
b = c;
c = a % b;
}
return b;
}
struct UnionFind {
vector<int> par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2
UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
for (int i = 0; i < N; i++)
par[i] = i;
}
int root(int x) { // データxが属する木の根を再帰で得る:root(x) = {xの木の根}
if (par[x] == x)
return x;
return par[x] = root(par[x]);
}
void unite(int x, int y) { // xとyの木を併合
int rx = root(x); // xの根をrx
int ry = root(y); // yの根をry
if (rx == ry)
return; // xとyの根が同じ(=同じ木にある)時はそのまま
par[rx] =
ry; // xとyの根が同じでない(=同じ木にない)時:xの根rxをyの根ryにつける
}
bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
int rx = root(x);
int ry = root(y);
return rx == ry;
}
};
typedef long long ll;
ll M = 1000000007;
vector<ll> fac(300001); // n!(mod M)
vector<ll> ifac(300001); // k!^{M-2} (mod M)
ll mpow(ll x, ll n) {
ll ans = 1;
while (n != 0) {
if (n & 1)
ans = ans * x % M;
x = x * x % M;
n = n >> 1;
}
return ans;
}
void setcomb() {
fac[0] = 1;
ifac[0] = 1;
for (ll i = 0; i < 1000000; i++) {
fac[i + 1] = fac[i] * (i + 1) % M; // n!(mod M)
}
ifac[1000000] = mpow(fac[1000000], M - 2);
for (ll i = 1000000; i > 0; i--) {
ifac[i - 1] = ifac[i] * i % M;
}
}
ll comb(ll a, ll b) {
if (a == 0 && b == 0)
return 1;
if (a < b || a < 0)
return 0;
ll tmp = ifac[a - b] * ifac[b] % M;
return tmp * fac[a] % M;
}
ll perm(ll a, ll b) {
if (a == 0 && b == 0)
return 1;
if (a < b || a < 0)
return 0;
return fac[a] * ifac[a - b] % M;
}
// mod. m での a の逆元 a^{-1} を計算する
long long modinv(long long a) {
long long b = M, u = 1, v = 0;
while (b) {
long long t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
u %= M;
if (u < 0)
u += M;
return u;
}
vector<vector<ll>> mul(vector<vector<ll>> a, vector<vector<ll>> b, int n) {
int i, j, k, t;
vector<vector<ll>> c(n);
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
t = 0;
for (k = 0; k < n; k++)
t = (t + a[i][k] * b[k][j] % M) % M;
c[i].push_back(t);
}
}
return c;
}
template <typename Monoid> struct SegmentTree {
int sz;
vector<Monoid> seg;
const Monoid M1;
SegmentTree(int n, const Monoid &M1) : M1(M1) {
sz = 1;
while (sz < n)
sz <<= 1;
seg.assign(2 * sz, M1);
}
void set(int k, const Monoid &x) { seg[k + sz] = x; }
void build() {
for (int k = sz - 1; k > 0; k--) {
seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
}
}
void update(int k, const Monoid &x) {
k += sz;
seg[k] = x;
while (k >>= 1) {
seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
}
}
Monoid query(int a, int b) {
Monoid L = M1, R = M1;
for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
if (a & 1)
L = f(L, seg[a++]);
if (b & 1)
R = f(seg[--b], R);
}
return f(L, R);
}
Monoid value(const int &k) const { return seg[k + sz]; }
Monoid f(Monoid a, Monoid b) { return a + b; }
};
int main() {
ll n, k, i, j, ans = 0, a[2222], count;
cin >> n >> k;
for (i = 0; i < n; i++)
cin >> a[i];
for (i = 0; i < n; i++) {
count = 0;
for (j = 0; j < i; j++)
if (a[j] > a[i])
count++;
ans += count * k % M;
ans %= M;
for (j = i + 1; j < n; j++)
if (a[j] > a[i])
count++;
ans += k * (k - 1) * count % M * modinv(2) % M;
ans %= M;
}
cout << ans << endl;
}
|
#include <algorithm>
#include <iostream>
#include <list>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int gcd(int a, int b) {
int c = a % b;
while (c != 0) {
a = b;
b = c;
c = a % b;
}
return b;
}
struct UnionFind {
vector<int> par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2
UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
for (int i = 0; i < N; i++)
par[i] = i;
}
int root(int x) { // データxが属する木の根を再帰で得る:root(x) = {xの木の根}
if (par[x] == x)
return x;
return par[x] = root(par[x]);
}
void unite(int x, int y) { // xとyの木を併合
int rx = root(x); // xの根をrx
int ry = root(y); // yの根をry
if (rx == ry)
return; // xとyの根が同じ(=同じ木にある)時はそのまま
par[rx] =
ry; // xとyの根が同じでない(=同じ木にない)時:xの根rxをyの根ryにつける
}
bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
int rx = root(x);
int ry = root(y);
return rx == ry;
}
};
typedef long long ll;
ll M = 1000000007;
vector<ll> fac(300001); // n!(mod M)
vector<ll> ifac(300001); // k!^{M-2} (mod M)
ll mpow(ll x, ll n) {
ll ans = 1;
while (n != 0) {
if (n & 1)
ans = ans * x % M;
x = x * x % M;
n = n >> 1;
}
return ans;
}
void setcomb() {
fac[0] = 1;
ifac[0] = 1;
for (ll i = 0; i < 1000000; i++) {
fac[i + 1] = fac[i] * (i + 1) % M; // n!(mod M)
}
ifac[1000000] = mpow(fac[1000000], M - 2);
for (ll i = 1000000; i > 0; i--) {
ifac[i - 1] = ifac[i] * i % M;
}
}
ll comb(ll a, ll b) {
if (a == 0 && b == 0)
return 1;
if (a < b || a < 0)
return 0;
ll tmp = ifac[a - b] * ifac[b] % M;
return tmp * fac[a] % M;
}
ll perm(ll a, ll b) {
if (a == 0 && b == 0)
return 1;
if (a < b || a < 0)
return 0;
return fac[a] * ifac[a - b] % M;
}
// mod. m での a の逆元 a^{-1} を計算する
long long modinv(long long a) {
long long b = M, u = 1, v = 0;
while (b) {
long long t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
u %= M;
if (u < 0)
u += M;
return u;
}
vector<vector<ll>> mul(vector<vector<ll>> a, vector<vector<ll>> b, int n) {
int i, j, k, t;
vector<vector<ll>> c(n);
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
t = 0;
for (k = 0; k < n; k++)
t = (t + a[i][k] * b[k][j] % M) % M;
c[i].push_back(t);
}
}
return c;
}
template <typename Monoid> struct SegmentTree {
int sz;
vector<Monoid> seg;
const Monoid M1;
SegmentTree(int n, const Monoid &M1) : M1(M1) {
sz = 1;
while (sz < n)
sz <<= 1;
seg.assign(2 * sz, M1);
}
void set(int k, const Monoid &x) { seg[k + sz] = x; }
void build() {
for (int k = sz - 1; k > 0; k--) {
seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
}
}
void update(int k, const Monoid &x) {
k += sz;
seg[k] = x;
while (k >>= 1) {
seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
}
}
Monoid query(int a, int b) {
Monoid L = M1, R = M1;
for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
if (a & 1)
L = f(L, seg[a++]);
if (b & 1)
R = f(seg[--b], R);
}
return f(L, R);
}
Monoid value(const int &k) const { return seg[k + sz]; }
Monoid f(Monoid a, Monoid b) { return a + b; }
};
int main() {
ll n, k, i, j, ans = 0, a[2222], count;
cin >> n >> k;
for (i = 0; i < n; i++)
cin >> a[i];
for (i = 0; i < n; i++) {
count = 0;
for (j = 0; j < i; j++)
if (a[j] > a[i])
count++;
ans += count * k % M;
ans %= M;
for (j = i + 1; j < n; j++)
if (a[j] > a[i])
count++;
ans += k * (k - 1) % M * count % M * modinv(2) % M;
ans %= M;
}
cout << ans << endl;
}
|
[
"assignment.change"
] | 731,984
| 731,985
|
u933068010
|
cpp
|
p02928
|
#include <algorithm>
#include <bitset>
#include <complex>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
// typedef pair<int,int> Pint;
// typedef pair<ll, ll> P;
// typedef pair<ll, pair<ll, ll>> P;
// typedef tuple<int,int,int> T;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define revrep(i, n) for (ll i = (n - 1); i >= 0; i--)
#define pb push_back
#define f first
#define s second
// const ll INFL = 1LL << 60;//10^18 = 2^60
const ll INFL = 1LL << 60;
const int INF = 1 << 30; // 10^9
ll MOD = 1000000007;
// ll MOD = 998244353;
vector<ll> dy = {0, 0, 1, -1, 1, 1, -1, -1, 0};
vector<ll> dx = {1, -1, 0, 0, 1, -1, 1, -1, 0};
ll max(ll a, ll b) { return (a > b) ? a : b; }
ll min(ll a, ll b) { return (a < b) ? a : b; }
ll pow_long(ll x, ll k) {
ll res = 1;
while (k > 0) {
if (k % 2)
res *= x;
x *= x;
k /= 2;
}
return res;
}
ll pow_mod(ll x, ll k) {
x %= MOD;
x += MOD;
x %= MOD;
ll res = 1;
while (k > 0) {
if (k % 2) {
res *= x;
res %= MOD;
}
x *= x;
x %= MOD;
k /= 2;
}
return res;
}
ll inverse(ll x) { return pow_mod(x, MOD - 2); };
//最大公約数
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
//最小公倍数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; };
ll kai_mod(ll x) {
if (x == 0)
return 1;
return x * kai_mod(x - 1) % MOD;
}
//コンビネーション
const int MAXcomb = 200010;
ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb];
// facはn!,finvは1/n!
// invは逆元
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAXcomb; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
ll comb(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * finv[k] % MOD * finv[n - k] % MOD;
}
ll solve(ll l, ll r, vector<ll> &A) {
ll res = 0;
ll mid = (l + r) / 2;
if (r - l == 1)
return res;
res += solve(l, mid, A);
res += solve(mid, r, A);
vector<ll> B;
ll x = l, y = mid;
while (x < mid || y < r) {
ll bs = B.size();
if (x == mid) {
B.pb(A[y++]);
} else if (y == r) {
res += bs - x + l;
B.pb(A[x++]);
} else {
if (A[x] <= A[y]) {
res += bs - x + l;
B.pb(A[x++]);
} else {
B.pb(A[y++]);
}
}
}
for (ll i = l; i < r; i++)
A[i] = B[i - l];
return res;
}
int main() {
ll N, K;
cin >> N >> K;
vector<ll> A(N);
rep(i, N) cin >> A[i];
ll ans = solve(0, N, A) * K % MOD;
A.pb(INFL);
rep(i, N) {
ll cnt = 1;
while (A[i] == A[i + 1]) {
i++;
cnt++;
}
ll right = N - i - 1;
ans += K * (K - 1) / 2 % MOD * right % MOD;
ans %= MOD;
}
cout << ans << endl;
}
|
#include <algorithm>
#include <bitset>
#include <complex>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
// typedef pair<int,int> Pint;
// typedef pair<ll, ll> P;
// typedef pair<ll, pair<ll, ll>> P;
// typedef tuple<int,int,int> T;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define revrep(i, n) for (ll i = (n - 1); i >= 0; i--)
#define pb push_back
#define f first
#define s second
// const ll INFL = 1LL << 60;//10^18 = 2^60
const ll INFL = 1LL << 60;
const int INF = 1 << 30; // 10^9
ll MOD = 1000000007;
// ll MOD = 998244353;
vector<ll> dy = {0, 0, 1, -1, 1, 1, -1, -1, 0};
vector<ll> dx = {1, -1, 0, 0, 1, -1, 1, -1, 0};
ll max(ll a, ll b) { return (a > b) ? a : b; }
ll min(ll a, ll b) { return (a < b) ? a : b; }
ll pow_long(ll x, ll k) {
ll res = 1;
while (k > 0) {
if (k % 2)
res *= x;
x *= x;
k /= 2;
}
return res;
}
ll pow_mod(ll x, ll k) {
x %= MOD;
x += MOD;
x %= MOD;
ll res = 1;
while (k > 0) {
if (k % 2) {
res *= x;
res %= MOD;
}
x *= x;
x %= MOD;
k /= 2;
}
return res;
}
ll inverse(ll x) { return pow_mod(x, MOD - 2); };
//最大公約数
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
//最小公倍数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; };
ll kai_mod(ll x) {
if (x == 0)
return 1;
return x * kai_mod(x - 1) % MOD;
}
//コンビネーション
const int MAXcomb = 200010;
ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb];
// facはn!,finvは1/n!
// invは逆元
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAXcomb; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
ll comb(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * finv[k] % MOD * finv[n - k] % MOD;
}
ll solve(ll l, ll r, vector<ll> &A) {
ll res = 0;
ll mid = (l + r) / 2;
if (r - l == 1)
return res;
res += solve(l, mid, A);
res += solve(mid, r, A);
vector<ll> B;
ll x = l, y = mid;
while (x < mid || y < r) {
ll bs = B.size();
if (x == mid) {
B.pb(A[y++]);
} else if (y == r) {
res += bs - x + l;
B.pb(A[x++]);
} else {
if (A[x] <= A[y]) {
res += bs - x + l;
B.pb(A[x++]);
} else {
B.pb(A[y++]);
}
}
}
for (ll i = l; i < r; i++)
A[i] = B[i - l];
return res;
}
int main() {
ll N, K;
cin >> N >> K;
vector<ll> A(N);
rep(i, N) cin >> A[i];
ll ans = solve(0, N, A) * K % MOD;
A.pb(INFL);
rep(i, N) {
ll cnt = 1;
while (A[i] == A[i + 1]) {
i++;
cnt++;
}
ll right = N - i - 1;
ans += K * (K - 1) / 2 % MOD * right % MOD * cnt % MOD;
ans %= MOD;
}
cout << ans << endl;
}
|
[
"assignment.change"
] | 731,988
| 731,989
|
u633284019
|
cpp
|
p02928
|
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
long long mod = 1e9 + 7;
long long N, K;
cin >> N >> K;
vector<int> A(N);
for (auto &a : A)
cin >> a;
long long ans = 0;
for (int i = 0; i < N; ++i) {
for (int j = i + 1; j < N; ++j) {
ans += (A[i] > A[j]);
}
}
ans *= K;
ans %= mod;
vector<int> B = A;
sort(B.begin(), B.end());
for (int i = 0; i < N; ++i) {
long long t = K * (K - 1) / 2;
long long x = lower_bound(B.begin(), B.end(), A[i]) - B.begin();
ans += t * x % mod;
ans %= mod;
}
cout << ans << endl;
}
|
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
long long mod = 1e9 + 7;
long long N, K;
cin >> N >> K;
vector<int> A(N);
for (auto &a : A)
cin >> a;
long long ans = 0;
for (int i = 0; i < N; ++i) {
for (int j = i + 1; j < N; ++j) {
ans += (A[i] > A[j]);
}
}
ans *= K;
ans %= mod;
vector<int> B = A;
sort(B.begin(), B.end());
for (int i = 0; i < N; ++i) {
long long t = K * (K - 1) / 2;
t %= mod;
long long x = lower_bound(B.begin(), B.end(), A[i]) - B.begin();
ans += t * x % mod;
ans %= mod;
}
cout << ans << endl;
}
|
[
"assignment.add"
] | 731,990
| 731,991
|
u107077660
|
cpp
|
p02928
|
#include <iostream>
#include <vector>
using namespace std;
const long mod = int(1e9) + 7;
int main() {
long n, k;
cin >> n >> k;
vector<long> a(n);
for (int i = 0; i < n; i++)
cin >> a[i];
vector<long> rtent(n), tent(n);
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (a[i] > a[j])
tent[i]++;
}
for (int j = i; j < n; j++) {
if (a[i] > a[j])
rtent[i]++;
}
}
long ret = 0;
for (int i = 0; i < n; i++) {
ret += k * (k - 1) / 2 * tent[i] + k * rtent[i];
ret %= mod;
}
cout << ret;
return 0;
}
|
#include <iostream>
#include <vector>
using namespace std;
const long mod = int(1e9) + 7;
int main() {
long n, k;
cin >> n >> k;
vector<long> a(n);
for (int i = 0; i < n; i++)
cin >> a[i];
vector<long> rtent(n), tent(n);
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (a[i] > a[j])
tent[i]++;
}
for (int j = i; j < n; j++) {
if (a[i] > a[j])
rtent[i]++;
}
}
long ret = 0;
for (int i = 0; i < n; i++) {
ret += ((k * (k - 1) / 2) % mod) * tent[i] + k * rtent[i];
ret %= mod;
}
cout << ret;
return 0;
}
|
[] | 731,992
| 731,993
|
u809153881
|
cpp
|
p02928
|
#include <bits/stdc++.h>
#define CEIL(a, b) ((a) / (b) + ((a) % (b) == 0 ? 0 : 1))
using namespace std;
using ll = long long;
using pii = pair<int, int>;
constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'000'000'001;
constexpr ll LLINF = 4'000'000'000'000'000'001;
// constexpr int INF = 2147483647; // 2 * 1e9
// constexpr ll LLINF = 9223372036854775807; // 9 * 1e18
const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1, 0};
const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1, 0};
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout << fixed << setprecision(10);
int n, k;
cin >> n >> k;
vector<int> a(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
vector<int> b(n), c(n);
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if (i == j)
continue;
if (a[i] > a[j]) {
++c[i];
if (i < j)
++b[i];
}
}
}
ll ans = 0;
for (int i = 0; i < n; ++i) {
ans += (ll)b[i] * k + (ll)k * (k - 1) / 2 * c[i];
ans %= MOD;
}
cout << ans << "\n";
return 0;
}
|
#include <bits/stdc++.h>
#define CEIL(a, b) ((a) / (b) + ((a) % (b) == 0 ? 0 : 1))
using namespace std;
using ll = long long;
using pii = pair<int, int>;
constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'000'000'001;
constexpr ll LLINF = 4'000'000'000'000'000'001;
// constexpr int INF = 2147483647; // 2 * 1e9
// constexpr ll LLINF = 9223372036854775807; // 9 * 1e18
const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1, 0};
const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1, 0};
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout << fixed << setprecision(10);
int n, k;
cin >> n >> k;
vector<int> a(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
vector<int> b(n), c(n);
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if (i == j)
continue;
if (a[i] > a[j]) {
++c[i];
if (i < j)
++b[i];
}
}
}
ll ans = 0;
for (int i = 0; i < n; ++i) {
ans += (ll)b[i] * k % MOD + (ll)k * (k - 1) / 2 % MOD * c[i] % MOD;
ans %= MOD;
}
cout << ans << "\n";
return 0;
}
|
[
"assignment.change"
] | 731,994
| 731,995
|
u993640894
|
cpp
|
p02928
|
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define MOD (int)(1e9 + 7)
int main() {
ll N, K;
cin >> N >> K;
vector<int> A(N);
for (int i = 0; i < N; i++) {
cin >> A[i];
}
vector<ll> cnt(N), cnt2(N);
for (int i = 0; i < N; i++) {
for (int j = i + 1; j < N; j++) {
if (A[i] > A[j])
cnt[i]++;
}
for (int j = 0; j < N; j++) {
if (A[i] > A[j])
cnt2[i]++;
}
}
ll ans = 0;
for (int i = 0; i < N; i++) {
ans += (cnt[i] * K) % MOD + cnt2[i] * (K * (K - 1) / 2) % MOD;
ans %= MOD;
}
cout << ans << endl;
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define MOD (int)(1e9 + 7)
int main() {
ll N, K;
cin >> N >> K;
vector<int> A(N);
for (int i = 0; i < N; i++) {
cin >> A[i];
}
vector<ll> cnt(N), cnt2(N);
for (int i = 0; i < N; i++) {
for (int j = i + 1; j < N; j++) {
if (A[i] > A[j])
cnt[i]++;
}
for (int j = 0; j < N; j++) {
if (A[i] > A[j])
cnt2[i]++;
}
}
ll ans = 0;
for (int i = 0; i < N; i++) {
ans += (cnt[i] * K) % MOD + cnt2[i] * ((K * (K - 1) / 2) % MOD);
ans %= MOD;
}
cout << ans << endl;
return 0;
}
|
[] | 731,996
| 731,997
|
u265881782
|
cpp
|
p02928
|
#include <bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define DBG_N(hoge) cerr << " " << (hoge) << endl;
#define DBG cerr << "!" << endl;
#define BITLE(n) (1LL << ((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s, f, t) ((s).substr((f)-1, (t) - (f) + 1))
#define ALL(a) (a).begin(), (a).end()
using namespace std;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll n, k;
cin >> n >> k;
vi A(n);
vi cnt(n);
for (auto &a : A)
cin >> a;
ll ans = 0;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++)
if (A[i] > A[j])
ans++;
}
ans *= k;
ans %= MOD;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++)
if (A[i] > A[j])
cnt[i]++;
}
for (int i = 0; i < n; i++) {
ans += (((k - 1) * k / 2) * (cnt[i])) % MOD;
ans %= MOD;
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define DBG_N(hoge) cerr << " " << (hoge) << endl;
#define DBG cerr << "!" << endl;
#define BITLE(n) (1LL << ((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s, f, t) ((s).substr((f)-1, (t) - (f) + 1))
#define ALL(a) (a).begin(), (a).end()
using namespace std;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll n, k;
cin >> n >> k;
vi A(n);
vi cnt(n);
for (auto &a : A)
cin >> a;
ll ans = 0;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++)
if (A[i] > A[j])
ans++;
}
ans *= k;
ans %= MOD;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++)
if (A[i] > A[j])
cnt[i]++;
}
for (int i = 0; i < n; i++) {
ans += (((k - 1) * k / 2) % MOD * (cnt[i])) % MOD;
ans %= MOD;
}
cout << ans << endl;
return 0;
}
|
[
"assignment.change"
] | 731,998
| 731,999
|
u905715926
|
cpp
|
p02928
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define MOD 1000000007
#define INF (1 << 29)
#define LINF (1LL << 60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;
Int gin[2160];
Int gall[2160];
Int a[2160];
Int res;
Int n, k;
int main() {
cin >> n >> k;
for (int i = 0; i < n; i++) {
cin >> a[i];
for (int j = 0; j < i; j++) {
if (a[j] > a[i])
gin[i]++;
}
}
for (int i = 1; i < n; i++) {
for (int j = 0; j < n; j++) {
if (a[j] > a[i])
gall[i]++;
}
}
for (int i = 0; i < n; i++) {
res += gall[i] * ((k * (k - 1)) / 2 % MOD) % MOD;
res %= MOD;
res += k * gin[i] % MOD;
res %= MOD;
}
cout << res << endl;
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define MOD 1000000007
#define INF (1 << 29)
#define LINF (1LL << 60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;
Int gin[2160];
Int gall[2160];
Int a[2160];
Int res;
Int n, k;
int main() {
cin >> n >> k;
for (int i = 0; i < n; i++) {
cin >> a[i];
for (int j = 0; j < i; j++) {
if (a[j] > a[i])
gin[i]++;
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (a[j] > a[i])
gall[i]++;
}
}
for (int i = 0; i < n; i++) {
res += gall[i] * ((k * (k - 1)) / 2 % MOD) % MOD;
res %= MOD;
res += k * gin[i] % MOD;
res %= MOD;
}
cout << res << endl;
return 0;
}
|
[
"literal.number.change",
"variable_declaration.value.change",
"control_flow.loop.for.initializer.change",
"expression.off_by_one"
] | 732,000
| 732,001
|
u299869545
|
cpp
|
p02928
|
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
typedef long long ll;
typedef long double ld;
#define pii pair<ll, ll>
#define vi vector<ll>
#define vvi vector<vi>
#define vpi vector<pii>
#define vvpi vector<vpi>
#define fast \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0)
#define test(t) \
ll t; \
cin >> t; \
while (t--)
#define mem(a, b) memset(a, b, sizeof(a))
#define inn freopen("input.txt", "r", stdin)
#define outt freopen("output.txt", "w", stdout)
#define all(arr) arr.begin(), arr.end()
#define fr(i, n) for (ll i = 0; i < (n); ++i)
#define rep(i, a, b) for (ll i = a; i <= b; ++i)
#define per(i, a, b) for (ll i = a; i >= b; i--)
#define remin(a, b) (a = min((a), (b)))
#define remax(a, b) (a = max((a), (b)))
ll power(ll x, ll y) {
ll res = 1;
while (y) {
if (y & 1)
res = (res * x) % mod;
y = y / 2, x = (x * x) % mod;
}
return res % mod;
}
signed main() {
fast;
ll n, k;
cin >> n >> k;
ll arr[n];
ll i, j;
for (i = 0; i < n; i++)
cin >> arr[i];
ll ans = 0;
ll p = (k * (k - 1)) / 2;
for (i = 0; i < n; i++) {
ll x = 0, y = 0;
for (j = i + 1; j < n; j++) {
if (arr[i] > arr[j])
x++;
}
for (j = 0; j < n; j++) {
if (arr[i] > arr[j])
y++;
}
ans = ans + k * x % mod + p * y % mod;
ans %= mod;
}
cout << ans;
}
|
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
typedef long long ll;
typedef long double ld;
#define pii pair<ll, ll>
#define vi vector<ll>
#define vvi vector<vi>
#define vpi vector<pii>
#define vvpi vector<vpi>
#define fast \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0)
#define test(t) \
ll t; \
cin >> t; \
while (t--)
#define mem(a, b) memset(a, b, sizeof(a))
#define inn freopen("input.txt", "r", stdin)
#define outt freopen("output.txt", "w", stdout)
#define all(arr) arr.begin(), arr.end()
#define fr(i, n) for (ll i = 0; i < (n); ++i)
#define rep(i, a, b) for (ll i = a; i <= b; ++i)
#define per(i, a, b) for (ll i = a; i >= b; i--)
#define remin(a, b) (a = min((a), (b)))
#define remax(a, b) (a = max((a), (b)))
ll power(ll x, ll y) {
ll res = 1;
while (y) {
if (y & 1)
res = (res * x) % mod;
y = y / 2, x = (x * x) % mod;
}
return res % mod;
}
signed main() {
fast;
ll n, k;
cin >> n >> k;
ll arr[n];
ll i, j;
for (i = 0; i < n; i++)
cin >> arr[i];
ll ans = 0;
ll p = (k * (k - 1)) / 2;
p = p % mod;
for (i = 0; i < n; i++) {
ll x = 0, y = 0;
for (j = i + 1; j < n; j++) {
if (arr[i] > arr[j])
x++;
}
for (j = 0; j < n; j++) {
if (arr[i] > arr[j])
y++;
}
ans = ans + k * x % mod + p * y % mod;
ans %= mod;
}
cout << ans;
}
|
[
"assignment.add"
] | 732,008
| 732,009
|
u232189905
|
cpp
|
p02928
|
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3f;
int a[30000];
int main() {
ll n, K;
cin >> n >> K;
rep(i, n) scanf("%d", &a[i]);
ll ans = 0;
rep(i, n) {
ll c1 = 0, c2 = 0;
for (int j = 0; j < i; j++) {
if (a[j] > a[i])
c1++;
}
rep(j, n) {
if (a[j] > a[i])
c2++;
}
ll d = (K - 1) * K / 2 * c2 + c1 * K;
(ans += d) %= MOD;
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3f;
int a[30000];
int main() {
ll n, K;
cin >> n >> K;
rep(i, n) scanf("%d", &a[i]);
ll ans = 0;
rep(i, n) {
ll c1 = 0, c2 = 0;
for (int j = 0; j < i; j++) {
if (a[j] > a[i])
c1++;
}
rep(j, n) {
if (a[j] > a[i])
c2++;
}
ll d = (K - 1) * K / 2 % MOD * c2 + c1 * K;
(ans += d) %= MOD;
}
cout << ans << endl;
}
|
[
"assignment.change"
] | 732,014
| 732,015
|
u781091740
|
cpp
|
p02928
|
#include <bits/stdc++.h>
#define MOD 1000000007
int ri() {
int n;
scanf("%d", &n);
return n;
}
int main() {
int n = ri();
int k = ri();
int a[n];
for (int i = 0; i < n; i++)
a[i] = ri();
int64_t res = 0;
for (int i = 0; i < n; i++) {
int every = 0;
int cur = 0;
for (int j = 0; j < n; j++)
if (a[j] > a[i]) {
if (j < i)
cur++;
every++;
}
res += ((int64_t)k * (k - 1) / 2 * every + (int64_t)k * cur) % MOD;
}
std::cout << res % MOD << std::endl;
return 0;
}
|
#include <bits/stdc++.h>
#define MOD 1000000007
int ri() {
int n;
scanf("%d", &n);
return n;
}
int main() {
int n = ri();
int k = ri();
int a[n];
for (int i = 0; i < n; i++)
a[i] = ri();
int64_t res = 0;
for (int i = 0; i < n; i++) {
int every = 0;
int cur = 0;
for (int j = 0; j < n; j++)
if (a[j] > a[i]) {
if (j < i)
cur++;
every++;
}
res += ((int64_t)k * (k - 1) / 2 % MOD * every + (int64_t)k * cur) % MOD;
}
std::cout << res % MOD << std::endl;
return 0;
}
|
[
"assignment.change"
] | 732,016
| 732,017
|
u040490988
|
cpp
|
p02929
|
#include <bits/stdc++.h>
using namespace std;
#define int ll
#define ll long long
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
// #define MOD 998244353
#define MEM_SIZE 101010
#define DEBUG_OUT true
#define ALL(x) (x).begin(), (x).end()
template <typename T> void DEBUG(T e) {
if (DEBUG_OUT == false)
return;
std::cout << e << " ";
}
template <typename T> void DEBUG(const std::vector<T> &v) {
if (DEBUG_OUT == false)
return;
for (const auto &e : v) {
std::cout << e << " ";
}
std::cout << std::endl;
}
template <typename T> void DEBUG(const std::vector<std::vector<T>> &vv) {
if (DEBUG_OUT == false)
return;
for (const auto &v : vv) {
DEBUG(v);
}
}
template <class T, class... Ts> void DEBUG(T d, Ts... e) {
if (DEBUG_OUT == false)
return;
DEBUG(d);
DEBUG(e...);
}
template <class T> void corner(bool flg, T hoge) {
if (flg) {
cout << hoge << endl;
abort();
}
}
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
return a < b && (a = b, true);
}
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
return a > b && (a = b, true);
}
// BELOW
// BELOW
struct mint {
int x; // typedef long long int;
mint(int x = 0) : x((x % MOD + MOD) % MOD) {}
mint &operator+=(const mint a) {
if ((x += a.x) >= MOD)
x -= MOD;
return *this;
}
mint &operator-=(const mint a) {
if ((x += MOD - a.x) >= MOD)
x -= MOD;
return *this;
}
mint &operator*=(const mint a) {
(x *= a.x) %= MOD;
return *this;
}
mint operator+(const mint a) const {
mint res(*this);
return res += a;
}
mint operator-(const mint a) const {
mint res(*this);
return res -= a;
}
mint operator*(const mint a) const {
mint res(*this);
return res *= a;
}
mint pow(int t) const {
if (!t)
return 1;
mint a = pow(t >> 1);
a *= a;
if (t & 1)
a *= *this;
return a;
}
// for prime MOD
mint inv() const { return pow(MOD - 2); }
mint &operator/=(const mint a) { return (*this) *= a.inv(); }
mint operator/(const mint a) const {
mint res(*this);
return res /= a;
}
};
const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
int COM(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int PERM(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[n - k] % MOD) % MOD;
}
int MCOM(int n, int k) {
// n個のものから重複を許してr個選ぶ。
// Choose R from N types of things, allowing for duplication.
return COM(n + k - 1, k);
}
// solve
//-----CODE------//
void solve(void) {
int n;
string s;
cin >> n >> s;
mint res = 1;
int now = 0;
for (int i = 0; i < 2 * n; i++) {
if (s[i] == 'W') {
if (now == 0) {
cout << 0 << endl;
return;
}
if (now % 2) {
now++;
} else {
res *= now;
now--;
}
} else {
if (now % 2) {
res *= now;
now--;
} else {
now++;
}
}
DEBUG(now);
}
if (now != 0) {
cout << 0 << endl;
return;
}
for (int i = 2; i <= n; i++) {
res *= i;
}
cout << res.x << endl;
}
int32_t main(int32_t argc, const char *argv[]) {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
std::cout << std::fixed;
std::cout << std::setprecision(11);
solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define int ll
#define ll long long
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
// #define MOD 998244353
#define MEM_SIZE 101010
#define DEBUG_OUT true
#define ALL(x) (x).begin(), (x).end()
template <typename T> void DEBUG(T e) {
if (DEBUG_OUT == false)
return;
std::cout << e << " ";
}
template <typename T> void DEBUG(const std::vector<T> &v) {
if (DEBUG_OUT == false)
return;
for (const auto &e : v) {
std::cout << e << " ";
}
std::cout << std::endl;
}
template <typename T> void DEBUG(const std::vector<std::vector<T>> &vv) {
if (DEBUG_OUT == false)
return;
for (const auto &v : vv) {
DEBUG(v);
}
}
template <class T, class... Ts> void DEBUG(T d, Ts... e) {
if (DEBUG_OUT == false)
return;
DEBUG(d);
DEBUG(e...);
}
template <class T> void corner(bool flg, T hoge) {
if (flg) {
cout << hoge << endl;
abort();
}
}
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
return a < b && (a = b, true);
}
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
return a > b && (a = b, true);
}
// BELOW
// BELOW
struct mint {
int x; // typedef long long int;
mint(int x = 0) : x((x % MOD + MOD) % MOD) {}
mint &operator+=(const mint a) {
if ((x += a.x) >= MOD)
x -= MOD;
return *this;
}
mint &operator-=(const mint a) {
if ((x += MOD - a.x) >= MOD)
x -= MOD;
return *this;
}
mint &operator*=(const mint a) {
(x *= a.x) %= MOD;
return *this;
}
mint operator+(const mint a) const {
mint res(*this);
return res += a;
}
mint operator-(const mint a) const {
mint res(*this);
return res -= a;
}
mint operator*(const mint a) const {
mint res(*this);
return res *= a;
}
mint pow(int t) const {
if (!t)
return 1;
mint a = pow(t >> 1);
a *= a;
if (t & 1)
a *= *this;
return a;
}
// for prime MOD
mint inv() const { return pow(MOD - 2); }
mint &operator/=(const mint a) { return (*this) *= a.inv(); }
mint operator/(const mint a) const {
mint res(*this);
return res /= a;
}
};
const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
int COM(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int PERM(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[n - k] % MOD) % MOD;
}
int MCOM(int n, int k) {
// n個のものから重複を許してr個選ぶ。
// Choose R from N types of things, allowing for duplication.
return COM(n + k - 1, k);
}
// solve
//-----CODE------//
void solve(void) {
int n;
string s;
cin >> n >> s;
mint res = 1;
int now = 0;
for (int i = 0; i < 2 * n; i++) {
if (s[i] == 'W') {
if (now == 0) {
cout << 0 << endl;
return;
}
if (now % 2) {
now++;
} else {
res *= now;
now--;
}
} else {
if (now % 2) {
res *= now;
now--;
} else {
now++;
}
}
// DEBUG(now);
}
if (now != 0) {
cout << 0 << endl;
return;
}
for (int i = 2; i <= n; i++) {
res *= i;
}
cout << res.x << endl;
}
int32_t main(int32_t argc, const char *argv[]) {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
std::cout << std::fixed;
std::cout << std::setprecision(11);
solve();
return 0;
}
|
[
"call.remove"
] | 732,038
| 732,039
|
u221285045
|
cpp
|
p02929
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define reps(i, n) for (int i = 1; i <= (int)(n); ++i)
#define repd(i, n) for (int i = (int)(n - 1); i >= 0; --i)
#define repds(i, n) for (int i = (int)(n); i > 0; --i)
#define all(f, x, ...) \
([&](decltype((x)) whole) { \
return (f)(begin(whole), end(whole), ##__VA_ARGS__); \
})(x)
#define rall(f, x, ...) \
([&](decltype((x)) whole) { \
return (f)(rbegin(whole), rend(whole), ##__VA_ARGS__); \
})(x)
#define sz(a) (int)(a).size()
using ll = long long;
using ld = long double;
constexpr ll inf = static_cast<ll>(1e17);
constexpr int iinf = static_cast<int>(1e9);
constexpr ll mod = static_cast<ll>(1e9 + 7);
int n;
string s;
void solve() {
cin >> n >> s;
ll ans = 1;
ll cnt = 0;
for (int i = 0; i < 2 * n; ++i) {
ll now = ((s[i] == 'W') + cnt) % 2;
if (now == 0) {
++cnt;
} else {
if (cnt == 0) {
cout << 0 << endl;
return;
}
ans *= cnt;
ans %= mod;
--cnt;
}
}
if (cnt != 0)
cout << 0 << endl;
reps(i, n) {
ans *= i;
ans %= mod;
}
cout << ans << endl;
return;
}
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define reps(i, n) for (int i = 1; i <= (int)(n); ++i)
#define repd(i, n) for (int i = (int)(n - 1); i >= 0; --i)
#define repds(i, n) for (int i = (int)(n); i > 0; --i)
#define all(f, x, ...) \
([&](decltype((x)) whole) { \
return (f)(begin(whole), end(whole), ##__VA_ARGS__); \
})(x)
#define rall(f, x, ...) \
([&](decltype((x)) whole) { \
return (f)(rbegin(whole), rend(whole), ##__VA_ARGS__); \
})(x)
#define sz(a) (int)(a).size()
using ll = long long;
using ld = long double;
constexpr ll inf = static_cast<ll>(1e17);
constexpr int iinf = static_cast<int>(1e9);
constexpr ll mod = static_cast<ll>(1e9 + 7);
int n;
string s;
void solve() {
cin >> n >> s;
ll ans = 1;
ll cnt = 0;
for (int i = 0; i < 2 * n; ++i) {
ll now = ((s[i] == 'W') + cnt) % 2;
if (now == 0) {
++cnt;
} else {
if (cnt == 0) {
cout << 0 << endl;
return;
}
ans *= cnt;
ans %= mod;
--cnt;
}
}
if (cnt != 0) {
cout << 0 << endl;
return;
}
reps(i, n) {
ans *= i;
ans %= mod;
}
cout << ans << endl;
return;
}
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
solve();
return 0;
}
|
[
"control_flow.return.add"
] | 732,042
| 732,043
|
u640248738
|
cpp
|
p02929
|
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
template <int MOD> class Modular {
private:
long long value;
public:
constexpr Modular() : value(){};
constexpr Modular(const Modular &other) : value(other.value) {}
template <typename U> constexpr Modular(const U &x) { value = normalize(x); }
template <typename U> static long long normalize(const U &x) {
long long v;
if (-MOD <= x && x < MOD)
v = static_cast<long long>(x);
else
v = static_cast<long long>(x % MOD);
if (v < 0)
v += MOD;
return v;
}
constexpr long long inverse(long long x) {
x = (x % MOD + MOD) % MOD;
long long y = MOD, u = 1, v = 0;
while (y) {
long long t = x / y;
x -= t * y;
swap(x, y);
u -= t * v;
swap(u, v);
}
return (u % MOD + MOD) % MOD;
}
explicit operator long long() const noexcept { return value; }
template <typename U> explicit operator U() const noexcept {
return static_cast<U>(value);
}
constexpr Modular &operator=(const Modular &other) &noexcept {
value = other.value;
return *this;
}
template <typename U> constexpr Modular &operator=(const U &other) &noexcept {
return *this = Modular(other);
}
constexpr Modular &operator+=(const Modular &other) noexcept {
if ((value += other.value) >= MOD)
value -= MOD;
return *this;
}
template <typename U> constexpr Modular &operator+=(const U &other) noexcept {
return *this += Modular(other);
}
constexpr Modular &operator-=(const Modular &other) noexcept {
if ((value -= other.value) < 0)
value += MOD;
return *this;
}
template <typename U> constexpr Modular &operator-=(const U &other) noexcept {
return *this -= Modular(other);
}
constexpr Modular &operator*=(const Modular &other) noexcept {
value = value * other.value % MOD;
return *this;
}
template <typename U> constexpr Modular &operator*=(const U &other) noexcept {
return *this *= Modular(other);
}
constexpr Modular &operator/=(const Modular &other) noexcept {
return *this *= Modular(inverse(other.value));
}
template <typename U> constexpr Modular &operator/=(const U &other) noexcept {
return *this *= Modular(inverse(normalize(other)));
}
constexpr Modular &operator++() noexcept { return *this += 1; }
constexpr Modular operator++(int) noexcept {
Modular ret(*this);
*this += 1;
return ret;
}
constexpr Modular &operator--() noexcept { return *this -= 1; }
constexpr Modular operator--(int) noexcept {
Modular ret(*this);
*this += 1;
return ret;
}
constexpr Modular operator-() const { return Modular(-value); }
friend constexpr bool operator==(const Modular<MOD> &lhs,
const Modular<MOD> &rhs) noexcept {
return lhs.value == rhs.value;
}
template <typename U>
friend constexpr bool operator==(const Modular<MOD> &lhs, U rhs) noexcept {
return lhs == Modular<MOD>(rhs);
}
template <typename U>
friend constexpr bool operator==(U lhs, const Modular<MOD> &rhs) noexcept {
return Modular<MOD>(lhs) == rhs;
}
friend constexpr bool operator!=(const Modular<MOD> &lhs,
const Modular<MOD> &rhs) noexcept {
return !(lhs == rhs);
}
template <typename U>
friend constexpr bool operator!=(const Modular<MOD> &lhs, U rhs) noexcept {
return !(lhs == rhs);
}
template <typename U>
friend constexpr bool operator!=(U lhs, const Modular<MOD> rhs) noexcept {
return !(lhs == rhs);
}
friend constexpr bool operator<(const Modular<MOD> &lhs,
const Modular<MOD> &rhs) noexcept {
return lhs.value < rhs.value;
}
template <typename U>
friend constexpr bool operator<(const Modular<MOD> &lhs, U rhs) noexcept {
return lhs.value < rhs;
}
template <typename U>
friend constexpr bool operator<(U lhs, const Modular<MOD> &rhs) noexcept {
return lhs < rhs.value;
}
friend constexpr bool operator>(const Modular<MOD> &lhs,
const Modular<MOD> &rhs) noexcept {
return rhs.value < lhs.value;
}
template <typename U>
friend constexpr bool operator>(const Modular<MOD> &lhs, U rhs) noexcept {
return rhs.value < lhs;
}
template <typename U>
friend constexpr bool operator>(U lhs, const Modular<MOD> &rhs) noexcept {
return rhs < lhs.value;
}
friend constexpr bool operator<=(const Modular<MOD> &lhs,
const Modular<MOD> &rhs) noexcept {
return !(lhs.value > rhs.value);
}
template <typename U>
friend constexpr bool operator<=(const Modular<MOD> &lhs, U rhs) noexcept {
return !(lhs.value > rhs);
}
template <typename U>
friend constexpr bool operator<=(U lhs, const Modular<MOD> &rhs) noexcept {
return !(lhs < rhs.value);
}
friend constexpr bool operator>=(const Modular<MOD> &lhs,
const Modular<MOD> &rhs) noexcept {
return !(lhs.value < rhs.value);
}
template <typename U>
friend constexpr bool operator>=(const Modular<MOD> &lhs, U rhs) noexcept {
return !(lhs.value < rhs);
}
template <typename U>
friend constexpr bool operator>=(U lhs, const Modular<MOD> &rhs) noexcept {
return !(lhs < rhs.value);
}
friend constexpr Modular<MOD> operator+(const Modular<MOD> &lhs,
const Modular<MOD> &rhs) noexcept {
return Modular<MOD>(lhs) += rhs;
}
template <typename U>
friend constexpr Modular<MOD> operator+(const Modular<MOD> &lhs,
U rhs) noexcept {
return Modular<MOD>(lhs) += rhs;
}
template <typename U>
friend constexpr Modular<MOD> operator+(U lhs,
const Modular<MOD> &rhs) noexcept {
return Modular<MOD>(lhs) += rhs;
}
friend constexpr Modular<MOD> operator-(const Modular<MOD> &lhs,
const Modular<MOD> &rhs) noexcept {
return Modular<MOD>(lhs) -= rhs;
}
template <typename U>
friend constexpr Modular<MOD> operator-(const Modular<MOD> &lhs,
U rhs) noexcept {
return Modular<MOD>(lhs) -= rhs;
}
template <typename U>
friend constexpr Modular<MOD> operator-(U lhs,
const Modular<MOD> &rhs) noexcept {
return Modular<MOD>(lhs) -= rhs;
}
friend constexpr Modular<MOD> operator*(const Modular<MOD> &lhs,
const Modular<MOD> &rhs) noexcept {
return Modular<MOD>(lhs) *= rhs;
}
template <typename U>
friend constexpr Modular<MOD> operator*(const Modular<MOD> &lhs,
U rhs) noexcept {
return Modular<MOD>(lhs) *= rhs;
}
template <typename U>
friend constexpr Modular<MOD> operator*(U lhs,
const Modular<MOD> &rhs) noexcept {
return Modular<MOD>(lhs) *= rhs;
}
friend constexpr Modular<MOD> operator/(const Modular<MOD> &lhs,
const Modular<MOD> &rhs) noexcept {
return Modular<MOD>(lhs) /= rhs;
}
template <typename U>
friend constexpr Modular<MOD> operator/(const Modular<MOD> &lhs,
U rhs) noexcept {
return Modular<MOD>(lhs) /= rhs;
}
template <typename U>
friend constexpr Modular<MOD> operator/(U lhs,
const Modular<MOD> &rhs) noexcept {
return Modular<MOD>(lhs) /= rhs;
}
friend std::ostream &operator<<(std::ostream &stream,
const Modular<MOD> &number) noexcept {
return stream << number.value;
}
friend std::istream &operator>>(std::istream &stream, Modular<MOD> &number) {
long long in;
stream >> in;
number.value = Modular<MOD>::normalize(in);
return stream;
}
constexpr int getmod() const { return MOD; }
};
template <int MOD, typename U>
Modular<MOD> power(const Modular<MOD> &x, const U &y) {
assert(y >= 0);
Modular<MOD> k = x, result = 1;
U p = y;
while (p > 0) {
if (p & 1)
result *= k;
k *= k;
p >>= 1;
}
return result;
}
template <int MOD> class BinaryCoefficients {
private:
vector<Modular<MOD>> fact_, inv_, finv_;
public:
constexpr BinaryCoefficients(int n = 2020200)
: fact_(n, 1), inv_(n, 1), finv_(n, 1) {
for (int i = 2; i < n; i++) {
fact_[i] = fact_[i - 1] * i;
inv_[i] = -inv_[MOD % i] * (MOD / i);
finv_[i] = finv_[i - 1] * inv_[i];
}
}
constexpr Modular<MOD> comb(int n, int k) const noexcept {
if (n < k || n < 0 || k < 0)
return 0;
return fact_[n] * finv_[k] * finv_[n - k];
}
constexpr Modular<MOD> fact(int n) const noexcept {
if (n < 0)
return 0;
return fact_[n];
}
constexpr Modular<MOD> inv(int n) const noexcept {
if (n < 0)
return 0;
return inv_[n];
}
constexpr Modular<MOD> finv(int n) const noexcept {
if (n < 0)
return 0;
return finv_[n];
}
};
constexpr int mod = 1e9 + 7;
// constexpr int mod = 998244353;
using mint = Modular<mod>;
using bicoef = BinaryCoefficients<mod>;
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
// c
int n;
cin >> n;
string s;
cin >> s;
mint ans = 1;
long long cur = 0;
for (int i = 0; i < 2 * n; i++) {
if (s[i] == 'B') {
if (cur % 2 == 0 && cur >= 0)
cur++;
else {
ans *= cur;
cur--;
// assert(cur >= 0);
}
} else {
if (cur % 2 == 1 && cur >= 0)
cur++;
else {
ans *= cur;
cur--;
// assert(cur >= 0);
}
}
if (cur < 0) {
cout << 0 << endl;
return 0;
}
// assert(cur >= 0);
}
bicoef bc(n + 100);
ans *= bc.fact(n);
cout << ans << endl;
return 0;
}
|
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
template <int MOD> class Modular {
private:
long long value;
public:
constexpr Modular() : value(){};
constexpr Modular(const Modular &other) : value(other.value) {}
template <typename U> constexpr Modular(const U &x) { value = normalize(x); }
template <typename U> static long long normalize(const U &x) {
long long v;
if (-MOD <= x && x < MOD)
v = static_cast<long long>(x);
else
v = static_cast<long long>(x % MOD);
if (v < 0)
v += MOD;
return v;
}
constexpr long long inverse(long long x) {
x = (x % MOD + MOD) % MOD;
long long y = MOD, u = 1, v = 0;
while (y) {
long long t = x / y;
x -= t * y;
swap(x, y);
u -= t * v;
swap(u, v);
}
return (u % MOD + MOD) % MOD;
}
explicit operator long long() const noexcept { return value; }
template <typename U> explicit operator U() const noexcept {
return static_cast<U>(value);
}
constexpr Modular &operator=(const Modular &other) &noexcept {
value = other.value;
return *this;
}
template <typename U> constexpr Modular &operator=(const U &other) &noexcept {
return *this = Modular(other);
}
constexpr Modular &operator+=(const Modular &other) noexcept {
if ((value += other.value) >= MOD)
value -= MOD;
return *this;
}
template <typename U> constexpr Modular &operator+=(const U &other) noexcept {
return *this += Modular(other);
}
constexpr Modular &operator-=(const Modular &other) noexcept {
if ((value -= other.value) < 0)
value += MOD;
return *this;
}
template <typename U> constexpr Modular &operator-=(const U &other) noexcept {
return *this -= Modular(other);
}
constexpr Modular &operator*=(const Modular &other) noexcept {
value = value * other.value % MOD;
return *this;
}
template <typename U> constexpr Modular &operator*=(const U &other) noexcept {
return *this *= Modular(other);
}
constexpr Modular &operator/=(const Modular &other) noexcept {
return *this *= Modular(inverse(other.value));
}
template <typename U> constexpr Modular &operator/=(const U &other) noexcept {
return *this *= Modular(inverse(normalize(other)));
}
constexpr Modular &operator++() noexcept { return *this += 1; }
constexpr Modular operator++(int) noexcept {
Modular ret(*this);
*this += 1;
return ret;
}
constexpr Modular &operator--() noexcept { return *this -= 1; }
constexpr Modular operator--(int) noexcept {
Modular ret(*this);
*this += 1;
return ret;
}
constexpr Modular operator-() const { return Modular(-value); }
friend constexpr bool operator==(const Modular<MOD> &lhs,
const Modular<MOD> &rhs) noexcept {
return lhs.value == rhs.value;
}
template <typename U>
friend constexpr bool operator==(const Modular<MOD> &lhs, U rhs) noexcept {
return lhs == Modular<MOD>(rhs);
}
template <typename U>
friend constexpr bool operator==(U lhs, const Modular<MOD> &rhs) noexcept {
return Modular<MOD>(lhs) == rhs;
}
friend constexpr bool operator!=(const Modular<MOD> &lhs,
const Modular<MOD> &rhs) noexcept {
return !(lhs == rhs);
}
template <typename U>
friend constexpr bool operator!=(const Modular<MOD> &lhs, U rhs) noexcept {
return !(lhs == rhs);
}
template <typename U>
friend constexpr bool operator!=(U lhs, const Modular<MOD> rhs) noexcept {
return !(lhs == rhs);
}
friend constexpr bool operator<(const Modular<MOD> &lhs,
const Modular<MOD> &rhs) noexcept {
return lhs.value < rhs.value;
}
template <typename U>
friend constexpr bool operator<(const Modular<MOD> &lhs, U rhs) noexcept {
return lhs.value < rhs;
}
template <typename U>
friend constexpr bool operator<(U lhs, const Modular<MOD> &rhs) noexcept {
return lhs < rhs.value;
}
friend constexpr bool operator>(const Modular<MOD> &lhs,
const Modular<MOD> &rhs) noexcept {
return rhs.value < lhs.value;
}
template <typename U>
friend constexpr bool operator>(const Modular<MOD> &lhs, U rhs) noexcept {
return rhs.value < lhs;
}
template <typename U>
friend constexpr bool operator>(U lhs, const Modular<MOD> &rhs) noexcept {
return rhs < lhs.value;
}
friend constexpr bool operator<=(const Modular<MOD> &lhs,
const Modular<MOD> &rhs) noexcept {
return !(lhs.value > rhs.value);
}
template <typename U>
friend constexpr bool operator<=(const Modular<MOD> &lhs, U rhs) noexcept {
return !(lhs.value > rhs);
}
template <typename U>
friend constexpr bool operator<=(U lhs, const Modular<MOD> &rhs) noexcept {
return !(lhs < rhs.value);
}
friend constexpr bool operator>=(const Modular<MOD> &lhs,
const Modular<MOD> &rhs) noexcept {
return !(lhs.value < rhs.value);
}
template <typename U>
friend constexpr bool operator>=(const Modular<MOD> &lhs, U rhs) noexcept {
return !(lhs.value < rhs);
}
template <typename U>
friend constexpr bool operator>=(U lhs, const Modular<MOD> &rhs) noexcept {
return !(lhs < rhs.value);
}
friend constexpr Modular<MOD> operator+(const Modular<MOD> &lhs,
const Modular<MOD> &rhs) noexcept {
return Modular<MOD>(lhs) += rhs;
}
template <typename U>
friend constexpr Modular<MOD> operator+(const Modular<MOD> &lhs,
U rhs) noexcept {
return Modular<MOD>(lhs) += rhs;
}
template <typename U>
friend constexpr Modular<MOD> operator+(U lhs,
const Modular<MOD> &rhs) noexcept {
return Modular<MOD>(lhs) += rhs;
}
friend constexpr Modular<MOD> operator-(const Modular<MOD> &lhs,
const Modular<MOD> &rhs) noexcept {
return Modular<MOD>(lhs) -= rhs;
}
template <typename U>
friend constexpr Modular<MOD> operator-(const Modular<MOD> &lhs,
U rhs) noexcept {
return Modular<MOD>(lhs) -= rhs;
}
template <typename U>
friend constexpr Modular<MOD> operator-(U lhs,
const Modular<MOD> &rhs) noexcept {
return Modular<MOD>(lhs) -= rhs;
}
friend constexpr Modular<MOD> operator*(const Modular<MOD> &lhs,
const Modular<MOD> &rhs) noexcept {
return Modular<MOD>(lhs) *= rhs;
}
template <typename U>
friend constexpr Modular<MOD> operator*(const Modular<MOD> &lhs,
U rhs) noexcept {
return Modular<MOD>(lhs) *= rhs;
}
template <typename U>
friend constexpr Modular<MOD> operator*(U lhs,
const Modular<MOD> &rhs) noexcept {
return Modular<MOD>(lhs) *= rhs;
}
friend constexpr Modular<MOD> operator/(const Modular<MOD> &lhs,
const Modular<MOD> &rhs) noexcept {
return Modular<MOD>(lhs) /= rhs;
}
template <typename U>
friend constexpr Modular<MOD> operator/(const Modular<MOD> &lhs,
U rhs) noexcept {
return Modular<MOD>(lhs) /= rhs;
}
template <typename U>
friend constexpr Modular<MOD> operator/(U lhs,
const Modular<MOD> &rhs) noexcept {
return Modular<MOD>(lhs) /= rhs;
}
friend std::ostream &operator<<(std::ostream &stream,
const Modular<MOD> &number) noexcept {
return stream << number.value;
}
friend std::istream &operator>>(std::istream &stream, Modular<MOD> &number) {
long long in;
stream >> in;
number.value = Modular<MOD>::normalize(in);
return stream;
}
constexpr int getmod() const { return MOD; }
};
template <int MOD, typename U>
Modular<MOD> power(const Modular<MOD> &x, const U &y) {
assert(y >= 0);
Modular<MOD> k = x, result = 1;
U p = y;
while (p > 0) {
if (p & 1)
result *= k;
k *= k;
p >>= 1;
}
return result;
}
template <int MOD> class BinaryCoefficients {
private:
vector<Modular<MOD>> fact_, inv_, finv_;
public:
constexpr BinaryCoefficients(int n = 2020200)
: fact_(n, 1), inv_(n, 1), finv_(n, 1) {
for (int i = 2; i < n; i++) {
fact_[i] = fact_[i - 1] * i;
inv_[i] = -inv_[MOD % i] * (MOD / i);
finv_[i] = finv_[i - 1] * inv_[i];
}
}
constexpr Modular<MOD> comb(int n, int k) const noexcept {
if (n < k || n < 0 || k < 0)
return 0;
return fact_[n] * finv_[k] * finv_[n - k];
}
constexpr Modular<MOD> fact(int n) const noexcept {
if (n < 0)
return 0;
return fact_[n];
}
constexpr Modular<MOD> inv(int n) const noexcept {
if (n < 0)
return 0;
return inv_[n];
}
constexpr Modular<MOD> finv(int n) const noexcept {
if (n < 0)
return 0;
return finv_[n];
}
};
constexpr int mod = 1e9 + 7;
// constexpr int mod = 998244353;
using mint = Modular<mod>;
using bicoef = BinaryCoefficients<mod>;
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
// c
int n;
cin >> n;
string s;
cin >> s;
mint ans = 1;
long long cur = 0;
for (int i = 0; i < 2 * n; i++) {
if (s[i] == 'B') {
if (cur % 2 == 0 && cur >= 0)
cur++;
else {
ans *= cur;
cur--;
// assert(cur >= 0);
}
} else {
if (cur % 2 == 1 && cur >= 0)
cur++;
else {
ans *= cur;
cur--;
// assert(cur >= 0);
}
}
// assert(cur >= 0);
}
if (cur != 0) {
cout << 0 << endl;
return 0;
}
bicoef bc(n + 100);
ans *= bc.fact(n);
cout << ans << endl;
return 0;
}
|
[
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 732,044
| 732,045
|
u817760251
|
cpp
|
p02929
|
#include <bits/stdc++.h>
using namespace std;
#define next Next
#define last Last
#define int long long
const int mod = 1e9 + 7;
const int N = 2e5 + 5;
/*char buf[1<<21],*p1=buf,*p2=buf;
inline int gc(){return
p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}*/
#define gc getchar
inline int read() {
int ret = 0, f = 0;
char c = gc();
while (!isdigit(c)) {
if (c == '-')
f = 1;
c = gc();
}
while (isdigit(c)) {
ret = ret * 10 + c - 48;
c = gc();
}
if (f)
return -ret;
return ret;
}
int n, gs1, gs2, ans = 1, vis[N][2];
char a[N];
map<int, int> dp[N];
int dfs(int x, int y) {
if (x > n * 2)
return 1;
if (dp[x].count(y))
return dp[x][y];
if (a[x] == 'B') {
if (y % 2 == 0)
return dp[x][y] = dfs(x + 1, y + 1);
else
return dp[x][y] = y * dfs(x + 1, y - 1) % mod;
} else {
if (y % 2 == 0)
return dp[x][y] = y * dfs(x + 1, y - 1) % mod;
else
return dp[x][y] = dfs(x + 1, y + 1);
}
}
signed main() {
n = read();
scanf("%s", a + 1);
// for(int i=1;i<=2*n;i++)
// if(a[i]=='W')gs1++;
// else gs2++;
// if(gs1!=gs2){puts("0");return 0;}
for (int i = 1; i <= n; i++)
ans = ans * i % mod;
cout << ans * dfs(1, 0) % mod << endl;
// cout<<dp[4][1]<<endl;
}
|
#include <bits/stdc++.h>
using namespace std;
#define next Next
#define last Last
#define int long long
const int mod = 1e9 + 7;
const int N = 2e5 + 5;
/*char buf[1<<21],*p1=buf,*p2=buf;
inline int gc(){return
p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}*/
#define gc getchar
inline int read() {
int ret = 0, f = 0;
char c = gc();
while (!isdigit(c)) {
if (c == '-')
f = 1;
c = gc();
}
while (isdigit(c)) {
ret = ret * 10 + c - 48;
c = gc();
}
if (f)
return -ret;
return ret;
}
int n, gs1, gs2, ans = 1, vis[N][2];
char a[N];
map<int, int> dp[N];
int dfs(int x, int y) {
if (x > n * 2)
return y == 0;
if (dp[x].count(y))
return dp[x][y];
if (a[x] == 'B') {
if (y % 2 == 0)
return dp[x][y] = dfs(x + 1, y + 1);
else
return dp[x][y] = y * dfs(x + 1, y - 1) % mod;
} else {
if (y % 2 == 0)
return dp[x][y] = y * dfs(x + 1, y - 1) % mod;
else
return dp[x][y] = dfs(x + 1, y + 1);
}
}
signed main() {
n = read();
scanf("%s", a + 1);
// for(int i=1;i<=2*n;i++)
// if(a[i]=='W')gs1++;
// else gs2++;
// if(gs1!=gs2){puts("0");return 0;}
for (int i = 1; i <= n; i++)
ans = ans * i % mod;
cout << ans * dfs(1, 0) % mod << endl;
// cout<<dp[4][1]<<endl;
}
|
[
"identifier.replace.add",
"literal.replace.remove",
"function.return_value.change"
] | 732,046
| 732,047
|
u447610671
|
cpp
|
p02929
|
// Written By NewbieChd
#include <cstdio>
using namespace std;
const int maxN = 2000003, mod = 1e9 + 7;
char s[maxN];
int main() {
int n, i, ans = 1, tmp = 1;
bool dir = 1;
scanf("%d%s", &n, s + 1);
if (s[1] != 'B') {
printf("0\n");
return 0;
}
for (i = 1; i <= n; ++i)
ans = 1ll * ans * i % mod;
n <<= 1;
for (i = 2; i <= n; ++i) {
if (s[i] == s[i - 1])
dir ^= 1;
if (dir)
++tmp;
else
ans = 1ll * ans * tmp % mod, --tmp;
}
printf("%d\n", ans);
return 0;
}
|
// Written By NewbieChd
#include <cstdio>
using namespace std;
const int maxN = 2000003, mod = 1e9 + 7;
char s[maxN];
int main() {
int n, i, ans = 1, tmp = 1;
bool dir = 1;
scanf("%d%s", &n, s + 1);
if (s[1] != 'B') {
printf("0\n");
return 0;
}
for (i = 1; i <= n; ++i)
ans = 1ll * ans * i % mod;
n <<= 1;
for (i = 2; i <= n; ++i) {
if (s[i] == s[i - 1])
dir ^= 1;
if (dir)
++tmp;
else
ans = 1ll * ans * tmp % mod, --tmp;
}
printf("%d\n", tmp ? 0 : ans);
return 0;
}
|
[] | 732,048
| 732,049
|
u305668100
|
cpp
|
p02929
|
#include <bits/stdc++.h>
#define debug(x) cerr << #x << " " << (x) << endl
using namespace std;
const int N = 100005;
const long long mod = 1000000007ll;
int n, now = 0, seq[N << 1];
char str[N << 1];
long long ans = 1ll;
int main() {
scanf("%d", &n);
scanf("%s", str);
for (int i = 1; i <= (n << 1); i++)
seq[i] = (str[i - 1] == 'B') ? 1 : 0;
seq[0] = seq[n + 1] = 0;
for (int i = (n << 1) + 1; i >= 1; i--)
seq[i] ^= (seq[i - 1] ^ 1);
for (int i = 1; i <= (n << 1); i++) {
if (seq[i]) {
seq[i + 1] ^= 1;
ans = ans * now % mod, now--;
} else
now++;
}
for (int i = 1; i <= n; i++)
ans = ans * i % mod;
if (now)
printf("%lld\n", 0ll);
else
printf("%lld\n", ans);
return 0;
}
|
#include <bits/stdc++.h>
#define debug(x) cerr << #x << " " << (x) << endl
using namespace std;
const int N = 100005;
const long long mod = 1000000007ll;
int n, now = 0, seq[N << 1];
char str[N << 1];
long long ans = 1ll;
int main() {
scanf("%d", &n);
scanf("%s", str);
for (int i = 1; i <= (n << 1); i++)
seq[i] = (str[i - 1] == 'B') ? 1 : 0;
seq[0] = seq[(n << 1) + 1] = 0;
for (int i = (n << 1) + 1; i >= 1; i--)
seq[i] ^= (seq[i - 1] ^ 1);
for (int i = 1; i <= (n << 1); i++) {
if (seq[i]) {
seq[i + 1] ^= 1;
ans = ans * now % mod, now--;
} else
now++;
}
for (int i = 1; i <= n; i++)
ans = ans * i % mod;
if (now)
printf("%lld\n", 0ll);
else
printf("%lld\n", ans);
return 0;
}
|
[] | 732,062
| 732,063
|
u198204105
|
cpp
|
p02929
|
#include <cstdio>
#include <iostream>
#define mod 1000000007
using namespace std;
int read() {
int x = 0, f = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-')
f = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
x = x * 10 + c - '0';
c = getchar();
}
return x * f;
}
char s[200005];
int a[200005];
int main() {
int n = read() * 2, tmp = 0, res = 1;
scanf("%s", s + 1);
for (int i = 1; i <= n; ++i)
a[i] = (s[i] == 'B') ^ (i & 1);
for (int i = 1; i <= n; ++i) {
if (a[i] == 0)
tmp++;
else
res = 1ll * res * tmp % mod, tmp--;
}
for (int i = 1; i <= n / 2; ++i)
res = 1ll * res * i % mod;
printf("%d\n", (!tmp) ? 0 : res);
return 0;
}
|
#include <cstdio>
#include <iostream>
#define mod 1000000007
using namespace std;
int read() {
int x = 0, f = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-')
f = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
x = x * 10 + c - '0';
c = getchar();
}
return x * f;
}
char s[200005];
int a[200005];
int main() {
int n = read() * 2, tmp = 0, res = 1;
scanf("%s", s + 1);
for (int i = 1; i <= n; ++i)
a[i] = (s[i] == 'B') ^ (i & 1);
for (int i = 1; i <= n; ++i) {
if (a[i] == 0)
tmp++;
else
res = 1ll * res * tmp % mod, tmp--;
}
for (int i = 1; i <= n / 2; ++i)
res = 1ll * res * i % mod;
printf("%d\n", (!tmp) ? res : 0);
return 0;
}
|
[] | 732,078
| 732,079
|
u547532427
|
cpp
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.