Datasets:

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 "bits/stdc++.h" using namespace std; typedef long long int ll; typedef pair<ll, ll> pi; typedef pair<pair<ll, ll>, ll> pii; vector<ll> vec; vector<vector<ll>> vec2; ll MOD = 1000000007; ll INF = 1145141919454519; int main() { ll N, K; cin >> N >> K; for (ll i = 0; i < N; i++) { ll t; cin >> t; vec.push_back(t); } //点灯数を求める //自分の右側にいくつ有るか vector<ll> r_T(N, 0); for (ll i = 0; i < N; i++) { for (ll j = i + 1; j < N; j++) { if (vec[i] > vec[j]) r_T[i]++; } } //自分の左側にいくつ有るか vector<ll> l_T(N, 0); for (ll i = N - 1; i >= 0; i--) { for (ll j = i - 1; j >= 0; j--) { if (vec[i] > vec[j]) l_T[i]++; } } ll sum = 0; for (ll i = 0; i < N; i++) { sum += r_T[i] * K % MOD; sum %= MOD; sum += (r_T[i] + l_T[i]) * (((K - 1) * K) % MOD / 2) % MOD; sum %= MOD; } cout << sum << endl; }
#include "bits/stdc++.h" using namespace std; typedef long long int ll; typedef pair<ll, ll> pi; typedef pair<pair<ll, ll>, ll> pii; vector<ll> vec; vector<vector<ll>> vec2; ll MOD = 1000000007; ll INF = 1145141919454519; int main() { ll N, K; cin >> N >> K; for (ll i = 0; i < N; i++) { ll t; cin >> t; vec.push_back(t); } //点灯数を求める //自分の右側にいくつ有るか vector<ll> r_T(N, 0); for (ll i = 0; i < N; i++) { for (ll j = i + 1; j < N; j++) { if (vec[i] > vec[j]) r_T[i]++; } } //自分の左側にいくつ有るか vector<ll> l_T(N, 0); for (ll i = N - 1; i >= 0; i--) { for (ll j = i - 1; j >= 0; j--) { if (vec[i] > vec[j]) l_T[i]++; } } ll sum = 0; for (ll i = 0; i < N; i++) { sum += r_T[i] * K % MOD; sum %= MOD; // cout << r_T[i] + l_T[i] << endl; sum += (r_T[i] + l_T[i]) * (((K - 1) * K) / 2 % MOD) % MOD; // sum += l_T[i] * (K-1) % MOD; sum %= MOD; } cout << sum << endl; }
[ "expression.operation.binary.remove", "assignment.change" ]
731,030
731,029
u048791623
cpp
p02928
#include <cstdio> using namespace std; typedef long long ll; const ll MOD = 1e9 + 7; int N, A[2000]; ll K; int main() { scanf("%d %ld", &N, &K); for (int i = 0; i < N; ++i) scanf("%d", &A[i]); ll localT = 0LL, localL = 0LL; for (int l = 0; l < N - 1; ++l) { for (int r = l; r < N; ++r) { if (A[l] > A[r]) ++localT; if (A[l] != A[r]) ++localL; } } ll sum = localT * K % MOD; if (K % 2 == 0) sum += (K / 2 * (K - 1)) % MOD * MOD; else sum += ((K - 1) / 2 * (K - 2) + K - 1) % MOD * localL; printf("%ld\n", sum % MOD); }
#include <cstdio> using namespace std; typedef long long ll; const ll MOD = 1e9 + 7; int N, A[2000]; ll K; int main() { scanf("%d %ld", &N, &K); for (int i = 0; i < N; ++i) scanf("%d", &A[i]); ll localT = 0LL, localL = 0LL; for (int l = 0; l < N - 1; ++l) { for (int r = l; r < N; ++r) { if (A[l] > A[r]) ++localT; if (A[l] != A[r]) ++localL; } } ll sum = localT * K % MOD; if (K % 2 == 0) sum += (K / 2 * (K - 1)) % MOD * localL; else sum += ((K - 1) / 2 * (K - 2) + K - 1) % MOD * localL; printf("%ld\n", sum % MOD); }
[ "assignment.value.change", "identifier.change", "expression.operation.binary.change" ]
731,033
731,034
u923285281
cpp
p02928
//{{{ #include <bits/stdc++.h> using namespace std; #define repX(a, b, c, x, ...) x #define repN(a) repX a #define rep(...) repN((__VA_ARGS__, rep3, rep2, loop))(__VA_ARGS__) #define rrep(...) repN((__VA_ARGS__, rrep3, rrep2))(__VA_ARGS__) #define loop(n) rep2(i_, n) #define rep2(i, n) rep3(i, 0, n) #define rep3(i, begin, end) \ for (ll i = (ll)(begin), i##_end = (ll)(end); i < i##_end; ++i) #define rrep2(i, n) rrep3(i, 0, n) #define rrep3(i, begin, end) \ for (ll i = (ll)(end - 1), i##_end = (ll)(begin); i >= i##_end; --i) #define each(x, a) for (auto &x : a) #define sz(x) ((ll)(x).size()) struct IoSetup { IoSetup() { cin.tie(nullptr); // ios::sync_with_stdio(false); cout << fixed << setprecision(10); cerr << fixed << setprecision(10); }; } ioSetup; using ull = unsigned long long; using ll = long long; using pii = pair<ll, ll>; using vp = vector<pii>; using vs = vector<string>; using vi = vector<ll>; using vvi = vector<vi>; #define v(T) vector<T> #define vv(T) v(v(T)) template <class T, class U> ostream &operator<<(ostream &o, const pair<T, U> &j) { o << "{" << j.first << ", " << j.second << "}"; return o; } template <class T, class U> ostream &operator<<(ostream &o, const map<T, U> &j) { o << "{"; for (auto t = j.begin(); t != j.end(); ++t) o << (t != j.begin() ? ", " : "") << *t; o << "}"; return o; } template <class T> ostream &operator<<(ostream &o, const set<T> &j) { o << "{"; for (auto t = j.begin(); t != j.end(); ++t) o << (t != j.begin() ? ", " : "") << *t; o << "}"; return o; } template <class T> ostream &operator<<(ostream &o, const multiset<T> &j) { o << "{"; for (auto t = j.begin(); t != j.end(); ++t) o << (t != j.begin() ? ", " : "") << *t; o << "}"; return o; } template <class T> ostream &operator<<(ostream &o, const vector<T> &j) { o << "{"; for (ll i = 0; i < (ll)j.size(); ++i) o << (i > 0 ? ", " : "") << j[i]; o << "}"; return o; } #ifdef LOCAL inline void dump(void) { cerr << endl; } template <class Head, class... Tail> inline void dump(Head &&head, Tail &&...tail) { cerr << head << " "; dump(tail...); } #define debug(...) \ do { \ cerr << "[L." << __LINE__ << "]\t" << #__VA_ARGS__ << "="; \ dump(__VA_ARGS__); \ } while (0) #else #define dump(...) #define debug(...) #endif template <class T, class Compare> inline void sort(T &a, Compare comp) { sort(a.begin(), a.end(), comp); } template <class T> inline void sort(T &a) { sort(a.begin(), a.end()); } template <class T> inline void rsort(T &a) { sort(a.rbegin(), a.rend()); } template <class T> inline void reverse(T &a) { reverse(a.begin(), a.end()); } template <class T> inline bool next_permutation(T &a) { return next_permutation(a.begin(), a.end()); } template <class T, class U> inline bool binary_search(T &a, const U &v) { return binary_search(a.begin(), a.end(), v); } template <class T, class U> inline auto lower_bound(T &a, const U &v) { return lower_bound(a.begin(), a.end(), v); } template <class T, class U> inline auto upper_bound(T &a, const U &v) { return upper_bound(a.begin(), a.end(), v); } template <class T> inline T Sum(vector<T> &a) { return accumulate(a.begin(), a.end(), (T)0); } template <class T> inline T max(vector<T> &a) { return *max_element(a.begin(), a.end()); } template <class T> inline T min(vector<T> &a) { return *min_element(a.begin(), a.end()); } template <class T, class U> inline bool chmax(T &a, const U &b) { return (b > a) ? (a = b, true) : false; } template <class T, class U> inline bool chmin(T &a, const U &b) { return (b < a) ? (a = b, true) : false; } ll gcd(const ll a, const ll b) { return b ? gcd(b, a % b) : a; } ll lcm(const ll a, const ll b) { return a / gcd(a, b) * b; } class in { int n, m; public: in() : n(0), m(0) {} in(int n_) : n(n_), m(0){}; in(int n_, int m_) : n(n_), m(m_){}; template <class T> operator T() { assert(n == 0); assert(m == 0); T ret; cin >> ret; return ret; } template <class T> operator vector<T>() { assert(n > 0); assert(m == 0); vector<T> ret(n); for (ll i = 0; i < (ll)n; ++i) cin >> ret[i]; return ret; } template <class T> operator vector<vector<T>>() { assert(n > 0); assert(m > 0); vector<vector<T>> ret(n, vector<T>(m)); for (ll i = 0; i < (ll)n; ++i) for (ll j = 0; j < (ll)m; ++j) cin >> ret[i][j]; return ret; } }; template <class T> void print(const T &a) { cout << a; } int out() { cout << '\n'; return 0; } template <class T> int out(const T &t) { print(t); cout << '\n'; return 0; } template <class Head, class... Tail> int out(const Head &head, const Tail &...tail) { print(head); cout << " "; out(tail...); return 0; } template <class T> vector<T> make_vector(size_t a) { return vector<T>(a); } template <class T, class... Tail> auto make_vector(size_t a, Tail... tail) { return vector<decltype(make_vector<T>(tail...))>(a, make_vector<T>(tail...)); } #define Vector make_vector<ll> template <std::int_fast64_t Mod> class Modular { using u64 = std::uint_fast64_t; public: u64 a; constexpr Modular(std::int_fast64_t x = 0) noexcept : a(x % Mod + (x < 0 ? Mod : 0)) {} constexpr u64 val() const noexcept { return a; } constexpr Modular operator+(const Modular rhs) const noexcept { return Modular(*this) += rhs; } constexpr Modular operator-(const Modular rhs) const noexcept { return Modular(*this) -= rhs; } constexpr Modular operator*(const Modular rhs) const noexcept { return Modular(*this) *= rhs; } constexpr Modular operator/(const Modular rhs) const noexcept { return Modular(*this) /= rhs; } constexpr bool operator==(const Modular rhs) const noexcept { return Modular(*this).val() == rhs.val(); } Modular &operator+=(const Modular rhs) noexcept { a += rhs.a; if (a >= Mod) a -= Mod; return *this; } Modular &operator-=(const Modular rhs) noexcept { if (a < rhs.a) a += Mod; a -= rhs.a; return *this; } Modular &operator++() noexcept { return *this += 1; } Modular &operator--() noexcept { return *this -= 1; } Modular &operator*=(const Modular rhs) noexcept { a = a * rhs.a % Mod; return *this; } Modular &operator/=(Modular rhs) noexcept { u64 exp = Mod - 2; while (exp) { if (exp % 2) *this *= rhs; rhs *= rhs; exp /= 2; } return *this; } }; template <std::int_fast64_t Mod> ostream &operator<<(ostream &os, const Modular<Mod> &m) { return os << m.a; } const double pi = acos(-1); const double eps = 1e-9; const ll inf = 1001001001; const ll mod = (ll)1e9 + 7; using mint = Modular<mod>; //}}} int main() { ll N = in(); ll K = in(); vi A = in(N); mint ans1 = 0; rep(i, N) { rep(j, i + 1, N) { if (A[i] > A[j]) ++ans1; } } map<ll, ll> mp; rep(i, N) { ++mp[A[i]]; } mint ans2 = 0; each(x, mp) { ans2 += N - x.second; } ans2 /= 2; mint ans = ans1 * K; ans += ans2 * K * (K - 1) / 2; out(ans); }
//{{{ #include <bits/stdc++.h> using namespace std; #define repX(a, b, c, x, ...) x #define repN(a) repX a #define rep(...) repN((__VA_ARGS__, rep3, rep2, loop))(__VA_ARGS__) #define rrep(...) repN((__VA_ARGS__, rrep3, rrep2))(__VA_ARGS__) #define loop(n) rep2(i_, n) #define rep2(i, n) rep3(i, 0, n) #define rep3(i, begin, end) \ for (ll i = (ll)(begin), i##_end = (ll)(end); i < i##_end; ++i) #define rrep2(i, n) rrep3(i, 0, n) #define rrep3(i, begin, end) \ for (ll i = (ll)(end - 1), i##_end = (ll)(begin); i >= i##_end; --i) #define each(x, a) for (auto &x : a) #define sz(x) ((ll)(x).size()) struct IoSetup { IoSetup() { cin.tie(nullptr); // ios::sync_with_stdio(false); cout << fixed << setprecision(10); cerr << fixed << setprecision(10); }; } ioSetup; using ull = unsigned long long; using ll = long long; using pii = pair<ll, ll>; using vp = vector<pii>; using vs = vector<string>; using vi = vector<ll>; using vvi = vector<vi>; #define v(T) vector<T> #define vv(T) v(v(T)) template <class T, class U> ostream &operator<<(ostream &o, const pair<T, U> &j) { o << "{" << j.first << ", " << j.second << "}"; return o; } template <class T, class U> ostream &operator<<(ostream &o, const map<T, U> &j) { o << "{"; for (auto t = j.begin(); t != j.end(); ++t) o << (t != j.begin() ? ", " : "") << *t; o << "}"; return o; } template <class T> ostream &operator<<(ostream &o, const set<T> &j) { o << "{"; for (auto t = j.begin(); t != j.end(); ++t) o << (t != j.begin() ? ", " : "") << *t; o << "}"; return o; } template <class T> ostream &operator<<(ostream &o, const multiset<T> &j) { o << "{"; for (auto t = j.begin(); t != j.end(); ++t) o << (t != j.begin() ? ", " : "") << *t; o << "}"; return o; } template <class T> ostream &operator<<(ostream &o, const vector<T> &j) { o << "{"; for (ll i = 0; i < (ll)j.size(); ++i) o << (i > 0 ? ", " : "") << j[i]; o << "}"; return o; } #ifdef LOCAL inline void dump(void) { cerr << endl; } template <class Head, class... Tail> inline void dump(Head &&head, Tail &&...tail) { cerr << head << " "; dump(tail...); } #define debug(...) \ do { \ cerr << "[L." << __LINE__ << "]\t" << #__VA_ARGS__ << "="; \ dump(__VA_ARGS__); \ } while (0) #else #define dump(...) #define debug(...) #endif template <class T, class Compare> inline void sort(T &a, Compare comp) { sort(a.begin(), a.end(), comp); } template <class T> inline void sort(T &a) { sort(a.begin(), a.end()); } template <class T> inline void rsort(T &a) { sort(a.rbegin(), a.rend()); } template <class T> inline void reverse(T &a) { reverse(a.begin(), a.end()); } template <class T> inline bool next_permutation(T &a) { return next_permutation(a.begin(), a.end()); } template <class T, class U> inline bool binary_search(T &a, const U &v) { return binary_search(a.begin(), a.end(), v); } template <class T, class U> inline auto lower_bound(T &a, const U &v) { return lower_bound(a.begin(), a.end(), v); } template <class T, class U> inline auto upper_bound(T &a, const U &v) { return upper_bound(a.begin(), a.end(), v); } template <class T> inline T Sum(vector<T> &a) { return accumulate(a.begin(), a.end(), (T)0); } template <class T> inline T max(vector<T> &a) { return *max_element(a.begin(), a.end()); } template <class T> inline T min(vector<T> &a) { return *min_element(a.begin(), a.end()); } template <class T, class U> inline bool chmax(T &a, const U &b) { return (b > a) ? (a = b, true) : false; } template <class T, class U> inline bool chmin(T &a, const U &b) { return (b < a) ? (a = b, true) : false; } ll gcd(const ll a, const ll b) { return b ? gcd(b, a % b) : a; } ll lcm(const ll a, const ll b) { return a / gcd(a, b) * b; } class in { int n, m; public: in() : n(0), m(0) {} in(int n_) : n(n_), m(0){}; in(int n_, int m_) : n(n_), m(m_){}; template <class T> operator T() { assert(n == 0); assert(m == 0); T ret; cin >> ret; return ret; } template <class T> operator vector<T>() { assert(n > 0); assert(m == 0); vector<T> ret(n); for (ll i = 0; i < (ll)n; ++i) cin >> ret[i]; return ret; } template <class T> operator vector<vector<T>>() { assert(n > 0); assert(m > 0); vector<vector<T>> ret(n, vector<T>(m)); for (ll i = 0; i < (ll)n; ++i) for (ll j = 0; j < (ll)m; ++j) cin >> ret[i][j]; return ret; } }; template <class T> void print(const T &a) { cout << a; } int out() { cout << '\n'; return 0; } template <class T> int out(const T &t) { print(t); cout << '\n'; return 0; } template <class Head, class... Tail> int out(const Head &head, const Tail &...tail) { print(head); cout << " "; out(tail...); return 0; } template <class T> vector<T> make_vector(size_t a) { return vector<T>(a); } template <class T, class... Tail> auto make_vector(size_t a, Tail... tail) { return vector<decltype(make_vector<T>(tail...))>(a, make_vector<T>(tail...)); } #define Vector make_vector<ll> template <std::int_fast64_t Mod> class Modular { using u64 = std::uint_fast64_t; public: u64 a; constexpr Modular(std::int_fast64_t x = 0) noexcept : a(x % Mod + (x < 0 ? Mod : 0)) {} constexpr u64 val() const noexcept { return a; } constexpr Modular operator+(const Modular rhs) const noexcept { return Modular(*this) += rhs; } constexpr Modular operator-(const Modular rhs) const noexcept { return Modular(*this) -= rhs; } constexpr Modular operator*(const Modular rhs) const noexcept { return Modular(*this) *= rhs; } constexpr Modular operator/(const Modular rhs) const noexcept { return Modular(*this) /= rhs; } constexpr bool operator==(const Modular rhs) const noexcept { return Modular(*this).val() == rhs.val(); } Modular &operator+=(const Modular rhs) noexcept { a += rhs.a; if (a >= Mod) a -= Mod; return *this; } Modular &operator-=(const Modular rhs) noexcept { if (a < rhs.a) a += Mod; a -= rhs.a; return *this; } Modular &operator++() noexcept { return *this += 1; } Modular &operator--() noexcept { return *this -= 1; } Modular &operator*=(const Modular rhs) noexcept { a = a * rhs.a % Mod; return *this; } Modular &operator/=(Modular rhs) noexcept { u64 exp = Mod - 2; while (exp) { if (exp % 2) *this *= rhs; rhs *= rhs; exp /= 2; } return *this; } }; template <std::int_fast64_t Mod> ostream &operator<<(ostream &os, const Modular<Mod> &m) { return os << m.a; } const double pi = acos(-1); const double eps = 1e-9; const ll inf = 1001001001; const ll mod = (ll)1e9 + 7; using mint = Modular<mod>; //}}} int main() { ll N = in(); ll K = in(); vi A = in(N); mint ans1 = 0; rep(i, N) { rep(j, i + 1, N) { if (A[i] > A[j]) ++ans1; } } map<ll, ll> mp; rep(i, N) { ++mp[A[i]]; } mint ans2 = 0; each(x, mp) { ans2 += (N - x.second) * x.second; } ans2 /= 2; mint ans = ans1 * K; ans += ans2 * K * (K - 1) / 2; out(ans); }
[ "assignment.change" ]
731,037
731,038
u899220667
cpp
p02928
//{{{ #include <bits/stdc++.h> using namespace std; #define repX(a, b, c, x, ...) x #define repN(a) repX a #define rep(...) repN((__VA_ARGS__, rep3, rep2, loop))(__VA_ARGS__) #define rrep(...) repN((__VA_ARGS__, rrep3, rrep2))(__VA_ARGS__) #define loop(n) rep2(i_, n) #define rep2(i, n) rep3(i, 0, n) #define rep3(i, begin, end) \ for (ll i = (ll)(begin), i##_end = (ll)(end); i < i##_end; ++i) #define rrep2(i, n) rrep3(i, 0, n) #define rrep3(i, begin, end) \ for (ll i = (ll)(end - 1), i##_end = (ll)(begin); i >= i##_end; --i) #define each(x, a) for (auto &x : a) #define sz(x) ((ll)(x).size()) struct IoSetup { IoSetup() { cin.tie(nullptr); // ios::sync_with_stdio(false); cout << fixed << setprecision(10); cerr << fixed << setprecision(10); }; } ioSetup; using ull = unsigned long long; using ll = long long; using pii = pair<ll, ll>; using vp = vector<pii>; using vs = vector<string>; using vi = vector<ll>; using vvi = vector<vi>; #define v(T) vector<T> #define vv(T) v(v(T)) template <class T, class U> ostream &operator<<(ostream &o, const pair<T, U> &j) { o << "{" << j.first << ", " << j.second << "}"; return o; } template <class T, class U> ostream &operator<<(ostream &o, const map<T, U> &j) { o << "{"; for (auto t = j.begin(); t != j.end(); ++t) o << (t != j.begin() ? ", " : "") << *t; o << "}"; return o; } template <class T> ostream &operator<<(ostream &o, const set<T> &j) { o << "{"; for (auto t = j.begin(); t != j.end(); ++t) o << (t != j.begin() ? ", " : "") << *t; o << "}"; return o; } template <class T> ostream &operator<<(ostream &o, const multiset<T> &j) { o << "{"; for (auto t = j.begin(); t != j.end(); ++t) o << (t != j.begin() ? ", " : "") << *t; o << "}"; return o; } template <class T> ostream &operator<<(ostream &o, const vector<T> &j) { o << "{"; for (ll i = 0; i < (ll)j.size(); ++i) o << (i > 0 ? ", " : "") << j[i]; o << "}"; return o; } #ifdef LOCAL inline void dump(void) { cerr << endl; } template <class Head, class... Tail> inline void dump(Head &&head, Tail &&...tail) { cerr << head << " "; dump(tail...); } #define debug(...) \ do { \ cerr << "[L." << __LINE__ << "]\t" << #__VA_ARGS__ << "="; \ dump(__VA_ARGS__); \ } while (0) #else #define dump(...) #define debug(...) #endif template <class T, class Compare> inline void sort(T &a, Compare comp) { sort(a.begin(), a.end(), comp); } template <class T> inline void sort(T &a) { sort(a.begin(), a.end()); } template <class T> inline void rsort(T &a) { sort(a.rbegin(), a.rend()); } template <class T> inline void reverse(T &a) { reverse(a.begin(), a.end()); } template <class T> inline bool next_permutation(T &a) { return next_permutation(a.begin(), a.end()); } template <class T, class U> inline bool binary_search(T &a, const U &v) { return binary_search(a.begin(), a.end(), v); } template <class T, class U> inline auto lower_bound(T &a, const U &v) { return lower_bound(a.begin(), a.end(), v); } template <class T, class U> inline auto upper_bound(T &a, const U &v) { return upper_bound(a.begin(), a.end(), v); } template <class T> inline T Sum(vector<T> &a) { return accumulate(a.begin(), a.end(), (T)0); } template <class T> inline T max(vector<T> &a) { return *max_element(a.begin(), a.end()); } template <class T> inline T min(vector<T> &a) { return *min_element(a.begin(), a.end()); } template <class T, class U> inline bool chmax(T &a, const U &b) { return (b > a) ? (a = b, true) : false; } template <class T, class U> inline bool chmin(T &a, const U &b) { return (b < a) ? (a = b, true) : false; } ll gcd(const ll a, const ll b) { return b ? gcd(b, a % b) : a; } ll lcm(const ll a, const ll b) { return a / gcd(a, b) * b; } class in { int n, m; public: in() : n(0), m(0) {} in(int n_) : n(n_), m(0){}; in(int n_, int m_) : n(n_), m(m_){}; template <class T> operator T() { assert(n == 0); assert(m == 0); T ret; cin >> ret; return ret; } template <class T> operator vector<T>() { assert(n > 0); assert(m == 0); vector<T> ret(n); for (ll i = 0; i < (ll)n; ++i) cin >> ret[i]; return ret; } template <class T> operator vector<vector<T>>() { assert(n > 0); assert(m > 0); vector<vector<T>> ret(n, vector<T>(m)); for (ll i = 0; i < (ll)n; ++i) for (ll j = 0; j < (ll)m; ++j) cin >> ret[i][j]; return ret; } }; template <class T> void print(const T &a) { cout << a; } int out() { cout << '\n'; return 0; } template <class T> int out(const T &t) { print(t); cout << '\n'; return 0; } template <class Head, class... Tail> int out(const Head &head, const Tail &...tail) { print(head); cout << " "; out(tail...); return 0; } template <class T> vector<T> make_vector(size_t a) { return vector<T>(a); } template <class T, class... Tail> auto make_vector(size_t a, Tail... tail) { return vector<decltype(make_vector<T>(tail...))>(a, make_vector<T>(tail...)); } #define Vector make_vector<ll> template <std::int_fast64_t Mod> class Modular { using u64 = std::uint_fast64_t; public: u64 a; constexpr Modular(std::int_fast64_t x = 0) noexcept : a(x % Mod + (x < 0 ? Mod : 0)) {} constexpr u64 val() const noexcept { return a; } constexpr Modular operator+(const Modular rhs) const noexcept { return Modular(*this) += rhs; } constexpr Modular operator-(const Modular rhs) const noexcept { return Modular(*this) -= rhs; } constexpr Modular operator*(const Modular rhs) const noexcept { return Modular(*this) *= rhs; } constexpr Modular operator/(const Modular rhs) const noexcept { return Modular(*this) /= rhs; } constexpr bool operator==(const Modular rhs) const noexcept { return Modular(*this).val() == rhs.val(); } Modular &operator+=(const Modular rhs) noexcept { a += rhs.a; if (a >= Mod) a -= Mod; return *this; } Modular &operator-=(const Modular rhs) noexcept { if (a < rhs.a) a += Mod; a -= rhs.a; return *this; } Modular &operator++() noexcept { return *this += 1; } Modular &operator--() noexcept { return *this -= 1; } Modular &operator*=(const Modular rhs) noexcept { a = a * rhs.a % Mod; return *this; } Modular &operator/=(Modular rhs) noexcept { u64 exp = Mod - 2; while (exp) { if (exp % 2) *this *= rhs; rhs *= rhs; exp /= 2; } return *this; } }; template <std::int_fast64_t Mod> ostream &operator<<(ostream &os, const Modular<Mod> &m) { return os << m.a; } const double pi = acos(-1); const double eps = 1e-9; const ll inf = 1001001001; const ll mod = (ll)1e9 + 7; using mint = Modular<mod>; //}}} int main() { ll N = in(); ll K = in(); vi A = in(N); mint ans1 = 0; rep(i, N) { rep(j, i + 1, N) { if (A[i] > A[j]) ++ans1; } } map<ll, ll> mp; rep(i, N) { ++mp[A[i]]; } ll ans2 = 0; each(x, mp) { ans2 += N - x.second; } ans2 /= 2; mint ans = ans1 * K; ans += (K * (K - 1) / 2) % mod * ans2; out(ans); }
//{{{ #include <bits/stdc++.h> using namespace std; #define repX(a, b, c, x, ...) x #define repN(a) repX a #define rep(...) repN((__VA_ARGS__, rep3, rep2, loop))(__VA_ARGS__) #define rrep(...) repN((__VA_ARGS__, rrep3, rrep2))(__VA_ARGS__) #define loop(n) rep2(i_, n) #define rep2(i, n) rep3(i, 0, n) #define rep3(i, begin, end) \ for (ll i = (ll)(begin), i##_end = (ll)(end); i < i##_end; ++i) #define rrep2(i, n) rrep3(i, 0, n) #define rrep3(i, begin, end) \ for (ll i = (ll)(end - 1), i##_end = (ll)(begin); i >= i##_end; --i) #define each(x, a) for (auto &x : a) #define sz(x) ((ll)(x).size()) struct IoSetup { IoSetup() { cin.tie(nullptr); // ios::sync_with_stdio(false); cout << fixed << setprecision(10); cerr << fixed << setprecision(10); }; } ioSetup; using ull = unsigned long long; using ll = long long; using pii = pair<ll, ll>; using vp = vector<pii>; using vs = vector<string>; using vi = vector<ll>; using vvi = vector<vi>; #define v(T) vector<T> #define vv(T) v(v(T)) template <class T, class U> ostream &operator<<(ostream &o, const pair<T, U> &j) { o << "{" << j.first << ", " << j.second << "}"; return o; } template <class T, class U> ostream &operator<<(ostream &o, const map<T, U> &j) { o << "{"; for (auto t = j.begin(); t != j.end(); ++t) o << (t != j.begin() ? ", " : "") << *t; o << "}"; return o; } template <class T> ostream &operator<<(ostream &o, const set<T> &j) { o << "{"; for (auto t = j.begin(); t != j.end(); ++t) o << (t != j.begin() ? ", " : "") << *t; o << "}"; return o; } template <class T> ostream &operator<<(ostream &o, const multiset<T> &j) { o << "{"; for (auto t = j.begin(); t != j.end(); ++t) o << (t != j.begin() ? ", " : "") << *t; o << "}"; return o; } template <class T> ostream &operator<<(ostream &o, const vector<T> &j) { o << "{"; for (ll i = 0; i < (ll)j.size(); ++i) o << (i > 0 ? ", " : "") << j[i]; o << "}"; return o; } #ifdef LOCAL inline void dump(void) { cerr << endl; } template <class Head, class... Tail> inline void dump(Head &&head, Tail &&...tail) { cerr << head << " "; dump(tail...); } #define debug(...) \ do { \ cerr << "[L." << __LINE__ << "]\t" << #__VA_ARGS__ << "="; \ dump(__VA_ARGS__); \ } while (0) #else #define dump(...) #define debug(...) #endif template <class T, class Compare> inline void sort(T &a, Compare comp) { sort(a.begin(), a.end(), comp); } template <class T> inline void sort(T &a) { sort(a.begin(), a.end()); } template <class T> inline void rsort(T &a) { sort(a.rbegin(), a.rend()); } template <class T> inline void reverse(T &a) { reverse(a.begin(), a.end()); } template <class T> inline bool next_permutation(T &a) { return next_permutation(a.begin(), a.end()); } template <class T, class U> inline bool binary_search(T &a, const U &v) { return binary_search(a.begin(), a.end(), v); } template <class T, class U> inline auto lower_bound(T &a, const U &v) { return lower_bound(a.begin(), a.end(), v); } template <class T, class U> inline auto upper_bound(T &a, const U &v) { return upper_bound(a.begin(), a.end(), v); } template <class T> inline T Sum(vector<T> &a) { return accumulate(a.begin(), a.end(), (T)0); } template <class T> inline T max(vector<T> &a) { return *max_element(a.begin(), a.end()); } template <class T> inline T min(vector<T> &a) { return *min_element(a.begin(), a.end()); } template <class T, class U> inline bool chmax(T &a, const U &b) { return (b > a) ? (a = b, true) : false; } template <class T, class U> inline bool chmin(T &a, const U &b) { return (b < a) ? (a = b, true) : false; } ll gcd(const ll a, const ll b) { return b ? gcd(b, a % b) : a; } ll lcm(const ll a, const ll b) { return a / gcd(a, b) * b; } class in { int n, m; public: in() : n(0), m(0) {} in(int n_) : n(n_), m(0){}; in(int n_, int m_) : n(n_), m(m_){}; template <class T> operator T() { assert(n == 0); assert(m == 0); T ret; cin >> ret; return ret; } template <class T> operator vector<T>() { assert(n > 0); assert(m == 0); vector<T> ret(n); for (ll i = 0; i < (ll)n; ++i) cin >> ret[i]; return ret; } template <class T> operator vector<vector<T>>() { assert(n > 0); assert(m > 0); vector<vector<T>> ret(n, vector<T>(m)); for (ll i = 0; i < (ll)n; ++i) for (ll j = 0; j < (ll)m; ++j) cin >> ret[i][j]; return ret; } }; template <class T> void print(const T &a) { cout << a; } int out() { cout << '\n'; return 0; } template <class T> int out(const T &t) { print(t); cout << '\n'; return 0; } template <class Head, class... Tail> int out(const Head &head, const Tail &...tail) { print(head); cout << " "; out(tail...); return 0; } template <class T> vector<T> make_vector(size_t a) { return vector<T>(a); } template <class T, class... Tail> auto make_vector(size_t a, Tail... tail) { return vector<decltype(make_vector<T>(tail...))>(a, make_vector<T>(tail...)); } #define Vector make_vector<ll> template <std::int_fast64_t Mod> class Modular { using u64 = std::uint_fast64_t; public: u64 a; constexpr Modular(std::int_fast64_t x = 0) noexcept : a(x % Mod + (x < 0 ? Mod : 0)) {} constexpr u64 val() const noexcept { return a; } constexpr Modular operator+(const Modular rhs) const noexcept { return Modular(*this) += rhs; } constexpr Modular operator-(const Modular rhs) const noexcept { return Modular(*this) -= rhs; } constexpr Modular operator*(const Modular rhs) const noexcept { return Modular(*this) *= rhs; } constexpr Modular operator/(const Modular rhs) const noexcept { return Modular(*this) /= rhs; } constexpr bool operator==(const Modular rhs) const noexcept { return Modular(*this).val() == rhs.val(); } Modular &operator+=(const Modular rhs) noexcept { a += rhs.a; if (a >= Mod) a -= Mod; return *this; } Modular &operator-=(const Modular rhs) noexcept { if (a < rhs.a) a += Mod; a -= rhs.a; return *this; } Modular &operator++() noexcept { return *this += 1; } Modular &operator--() noexcept { return *this -= 1; } Modular &operator*=(const Modular rhs) noexcept { a = a * rhs.a % Mod; return *this; } Modular &operator/=(Modular rhs) noexcept { u64 exp = Mod - 2; while (exp) { if (exp % 2) *this *= rhs; rhs *= rhs; exp /= 2; } return *this; } }; template <std::int_fast64_t Mod> ostream &operator<<(ostream &os, const Modular<Mod> &m) { return os << m.a; } const double pi = acos(-1); const double eps = 1e-9; const ll inf = 1001001001; const ll mod = (ll)1e9 + 7; using mint = Modular<mod>; //}}} int main() { ll N = in(); ll K = in(); vi A = in(N); mint ans1 = 0; rep(i, N) { rep(j, i + 1, N) { if (A[i] > A[j]) ++ans1; } } map<ll, ll> mp; rep(i, N) { ++mp[A[i]]; } ll ans2 = 0; each(x, mp) { ans2 += (N - x.second) * x.second; } ans2 /= 2; mint ans = ans1 * K; ans += (K * (K - 1) / 2) % mod * ans2; out(ans); }
[ "assignment.change" ]
731,039
731,040
u899220667
cpp
p02928
#include <bits/stdc++.h> #define sort_(a) sort(a.begin(), a.end()) #define rsort(a) sort(a.rbegin(), a.rend()) #define rep(i, n) for (int i = 0; i < n; i++) #define rrep(i, n) for (int i = n - 1; 0 <= i; i--) #define for_(i, start, end) for (int i = start; i < end; i++) #define rfor(i, start, end) for (int i = start - 1; 0 <= i; i--) #define all(a) a.begin(), a.end() using ll = long long; using ld = long double; using namespace std; constexpr int INF32 = 1'050'000'000; constexpr long long INF64 = 4'000'000'000'000'000'000; constexpr int MOD7 = 1'000'000'007; constexpr int MOD53 = 998'244'353; constexpr double PI = 3.14159265358979323846; 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; } void print() { std::cout << '\n'; } template <class H, class... T> void print(H &&head, T &&...args) { std::cout << head; sizeof...(args) == 0 ? std::cout << "" : std::cout << ' '; print(std::forward<T>(args)...); } template <class T> void print(std::vector<T> &v) { for (int i = 0; i < v.size(); i++) { std::cout << v[i]; i == v.size() - 1 ? std::cout << '\n' : std::cout << ' '; } } template <class T> void print(std::vector<std::vector<T>> &v) { for (int i = 0; i < v.size(); i++) { for (int j = 0; j < v[i].size(); j++) { std::cout << v[i][j]; j == v[i].size() - 1 ? std::cout << '\n' : std::cout << ' '; } } } void scan() {} template <class H, class... T> void scan(H &&head, T &&...args) { std::cin >> head; scan(std::forward<T>(args)...); } template <class T> void scan(std::vector<T> &v) { for (auto &&i : v) { scan(i); } } template <int mod> class modint { private: long long val; public: constexpr modint(long long x = 0) noexcept : val(x % mod) { if (val < 0) val += mod; }; constexpr modint operator-() const noexcept { return val ? mod - val : 0; } constexpr modint operator+(const modint &x) const noexcept { return modint(*this) += x; } constexpr modint &operator++() noexcept { val += 1; if (mod <= val) val -= mod; return *this; } constexpr modint operator++(int) noexcept { modint<mod> ret = *this; val += 1; if (mod <= val) val -= mod; return ret; } constexpr modint operator-(const modint &x) const noexcept { return modint(*this) -= x; } constexpr modint &operator--() noexcept { val -= 1; if (val < 0) val += mod; return *this; } constexpr modint operator--(int) noexcept { modint<mod> ret = *this; val -= 1; if (val < 0) val += mod; return ret; } constexpr modint operator*(const modint &x) const noexcept { return modint(*this) *= x; } constexpr modint operator/(const modint &x) const noexcept { return modint(*this) /= x; } constexpr modint &operator+=(const modint &x) noexcept { val += x.val; if (mod <= val) val -= mod; return *this; } constexpr modint &operator-=(const modint &x) noexcept { val -= x.val; if (val < 0) val += mod; return *this; } constexpr modint &operator*=(const modint &x) noexcept { val = val * x.val % mod; return *this; } constexpr modint &operator/=(const modint &x) noexcept { val *= x.inv(); return *this; } constexpr modint inv() const noexcept { long long a = val, b = mod, u = 1, v = 0, t; while (0 < b) { t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } return modint(u); } constexpr bool operator==(const modint &x) const noexcept { return this->val == x.val; } constexpr bool operator!=(const modint &x) const noexcept { return this->val != x.val; } constexpr bool operator<(const modint &x) const noexcept { return val < x.val; } constexpr bool operator<=(const modint &x) const noexcept { return val <= x.val; } constexpr bool operator>(const modint &x) const noexcept { return x.val < val; } constexpr bool operator>=(const modint &x) const noexcept { return x.val <= val; } friend constexpr ostream &operator<<(ostream &os, modint<mod> &x) noexcept { return os << x.val; } friend constexpr istream &operator>>(istream &is, modint<mod> &x) noexcept { return is >> x.val; } friend constexpr modint<mod> power(const modint<mod> &radix, long long x) noexcept { if (x == 0) return 1; auto t = power(radix, x / 2); t = t * t; if (x & 1) t = t * radix; return t; } }; using mint = modint<MOD7>; int main() { cin.tie(0); ios::sync_with_stdio(false); int N, K; scan(N, K); vector<int> a(N); scan(a); ll cnt = 0; ll cnt2 = 0; rep(i, N) { rep(j, N) { if (a[j] < a[i]) cnt2++; if (i < j && a[j] < a[i]) cnt++; } } mint ans = cnt2; ans *= K * (K - 1) / 2; ans += cnt * K; print(ans); return 0; }
#include <bits/stdc++.h> #define sort_(a) sort(a.begin(), a.end()) #define rsort(a) sort(a.rbegin(), a.rend()) #define rep(i, n) for (int i = 0; i < n; i++) #define rrep(i, n) for (int i = n - 1; 0 <= i; i--) #define for_(i, start, end) for (int i = start; i < end; i++) #define rfor(i, start, end) for (int i = start - 1; 0 <= i; i--) #define all(a) a.begin(), a.end() using ll = long long; using ld = long double; using namespace std; constexpr int INF32 = 1'050'000'000; constexpr long long INF64 = 4'000'000'000'000'000'000; constexpr int MOD7 = 1'000'000'007; constexpr int MOD53 = 998'244'353; constexpr double PI = 3.14159265358979323846; 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; } void print() { std::cout << '\n'; } template <class H, class... T> void print(H &&head, T &&...args) { std::cout << head; sizeof...(args) == 0 ? std::cout << "" : std::cout << ' '; print(std::forward<T>(args)...); } template <class T> void print(std::vector<T> &v) { for (int i = 0; i < v.size(); i++) { std::cout << v[i]; i == v.size() - 1 ? std::cout << '\n' : std::cout << ' '; } } template <class T> void print(std::vector<std::vector<T>> &v) { for (int i = 0; i < v.size(); i++) { for (int j = 0; j < v[i].size(); j++) { std::cout << v[i][j]; j == v[i].size() - 1 ? std::cout << '\n' : std::cout << ' '; } } } void scan() {} template <class H, class... T> void scan(H &&head, T &&...args) { std::cin >> head; scan(std::forward<T>(args)...); } template <class T> void scan(std::vector<T> &v) { for (auto &&i : v) { scan(i); } } template <int mod> class modint { private: long long val; public: constexpr modint(long long x = 0) noexcept : val(x % mod) { if (val < 0) val += mod; }; constexpr modint operator-() const noexcept { return val ? mod - val : 0; } constexpr modint operator+(const modint &x) const noexcept { return modint(*this) += x; } constexpr modint &operator++() noexcept { val += 1; if (mod <= val) val -= mod; return *this; } constexpr modint operator++(int) noexcept { modint<mod> ret = *this; val += 1; if (mod <= val) val -= mod; return ret; } constexpr modint operator-(const modint &x) const noexcept { return modint(*this) -= x; } constexpr modint &operator--() noexcept { val -= 1; if (val < 0) val += mod; return *this; } constexpr modint operator--(int) noexcept { modint<mod> ret = *this; val -= 1; if (val < 0) val += mod; return ret; } constexpr modint operator*(const modint &x) const noexcept { return modint(*this) *= x; } constexpr modint operator/(const modint &x) const noexcept { return modint(*this) /= x; } constexpr modint &operator+=(const modint &x) noexcept { val += x.val; if (mod <= val) val -= mod; return *this; } constexpr modint &operator-=(const modint &x) noexcept { val -= x.val; if (val < 0) val += mod; return *this; } constexpr modint &operator*=(const modint &x) noexcept { val = val * x.val % mod; return *this; } constexpr modint &operator/=(const modint &x) noexcept { val *= x.inv(); return *this; } constexpr modint inv() const noexcept { long long a = val, b = mod, u = 1, v = 0, t; while (0 < b) { t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } return modint(u); } constexpr bool operator==(const modint &x) const noexcept { return this->val == x.val; } constexpr bool operator!=(const modint &x) const noexcept { return this->val != x.val; } constexpr bool operator<(const modint &x) const noexcept { return val < x.val; } constexpr bool operator<=(const modint &x) const noexcept { return val <= x.val; } constexpr bool operator>(const modint &x) const noexcept { return x.val < val; } constexpr bool operator>=(const modint &x) const noexcept { return x.val <= val; } friend constexpr ostream &operator<<(ostream &os, modint<mod> &x) noexcept { return os << x.val; } friend constexpr istream &operator>>(istream &is, modint<mod> &x) noexcept { return is >> x.val; } friend constexpr modint<mod> power(const modint<mod> &radix, long long x) noexcept { if (x == 0) return 1; auto t = power(radix, x / 2); t = t * t; if (x & 1) t = t * radix; return t; } }; using mint = modint<MOD7>; int main() { cin.tie(0); ios::sync_with_stdio(false); ll N, K; scan(N, K); vector<int> a(N); scan(a); ll cnt = 0; ll cnt2 = 0; rep(i, N) { rep(j, N) { if (a[j] < a[i]) cnt2++; if (i < j && a[j] < a[i]) cnt++; } } mint ans = cnt2; ans *= K * (K - 1) / 2; ans += cnt * K; print(ans); return 0; }
[ "variable_declaration.type.change" ]
731,043
731,044
u324303263
cpp
p02928
#include <bits/stdc++.h> using namespace std; using ll = long long; template <class T> ostream &operator<<(ostream &os, vector<T> &v) { for (auto i = v.begin(); i != v.end(); i++) { os << *i << " "; } return os; } const long long MOD = 1000000007; void solve(long long N, long long K, std::vector<long long> A) { ll ans = 0; for (ll i = 0; i < N; i++) { ll cnt = 0; for (ll j = i; j < N; j++) { if (A[j] < A[i]) { cnt++; } } ans += (cnt * K) % MOD; ans %= MOD; // ans = ans % MOD; } for (ll i = 0; i < N; i++) { ll cnt = 0; for (ll j = 0; j < N; j++) { if (A[j] < A[i]) { cnt++; } } // ans+=(((K-1)*(2*cnt+(K-2)*cnt))/2)%MOD; ans += (cnt * (K * (K - 1) / 2) % MOD) % MOD; // ans += ((((K*(K-1))%MOD)*cnt)/2)%MOD; ans %= MOD; } std::cout << ans << std::endl; } int main() { long long N; scanf("%lld", &N); long long K; scanf("%lld", &K); std::vector<long long> A(N - 1 - 0 + 1); for (int i = 0; i < N - 1 - 0 + 1; i++) { scanf("%lld", &A[i]); } solve(N, K, std::move(A)); return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; template <class T> ostream &operator<<(ostream &os, vector<T> &v) { for (auto i = v.begin(); i != v.end(); i++) { os << *i << " "; } return os; } const long long MOD = 1000000007; void solve(long long N, long long K, std::vector<long long> A) { ll ans = 0; for (ll i = 0; i < N; i++) { ll cnt = 0; for (ll j = i; j < N; j++) { if (A[j] < A[i]) { cnt++; } } ans += (cnt * K) % MOD; ans %= MOD; // ans = ans % MOD; } for (ll i = 0; i < N; i++) { ll cnt = 0; for (ll j = 0; j < N; j++) { if (A[j] < A[i]) { cnt++; } } // ans+=(((K-1)*(2*cnt+(K-2)*cnt))/2)%MOD; ans += (cnt * ((K * (K - 1) / 2) % MOD)) % MOD; // ans += ((((K*(K-1))%MOD)*cnt)/2)%MOD; ans %= MOD; } std::cout << ans << std::endl; } int main() { long long N; scanf("%lld", &N); long long K; scanf("%lld", &K); std::vector<long long> A(N - 1 - 0 + 1); for (int i = 0; i < N - 1 - 0 + 1; i++) { scanf("%lld", &A[i]); } solve(N, K, std::move(A)); return 0; }
[]
731,045
731,046
u131340563
cpp
p02928
#include <bits/stdc++.h> using namespace std; using ll = long long; const int MOD = 1e9 + 7; #define REP(i, n) for (int i = 0; i < n; ++i) #define FOR(i, t, n) for (ll i = t; i <= (ll)n; ++i) struct edge { int from, to; ll cost; }; class Eratosthenes { public: vector<bool> prime; Eratosthenes(ll size) { size = max((int)sqrt(size) + 1, 101010); prime.resize(size, 1); prime[0] = 0; prime[1] = 0; for (size_t i = 2; i * i <= size; ++i) if (prime[i]) { for (size_t j = 2; i * j <= size; ++j) prime[i * j] = false; } } }; class Combination { vector<ll> fac; // n!(mod M) vector<ll> ifac; // k!^{M-2} (mod M) public: Combination(ll size) { fac.resize(size); ifac.resize(size); fac[0] = 1; ifac[0] = 1; for (ll i = 0; i < size; i++) { fac[i + 1] = fac[i] * (i + 1) % MOD; ifac[i + 1] = ifac[i] * mpow(i + 1, MOD - 2) % MOD; } } ll mpow(ll x, ll n) { ll ans = 1; while (n != 0) { if (n & 1) ans = ans * x % MOD; x = x * x % MOD; n = n >> 1; } return ans; } 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] % MOD; return tmp * fac[a] % MOD; } }; ll GCD(ll a, ll b) { if (b == 0) return a; return GCD(b, a % b); } ll LCM(ll a, ll b) { ll gcd = GCD(a, b); return a / gcd * b; } ll N, K; int main() { cin >> N >> K; vector<int> A(N), B(N), C(N); REP(i, N) cin >> A[i]; REP(i, N) { REP(k, N) { if (i < k) if (A[i] > A[k]) B[i]++; if (A[i] > A[k]) C[i]++; } } ll res = 0; REP(i, N) { res += K * B[i] % MOD; res %= MOD; res += (K * (K - 1) % MOD) / 2 * C[i] % MOD; res %= MOD; } cout << res << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; const int MOD = 1e9 + 7; #define REP(i, n) for (int i = 0; i < n; ++i) #define FOR(i, t, n) for (ll i = t; i <= (ll)n; ++i) struct edge { int from, to; ll cost; }; class Eratosthenes { public: vector<bool> prime; Eratosthenes(ll size) { size = max((int)sqrt(size) + 1, 101010); prime.resize(size, 1); prime[0] = 0; prime[1] = 0; for (size_t i = 2; i * i <= size; ++i) if (prime[i]) { for (size_t j = 2; i * j <= size; ++j) prime[i * j] = false; } } }; class Combination { vector<ll> fac; // n!(mod M) vector<ll> ifac; // k!^{M-2} (mod M) public: Combination(ll size) { fac.resize(size); ifac.resize(size); fac[0] = 1; ifac[0] = 1; for (ll i = 0; i < size; i++) { fac[i + 1] = fac[i] * (i + 1) % MOD; ifac[i + 1] = ifac[i] * mpow(i + 1, MOD - 2) % MOD; } } ll mpow(ll x, ll n) { ll ans = 1; while (n != 0) { if (n & 1) ans = ans * x % MOD; x = x * x % MOD; n = n >> 1; } return ans; } 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] % MOD; return tmp * fac[a] % MOD; } }; ll GCD(ll a, ll b) { if (b == 0) return a; return GCD(b, a % b); } ll LCM(ll a, ll b) { ll gcd = GCD(a, b); return a / gcd * b; } ll N, K; int main() { cin >> N >> K; vector<int> A(N), B(N), C(N); REP(i, N) cin >> A[i]; REP(i, N) { REP(k, N) { if (i < k) if (A[i] > A[k]) B[i]++; if (A[i] > A[k]) C[i]++; } } ll res = 0; REP(i, N) { res += K * B[i] % MOD; res %= MOD; res += K * (K - 1) / 2 % MOD * C[i] % MOD; res %= MOD; } cout << res << endl; return 0; }
[ "assignment.change" ]
731,049
731,050
u181806820
cpp
p02928
#include "bits/stdc++.h" #define in std::cin #define out std::cout #define rep(i, N) for (LL i = 0; i < N; ++i) typedef long long int LL; const LL mod = 1000000007; int main() { LL N, K; in >> N >> K; std::vector<LL> A(N); rep(i, N) in >> A[i]; LL ans = 0; rep(i, N) { rep(j, N) { if (A[i] > A[j]) { if (i < j) (ans += (K * (K + 1)) % mod / 2) %= mod; else (ans += (K * (K - 1)) % mod / 2) %= mod; } } } out << ans << std::endl; }
#include "bits/stdc++.h" #define in std::cin #define out std::cout #define rep(i, N) for (LL i = 0; i < N; ++i) typedef long long int LL; const LL mod = 1000000007; int main() { LL N, K; in >> N >> K; std::vector<LL> A(N); rep(i, N) in >> A[i]; LL ans = 0; rep(i, N) { rep(j, N) { if (A[i] > A[j]) { if (i < j) (ans += (K * (K + 1)) / 2) %= mod; else (ans += (K * (K - 1)) / 2) %= mod; } } } out << ans << std::endl; }
[ "expression.operation.binary.remove" ]
731,056
731,057
u660613376
cpp
p02928
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ll n, k; cin >> n >> k; vector<ll> a; ll tmp; for (int i = 0; i < n; i++) { cin >> tmp; a.push_back(tmp); } ll tentou = 0; ll ans = 0; bool first = false; ll sumtentou = 0; for (int i = 0; i < n; i++) { first = false; ll tentou = 0; for (int j = 0; j < n; j++) { if (i == j) { first = true; } if (first) { if (a.at(i) > a.at(j)) { tentou++; ans++; } } else { if (a.at(i) > a.at(j)) { tentou++; } } } sumtentou += tentou; } // cout << ans << endl; // cout << sumtentou << endl; ll out = 0; ans = (ans * k) % 1000000007; // cout << k*(k-1) << endl; out = (sumtentou % 1000000007) * ((k * (k - 1) / 2) % 1000000007); cout << out % 1000000007 + ans % 1000000007 << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ll n, k; cin >> n >> k; vector<ll> a; ll tmp; for (int i = 0; i < n; i++) { cin >> tmp; a.push_back(tmp); } ll tentou = 0; ll ans = 0; bool first = false; ll sumtentou = 0; for (int i = 0; i < n; i++) { first = false; ll tentou = 0; for (int j = 0; j < n; j++) { if (i == j) { first = true; } if (first) { if (a.at(i) > a.at(j)) { tentou++; ans++; } } else { if (a.at(i) > a.at(j)) { tentou++; } } } sumtentou += tentou; } // cout << ans << endl; // cout << sumtentou << endl; ll out = 0; ans = (ans * k) % 1000000007; // cout << k*(k-1) << endl; out = (sumtentou % 1000000007) * ((k * (k - 1) / 2) % 1000000007); cout << (out % 1000000007 + ans % 1000000007) % 1000000007 << endl; }
[ "expression.operation.binary.add" ]
731,058
731,059
u091552241
cpp
p02928
#include <bits/stdc++.h> using namespace std; #define rep(j, n) for (int i = (int)(j); i < (int)(n); i++) #define int int64_t signed main() { int ans = 0; int N, K; cin >> N >> K; int X = (K - 1) * K / 2; vector<int> A(N); rep(0, N) cin >> A[i]; rep(0, N) { int count = 0, sum = 0; for (int j = 0; j < N; j++) { if (A.at(j) < A.at(i)) { sum++; if (j > i) count++; } } ans += count * K; ans += sum * X; if (ans >= 1000000007) ans %= 1000000007; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(j, n) for (int i = (int)(j); i < (int)(n); i++) #define int int64_t signed main() { int ans = 0; int N, K; cin >> N >> K; int X = (K - 1) * K / 2; X %= 1000000007; vector<int> A(N); rep(0, N) cin >> A[i]; rep(0, N) { int count = 0, sum = 0; for (int j = 0; j < N; j++) { if (A.at(j) < A.at(i)) { sum++; if (j > i) count++; } } ans += count * K; ans += sum * X; if (ans >= 1000000007) ans %= 1000000007; } cout << ans << endl; }
[ "assignment.add" ]
731,060
731,061
u347057617
cpp
p02928
#include <bits/stdc++.h> using namespace std; #define INF 1001001001 // int32_t #define MOD 1000000007 #define MOD2 998244353 #define all(a) (a).begin(), (a).end() #define mkp make_pair #define pb push_back typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; int mmul(int p, int q, int m) { ll lp = p, lq = q; return (int)(((lp % m) * (lq % m)) % m); } int mpow(int x, int n, int m) { ll res = x, ans = 1; while (n != 0) { if (n % 2 == 0) { res = mmul(res, res, m); n >>= 1; } else { ans = mmul(ans, res, m); --n; } } return (int)ans; } int mdiv(int p, int q, int m) { return mmul(p, mpow(q, m - 2, m), m); } int main() { bool flag = false; ll ans = 0, sum = 0; ll n, k; cin >> n >> k; ll in = 0, tr = 0; vector<int> a(n); 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[j] < a[i]) in++; } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (i == j) continue; if (a[j] < a[i]) tr++; } } // cout <<endl<< in << " " << tr<<endl; ans += mmul(in, k, MOD); // cout << in << " x " << k<<endl; ans %= MOD; ll mul = k * (k - 1) / 2; mul %= MOD; ans += mmul(tr, mul, MOD); // cout <<fixed<<setprecision(16)<< << endl; cout << ans << endl; // if(flag)cout << "Yes" <<endl; // else cout << "No" <<endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define INF 1001001001 // int32_t #define MOD 1000000007 #define MOD2 998244353 #define all(a) (a).begin(), (a).end() #define mkp make_pair #define pb push_back typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; int mmul(int p, int q, int m) { ll lp = p, lq = q; return (int)(((lp % m) * (lq % m)) % m); } int mpow(int x, int n, int m) { ll res = x, ans = 1; while (n != 0) { if (n % 2 == 0) { res = mmul(res, res, m); n >>= 1; } else { ans = mmul(ans, res, m); --n; } } return (int)ans; } int mdiv(int p, int q, int m) { return mmul(p, mpow(q, m - 2, m), m); } int main() { bool flag = false; ll ans = 0, sum = 0; ll n, k; cin >> n >> k; ll in = 0, tr = 0; vector<int> a(n); 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[j] < a[i]) in++; } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (i == j) continue; if (a[j] < a[i]) tr++; } } // cout <<endl<< in << " " << tr<<endl; ans += mmul(in, k, MOD); // cout << in << " x " << k<<endl; ans %= MOD; ll mul = k * (k - 1) / 2; mul %= MOD; ans += mmul(tr, mul, MOD); ans %= MOD; // cout <<fixed<<setprecision(16)<< << endl; cout << ans << endl; // if(flag)cout << "Yes" <<endl; // else cout << "No" <<endl; return 0; }
[ "assignment.add" ]
731,064
731,065
u355424600
cpp
p02928
#include <algorithm> #include <climits> #include <cmath> #include <cstdio> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <string> #include <utility> #include <vector> using namespace std; using ll = long long int; void prime(vector<int> &num, int n) { for (int i = 0; i <= n; i++) { num[i] = 1; } num[0] = 0; num[1] = 0; num[2] = 1; for (int i = 2; i <= sqrt(n); i++) { if (num[i] == 1) { for (int j = 2; j <= n / i; j++) { num[i * j] = 0; } } } } ll gcd(ll a, ll b) { ll tmp; if (b > a) { tmp = a; a = b; b = tmp; } while (a % b != 0) { tmp = b; b = a % b; a = tmp; } return b; } ll lcm(ll a, ll b) { return a * b / gcd(a, b); } int main(void) { ll n, k; cin >> n >> k; vector<ll> a(n); for (int i = 0; i < n; i++) { ll x; cin >> x; a[i] = x; } vector<ll> b(n); for (int i = 0; i < n; i++) { b[i] = 0; } for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { if (a[i] > a[j]) b[i]++; } // cout<<b[i]<<" "; } // cout<<endl; vector<ll> c(n); for (int i = 0; i < n; i++) { c[i] = 0; } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (i != j && a[i] > a[j]) c[i]++; } // cout<<c[i]<<" "; } // cout<<endl; ll sum = 0; for (int i = 0; i < n; i++) { sum += (b[i] * k) % 1000000007; sum += (c[i] * ((k - 1) * k / 2)) % 1000000007; sum = sum % 1000000007; // cout<<sum<<" "; } cout << sum % (1000000007) << endl; return 0; }
#include <algorithm> #include <climits> #include <cmath> #include <cstdio> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <string> #include <utility> #include <vector> using namespace std; using ll = long long int; void prime(vector<int> &num, int n) { for (int i = 0; i <= n; i++) { num[i] = 1; } num[0] = 0; num[1] = 0; num[2] = 1; for (int i = 2; i <= sqrt(n); i++) { if (num[i] == 1) { for (int j = 2; j <= n / i; j++) { num[i * j] = 0; } } } } ll gcd(ll a, ll b) { ll tmp; if (b > a) { tmp = a; a = b; b = tmp; } while (a % b != 0) { tmp = b; b = a % b; a = tmp; } return b; } ll lcm(ll a, ll b) { return a * b / gcd(a, b); } int main(void) { ll n, k; cin >> n >> k; vector<ll> a(n); for (int i = 0; i < n; i++) { ll x; cin >> x; a[i] = x; } vector<ll> b(n); for (int i = 0; i < n; i++) { b[i] = 0; } for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { if (a[i] > a[j]) b[i]++; } // cout<<b[i]<<" "; } // cout<<endl; vector<ll> c(n); for (int i = 0; i < n; i++) { c[i] = 0; } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (i != j && a[i] > a[j]) c[i]++; } // cout<<c[i]<<" "; } // cout<<endl; ll sum = 0; for (int i = 0; i < n; i++) { sum += (b[i] * k) % 1000000007; sum += (c[i] * (((k - 1) * k / 2) % 1000000007)) % 1000000007; sum = sum % 1000000007; // cout<<sum<<" "; } cout << sum % (1000000007) << endl; return 0; }
[]
731,066
731,067
u939401127
cpp
p02928
#include <algorithm> #include <array> #include <cstdlib> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> #define _USE_MATH_DEFINES #include <climits> #include <cmath> #include <cstdio> #include <iomanip> #include <unordered_map> #include <utility> using namespace std; typedef long long int ll; #define SP(x) setprecision((int)x) #define ALL(v) v.begin(), v.end() /* デカい配列はここで宣言 */ int main(int argc, char const *argv[]) { ll n, k; cin >> n >> k; vector<ll> a(n); for (ll i = 0; i < n; i++) { cin >> a[i]; } ll ans = 0; vector<ll> b(n, 0); vector<ll> c(n, 0); for (ll i = 0; i < n; i++) { for (ll t = i + 1; t < n; t++) { if (a[i] > a[t]) { b[i]++; } } for (ll t = 0; t < n; t++) { if (a[i] > a[t]) { if (i != t) { c[i]++; } } } ans += b[i] * k; ans %= 1000000007; ans += c[i] * k * (k - 1) / 2; ans %= 1000000007; // ans += (b[i] * k + c[i] * k * (k - 1) / 2) % 1000000007; } cout << ans << endl; }
#include <algorithm> #include <array> #include <cstdlib> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> #define _USE_MATH_DEFINES #include <climits> #include <cmath> #include <cstdio> #include <iomanip> #include <unordered_map> #include <utility> using namespace std; typedef long long int ll; #define SP(x) setprecision((int)x) #define ALL(v) v.begin(), v.end() /* デカい配列はここで宣言 */ int main(int argc, char const *argv[]) { ll n, k; cin >> n >> k; vector<ll> a(n); for (ll i = 0; i < n; i++) { cin >> a[i]; } ll ans = 0; vector<ll> b(n, 0); vector<ll> c(n, 0); for (ll i = 0; i < n; i++) { for (ll t = i + 1; t < n; t++) { if (a[i] > a[t]) { b[i]++; } } for (ll t = 0; t < n; t++) { if (a[i] > a[t]) { if (i != t) { c[i]++; } } } ans += b[i] * k; ans %= 1000000007; ans += c[i] * (k * (k - 1) / 2 % 1000000007); ans %= 1000000007; } cout << ans << endl; }
[]
731,074
731,075
u324139341
cpp
p02928
#include <algorithm> #include <iostream> using namespace std; #define int long long #define mod 1000000007 // 10^9+7 #define rep(i, n) for (int i = 0; i < n; i++) int n, k, a[3000], cnt = 0, s = 0; signed main() { cin >> n >> k; rep(i, n) cin >> a[i]; rep(i, n) { for (int j = i + 1; j < n; j++) { if (a[i] < a[j]) cnt++; else if (a[i] == a[j]) s++; } } int t = k * (k + 1) / 2; t %= mod; int d = n * (n - 1) / 2 - s; int ans = t * d - k * cnt; ans %= mod; cout << ans << endl; return 0; }
#include <algorithm> #include <iostream> using namespace std; #define int long long #define mod 1000000007 // 10^9+7 #define rep(i, n) for (int i = 0; i < n; i++) int n, k, a[3000], cnt = 0, s = 0; signed main() { cin >> n >> k; rep(i, n) cin >> a[i]; rep(i, n) { for (int j = i + 1; j < n; j++) { if (a[i] > a[j]) cnt++; else if (a[i] == a[j]) s++; } } int t = k * (k - 1) / 2; t %= mod; int d = n * (n - 1) / 2 - s; int ans = t * d + k * cnt; ans %= mod; cout << ans << endl; return 0; }
[ "misc.opposites", "expression.operator.compare.change", "control_flow.branch.if.condition.change", "expression.operator.arithmetic.change", "expression.operation.binary.change" ]
731,076
731,077
u988961969
cpp
p02928
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; int a[2010]; int main() { long long res = 0; int n; long long k; 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]) { long long inv = k * (k + 1) / 2ll; res += inv % mod; res % -mod; } else if (a[i] < a[j]) { long long cnt = k * (k - 1) / 2ll; res += cnt % mod; res %= mod; } } } cout << res << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; int a[2010]; int main() { long long res = 0; int n; long long k; 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]) { long long inv = k * (k + 1) / 2ll; res += inv % mod; res %= mod; } else if (a[i] < a[j]) { long long cnt = k * (k - 1) / 2ll; res += cnt % mod; res %= mod; } } } cout << res << endl; return 0; }
[ "assignment.compound.arithmetic.replace.add", "expression.operator.arithmetic.replace.remove", "expression.operation.binary.change", "expression.operation.unary.arithmetic.remove" ]
731,078
731,079
u871472869
cpp
p02928
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<ll, ll> pll; #define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i)) #define REP(i, n) FOR(i, n, 0) #define OF64 std::setprecision(10) const ll MOD = 1000000007; const ll INF = (ll)1e15; ll A[2005]; ll B[2005]; ll C[2005]; int main() { ll N, K; cin >> N >> K; REP(i, N) { cin >> A[i]; } memset(B, 0, sizeof(B)); memset(C, 0, sizeof(C)); REP(i, N) { FOR(j, N, i + 1) { if (A[i] > A[j]) B[i]++; } REP(j, N) { if (A[i] > A[j]) C[i]++; } } ll ans = 0; ll mul = K * (K - 1) / 2; mul % MOD; REP(i, N) { ans += (B[i] * K) % MOD + (mul * C[i]) % MOD; ans %= MOD; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<ll, ll> pll; #define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i)) #define REP(i, n) FOR(i, n, 0) #define OF64 std::setprecision(10) const ll MOD = 1000000007; const ll INF = (ll)1e15; ll A[2005]; ll B[2005]; ll C[2005]; int main() { ll N, K; cin >> N >> K; REP(i, N) { cin >> A[i]; } memset(B, 0, sizeof(B)); memset(C, 0, sizeof(C)); REP(i, N) { FOR(j, N, i + 1) { if (A[i] > A[j]) B[i]++; } REP(j, N) { if (A[i] > A[j]) C[i]++; } } ll ans = 0; ll mul = K * (K - 1) / 2; mul %= MOD; REP(i, N) { ans += (B[i] * K) % MOD + (mul * C[i]) % MOD; ans %= MOD; } cout << ans << endl; return 0; }
[ "assignment.compound.arithmetic.replace.add", "expression.operator.arithmetic.replace.remove", "expression.operation.binary.change" ]
731,080
731,081
u340980616
cpp
p02928
#include <algorithm> #include <iostream> #include <vector> using namespace std; const long mod = 1e9 + 7; int main() { cin.tie(0); ios::sync_with_stdio(false); int N, K; cin >> N >> K; long long ans = 0; vector<int> A(N); for (int i = 0; i < N; i++) cin >> A[i]; for (int i = 0; i < N; i++) { long long cnt = 0, t = 0; for (int j = 0; j < N; j++) if (A[j] > A[i]) cnt++, t += j < i; ans += K * (K - 1) / 2 % mod * cnt % mod + t * K % mod; ans %= mod; } cout << ans << endl; return 0; }
#include <algorithm> #include <iostream> #include <vector> using namespace std; const long mod = 1e9 + 7; int main() { cin.tie(0); ios::sync_with_stdio(false); long N, K; cin >> N >> K; long long ans = 0; vector<int> A(N); for (int i = 0; i < N; i++) cin >> A[i]; for (int i = 0; i < N; i++) { long long cnt = 0, t = 0; for (int j = 0; j < N; j++) if (A[j] > A[i]) cnt++, t += j < i; ans += K * (K - 1) / 2 % mod * cnt % mod + t * K % mod; ans %= mod; } cout << ans << endl; return 0; }
[ "variable_declaration.type.primitive.change" ]
731,086
731,087
u013803727
cpp
p02928
#include <bits/stdc++.h> using namespace std; #define ll long long #define rep(i, n) for (ll i = 0; i < n; ++i) ll dx[4] = {0, 1, 0, -1}; ll dy[4] = {1, 0, -1, 0}; const ll INF = 1 << LLONG_MAX; const ll MOD = 1e9 + 7; int main() { ios_base::sync_with_stdio(false); cin.tie(0); ll N, K; cin >> N >> K; vector<ll> A(N); rep(i, N) { cin >> A[i]; } ll ans = 0; ll mul = K * (K - 1) / 2 % MOD; for (int i = 0; i < N; ++i) { ll right = 0, left = 0; for (int j = i + 1; j < N; ++j) { if (A[i] > A[j]) { right++; // A[i]より小さい右側の数 } } ans = (ans + K * right) % MOD; for (int j = 1; j <= i - 1; ++j) { if (A[i] > A[j]) { left++; // A[i]より小さい数全ての個数 } } ans = (ans + (right + left) * mul) % MOD; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define rep(i, n) for (ll i = 0; i < n; ++i) ll dx[4] = {0, 1, 0, -1}; ll dy[4] = {1, 0, -1, 0}; const ll INF = 1 << LLONG_MAX; const ll MOD = 1e9 + 7; int main() { ios_base::sync_with_stdio(false); cin.tie(0); ll N, K; cin >> N >> K; vector<ll> A(N); rep(i, N) { cin >> A[i]; } ll ans = 0; ll mul = K * (K - 1) / 2 % MOD; for (int i = 0; i < N; ++i) { ll right = 0, left = 0; for (int j = i + 1; j < N; ++j) { if (A[i] > A[j]) { right++; // A[i]より小さい右側の数 } } ans = (ans + K * right) % MOD; for (int j = 0; j <= i - 1; ++j) { if (A[i] > A[j]) { left++; // A[i]より小さい数全ての個数 } } ans = (ans + (right + left) * mul) % MOD; } cout << ans << endl; return 0; }
[ "literal.number.change", "variable_declaration.value.change", "control_flow.loop.for.initializer.change", "expression.off_by_one" ]
731,088
731,089
u946090308
cpp
p02928
#include <bits/stdc++.h> using namespace std; #define ll long long #define rep(i, n) for (ll i = 0; i < n; ++i) ll dx[4] = {0, 1, 0, -1}; ll dy[4] = {1, 0, -1, 0}; const ll INF = 1 << LLONG_MAX; const ll MOD = 1e9 + 7; int main() { ios_base::sync_with_stdio(false); cin.tie(0); ll N, K; cin >> N >> K; vector<ll> A(N); rep(i, N) { cin >> A[i]; } ll ans = 0; ll mul = K * (K - 1) / 2 % MOD; for (int i = 0; i < N; ++i) { int right = 0, left = 0; for (int j = i + 1; j < N; ++j) { if (A[i] > A[j]) { right++; // A[i]より小さい右側の数 } } ans = (ans + K * right) % MOD; for (int j = 1; j <= i - 1; ++j) { if (A[i] > A[j]) { left++; // A[i]より小さい数全ての個数 } } ans = (ans + (right + left) * mul) % MOD; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define rep(i, n) for (ll i = 0; i < n; ++i) ll dx[4] = {0, 1, 0, -1}; ll dy[4] = {1, 0, -1, 0}; const ll INF = 1 << LLONG_MAX; const ll MOD = 1e9 + 7; int main() { ios_base::sync_with_stdio(false); cin.tie(0); ll N, K; cin >> N >> K; vector<ll> A(N); rep(i, N) { cin >> A[i]; } ll ans = 0; ll mul = K * (K - 1) / 2 % MOD; for (int i = 0; i < N; ++i) { ll right = 0, left = 0; for (int j = i + 1; j < N; ++j) { if (A[i] > A[j]) { right++; // A[i]より小さい右側の数 } } ans = (ans + K * right) % MOD; for (int j = 0; j <= i - 1; ++j) { if (A[i] > A[j]) { left++; // A[i]より小さい数全ての個数 } } ans = (ans + (right + left) * mul) % MOD; } cout << ans << endl; return 0; }
[ "variable_declaration.type.change", "literal.number.change", "variable_declaration.value.change", "control_flow.loop.for.initializer.change", "expression.off_by_one" ]
731,090
731,089
u946090308
cpp
p02928
#include <algorithm> //STLͨ���㷨 #include <cmath> //������ѧ���� #include <cstdio> //��������/������� #include <cstring> //�ַ������� #include <ctime> //�������ʱ��ĺ��� #include <iostream> //����������/��� #include <string> //�ַ����� #define itn int #define fro for #define ll long long #define reg register #define inf 1234567890 #define rep(i, a, b, c) for (int i = a; i <= b; i += c) /*#include <bitset> //STLλ������ #include <cerrno> //��������� #include <clocale> //���屾�ػ����� #include <complex> //������ #include <cstdlib> //������������ڴ���亯�� #include <cstype> //�ַ����� #include <cwchar.h>//���ַ�����������/��� #include <cwctype.h> //���ַ�����*/ #include <deque> //STL˫�˶������� #include <exception> //�쳣������ #include <fstream> //�ļ�����/��� #include <functional> //STL�������㺯��(���������) #include <iomanip> //����������/��� #include <ios> //��������/���֧�� #include <iosfwd> //����/���ϵͳʹ�õ�ǰ������ #include <istream> //���������� #include <limits> //�����������������ֵ���� #include <list> //STL�����б����� #include <map> //STLӳ������ #include <ostream> //��������� #include <queue> //STL�������� #include <set> //STL�������� #include <sstream> //�����ַ������� #include <stack> //STL��ջ���� #include <stdexcept> //��׼�쳣�� #include <streambuf> //�ײ�����/���֧�� #include <utility> //STLͨ��ģ���� #include <vector> //STL��̬�������� using namespace std; int ans; int max(int x, int y) { return x > y ? x : y; } int min(int x, int y) { return x < y ? x : y; } int abs(int x) { return x > 0 ? x : -x; } int gcd(int x, int y) { return (!y) ? x : gcd(y, x % y); } void exgcd(int a, int b, int &d, int &x, int &y) { if (!b) { d = a, x = 1, y = 0; } else { exgcd(b, a % b, d, y, x); y -= x * (a / b); } } int quick_power(ll a, int b) { ll r = 1; for (; b; b >>= 1, a = a * a) if (b & 1) r = r * a; return r; } inline char read() { static const int IN_LEN = 1000000; static char buf[IN_LEN], *s, *t; return (s == t ? t = (s = buf) + fread(buf, 1, IN_LEN, stdin), (s == t ? -1 : *s++) : *s++); } template <class T> inline void read(T &x) { static bool iosig; static char c; for (iosig = false, c = read(); !isdigit(c); c = read()) { if (c == '-') iosig = true; if (c == -1) return; } for (x = 0; isdigit(c); c = read()) x = x * 10 + (c ^ '0'); if (iosig) x = -x; } char sr[10000000], z[20]; int C = -1, Z = 0; void Ot() { fwrite(sr, 1, C + 1, stdout), C = -1; } void print(int x) { if (x < 0) sr[++C] = '-', x = -x; while (z[++Z] = x % 10 + 48, x /= 10) ; while (sr[++C] = z[Z], --Z) ; sr[++C] = '\n'; } // int find(int x){return fa[x]=fa[x]==x?x:find(fa[x]);} // void add(int x,int y,int // z){to[++cnt]=y;v[cnt]=z;Next[cnt]=head[x];head[x]=cnt;} const int mod = 1e9 + 7; int a[100100], ans1, ans2; int main() { int n, k; read(n); read(k); for (int i = 1; i <= n; i++) read(a[i]); for (int i = 1; i <= n; i++) { for (int j = 1; j < i; j++) if (a[i] > a[j]) ans1++; for (int j = i + 1; j <= n; j++) if (a[i] > a[j]) ans2++; } ll k1 = 1ll * k * (k - 1) / 2 % mod, k2 = 1ll * k * (k + 1) / 2 % mod; cout << 1ll * (ans1 * k1 + ans2 * k2) * k * 500000004 % mod; return 0; }
#include <algorithm> //STLͨ���㷨 #include <cmath> //������ѧ���� #include <cstdio> //��������/������� #include <cstring> //�ַ������� #include <ctime> //�������ʱ��ĺ��� #include <iostream> //����������/��� #include <string> //�ַ����� #define itn int #define fro for #define ll long long #define reg register #define inf 1234567890 #define rep(i, a, b, c) for (int i = a; i <= b; i += c) /*#include <bitset> //STLλ������ #include <cerrno> //��������� #include <clocale> //���屾�ػ����� #include <complex> //������ #include <cstdlib> //������������ڴ���亯�� #include <cstype> //�ַ����� #include <cwchar.h>//���ַ�����������/��� #include <cwctype.h> //���ַ�����*/ #include <deque> //STL˫�˶������� #include <exception> //�쳣������ #include <fstream> //�ļ�����/��� #include <functional> //STL�������㺯��(���������) #include <iomanip> //����������/��� #include <ios> //��������/���֧�� #include <iosfwd> //����/���ϵͳʹ�õ�ǰ������ #include <istream> //���������� #include <limits> //�����������������ֵ���� #include <list> //STL�����б����� #include <map> //STLӳ������ #include <ostream> //��������� #include <queue> //STL�������� #include <set> //STL�������� #include <sstream> //�����ַ������� #include <stack> //STL��ջ���� #include <stdexcept> //��׼�쳣�� #include <streambuf> //�ײ�����/���֧�� #include <utility> //STLͨ��ģ���� #include <vector> //STL��̬�������� using namespace std; int ans; int max(int x, int y) { return x > y ? x : y; } int min(int x, int y) { return x < y ? x : y; } int abs(int x) { return x > 0 ? x : -x; } int gcd(int x, int y) { return (!y) ? x : gcd(y, x % y); } void exgcd(int a, int b, int &d, int &x, int &y) { if (!b) { d = a, x = 1, y = 0; } else { exgcd(b, a % b, d, y, x); y -= x * (a / b); } } int quick_power(ll a, int b) { ll r = 1; for (; b; b >>= 1, a = a * a) if (b & 1) r = r * a; return r; } inline char read() { static const int IN_LEN = 1000000; static char buf[IN_LEN], *s, *t; return (s == t ? t = (s = buf) + fread(buf, 1, IN_LEN, stdin), (s == t ? -1 : *s++) : *s++); } template <class T> inline void read(T &x) { static bool iosig; static char c; for (iosig = false, c = read(); !isdigit(c); c = read()) { if (c == '-') iosig = true; if (c == -1) return; } for (x = 0; isdigit(c); c = read()) x = x * 10 + (c ^ '0'); if (iosig) x = -x; } char sr[10000000], z[20]; int C = -1, Z = 0; void Ot() { fwrite(sr, 1, C + 1, stdout), C = -1; } void print(int x) { if (x < 0) sr[++C] = '-', x = -x; while (z[++Z] = x % 10 + 48, x /= 10) ; while (sr[++C] = z[Z], --Z) ; sr[++C] = '\n'; } // int find(int x){return fa[x]=fa[x]==x?x:find(fa[x]);} // void add(int x,int y,int // z){to[++cnt]=y;v[cnt]=z;Next[cnt]=head[x];head[x]=cnt;} const int mod = 1e9 + 7; int a[100100], ans1, ans2; int main() { int n, k; read(n); read(k); for (int i = 1; i <= n; i++) read(a[i]); for (int i = 1; i <= n; i++) { for (int j = 1; j < i; j++) if (a[i] > a[j]) ans1++; for (int j = i + 1; j <= n; j++) if (a[i] > a[j]) ans2++; } ll k1 = 1ll * k * (k - 1) / 2 % mod, k2 = 1ll * k * (k + 1) / 2 % mod; cout << 1ll * (ans1 * k1 + ans2 * k2) % mod; return 0; }
[ "expression.operation.binary.remove" ]
731,094
731,095
u794315108
cpp
p02928
#include <bits/stdc++.h> #define int long #define ll long long #define rep(i, n) for (int i = 0; i < n; i++) #define IOS \ cin.tie(0); \ ios::sync_with_stdio(false) const int INF = 1e9; using namespace std; #define MOD (1000000007) main() { ll N, K; cin >> N >> K; int A[N]; rep(i, N) cin >> A[i]; int cnt1 = 0, cnt2 = 0; rep(i, N) { rep(j, N) { if (i == j) continue; if (A[i] > A[j]) { cnt2++; if (i < j) cnt1++; } } } ll a = (cnt1 * K) % MOD; ll b = ((K * (K - 1)) % MOD / 2 * cnt2) % MOD; cout << (a + b) % MOD << endl; }
#include <bits/stdc++.h> #define int long #define ll long long #define rep(i, n) for (int i = 0; i < n; i++) #define IOS \ cin.tie(0); \ ios::sync_with_stdio(false) const int INF = 1e9; using namespace std; #define MOD (1000000007) main() { ll N, K; cin >> N >> K; int A[N]; rep(i, N) cin >> A[i]; int cnt1 = 0, cnt2 = 0; rep(i, N) { rep(j, N) { if (i == j) continue; if (A[i] > A[j]) { cnt2++; if (i < j) cnt1++; } } } ll a = (cnt1 * K) % MOD; ll b = (K * (K - 1) / 2 % MOD * cnt2) % MOD; cout << (a + b) % MOD << endl; }
[ "expression.operation.binary.remove" ]
731,099
731,100
u526894223
cpp
p02928
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll mod = 1000000000 + 7; int main() { ll N, K; cin >> N >> K; vector<ll> A(N); for (int i = 0; i < N; i++) cin >> A.at(i); ll res = 0; ll m = 0; ll s = 0; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { if (A.at(i) > A.at(j)) { s++; if (i < j) m++; } s %= mod; m %= mod; } } cout << m * K % mod + K * (K - 1) / 2 % mod * s % mod << endl; // cout<<m<<endl<<s<<endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll mod = 1000000000 + 7; int main() { ll N, K; cin >> N >> K; vector<ll> A(N); for (int i = 0; i < N; i++) cin >> A.at(i); ll res = 0; ll m = 0; ll s = 0; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { if (A.at(i) > A.at(j)) { s++; if (i < j) m++; } s %= mod; m %= mod; } } cout << (m * K % mod + K * (K - 1) / 2 % mod * s % mod) % mod << endl; // cout<<m<<endl<<s<<endl; }
[ "expression.operation.binary.add" ]
731,103
731,104
u652009496
cpp
p02928
#include <cassert> // PXjUXeZStdX #include <ccomplex> #include <cctype> #include <cerrno> #include <cfenv> #include <cfloat> #include <cinttypes> #include <ciso646> #include <climits> #include <clocale> #include <cmath> #include <csetjmp> #include <csignal> #include <cstdarg> #include <cstdbool> #include <cstddef> #include <cstdint> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctgmath> #include <ctime> #include <cwchar> #include <cwctype> // C++ #include <algorithm> #include <array> #include <atomic> #include <bitset> #include <chrono> #include <complex> #include <condition_variable> #include <deque> #include <exception> #include <forward_list> #include <fstream> #include <functional> #include <future> #include <initializer_list> #include <iomanip> #include <ios> #include <iosfwd> #include <iostream> #include <istream> #include <iterator> #include <limits> #include <list> #include <locale> #include <map> #include <memory> #include <mutex> #include <new> #include <numeric> #include <ostream> #include <queue> #include <random> #include <ratio> #include <regex> #include <scoped_allocator> #include <set> #include <sstream> #include <stack> #include <stdexcept> #include <streambuf> #include <string> #include <system_error> #include <thread> #include <tuple> #include <type_traits> #include <typeindex> #include <typeinfo> #include <unordered_map> #include <unordered_set> #include <utility> #include <valarray> #include <vector> // #include <boost/foreach.hpp> // #include <boost/range/algorithm.hpp> #define rep(i, j, k) for (int i = (int)j; i < (int)k; i++) #define ll long long #define Sort(v) sort(all(v)) //#define INF 1e9 #define LINF (1LL << 40) #define END return 0 #define pb push_back #define se second #define fi first #define pb push_back #define all(v) (v).begin(), (v).end() #define MP make_pair #define int long long using namespace std; int day[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; // int dx[]={0,1,0,-1}; // int dy[]={1,0,-1,0}; typedef pair<int, int> P; const long long MOD = 1000000007LL; bool isupper(char c) { if ('A' <= c && c <= 'Z') return 1; return 0; } bool islower(char c) { if ('a' <= c && c <= 'z') return 1; return 0; } bool iskaibun(string s) { for (int i = 0; i < s.size() / 2; i++) if (s[i] != s[s.size() - i - 1]) return 0; return 1; } bool isnumber(char c) { return ('0' <= c && c <= '9'); } bool isalpha(char c) { return (isupper(c) || islower(c)); } template <typename T> void print(vector<T> v) { for (int i = 0; i < v.size(); i++) { if (i) cout << " "; cout << v[i]; } cout << endl; } int INF = 1e18; template <typename T> void printendl(vector<T> v) { for (auto date : v) cout << date << endl; } template <typename T> void printvv(vector<vector<T>> v) { for (int i = 0; i < v.size(); i++) { for (int j = 0; j < v[i].size(); j++) { if (j) cout << " "; cout << v[i][j]; } cout << endl; } } int ans = 0; int gcd(int a, int b) { ans++; if (a < b) swap(a, b); if (b == 0) return a; else return gcd(b, a % b); } int powl(int n, int p) { int ret = 1; for (int i = 0; i < p; i++) ret *= n; return ret; } struct Edge { int to, cost; }; struct S { int score[3]; char team; }; signed main() { int n, k; cin >> n >> k; vector<int> v(n); rep(i, 0, n) cin >> v[i]; int ans = 0; vector<int> c(n, 0); rep(i, 0, n) { rep(j, i + 1, n) { if (v[i] > v[j]) ans++; } rep(j, 0, n) { if (v[i] > v[j]) c[i]++; } } ans *= k; ans %= MOD; rep(i, 0, n) { ans += c[i] * k * (k - 1) / 2; ans %= MOD; } cout << ans << endl; } /* */
#include <cassert> // PXjUXeZStdX #include <ccomplex> #include <cctype> #include <cerrno> #include <cfenv> #include <cfloat> #include <cinttypes> #include <ciso646> #include <climits> #include <clocale> #include <cmath> #include <csetjmp> #include <csignal> #include <cstdarg> #include <cstdbool> #include <cstddef> #include <cstdint> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctgmath> #include <ctime> #include <cwchar> #include <cwctype> // C++ #include <algorithm> #include <array> #include <atomic> #include <bitset> #include <chrono> #include <complex> #include <condition_variable> #include <deque> #include <exception> #include <forward_list> #include <fstream> #include <functional> #include <future> #include <initializer_list> #include <iomanip> #include <ios> #include <iosfwd> #include <iostream> #include <istream> #include <iterator> #include <limits> #include <list> #include <locale> #include <map> #include <memory> #include <mutex> #include <new> #include <numeric> #include <ostream> #include <queue> #include <random> #include <ratio> #include <regex> #include <scoped_allocator> #include <set> #include <sstream> #include <stack> #include <stdexcept> #include <streambuf> #include <string> #include <system_error> #include <thread> #include <tuple> #include <type_traits> #include <typeindex> #include <typeinfo> #include <unordered_map> #include <unordered_set> #include <utility> #include <valarray> #include <vector> // #include <boost/foreach.hpp> // #include <boost/range/algorithm.hpp> #define rep(i, j, k) for (int i = (int)j; i < (int)k; i++) #define ll long long #define Sort(v) sort(all(v)) //#define INF 1e9 #define LINF (1LL << 40) #define END return 0 #define pb push_back #define se second #define fi first #define pb push_back #define all(v) (v).begin(), (v).end() #define MP make_pair #define int long long using namespace std; int day[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; // int dx[]={0,1,0,-1}; // int dy[]={1,0,-1,0}; typedef pair<int, int> P; const long long MOD = 1000000007LL; bool isupper(char c) { if ('A' <= c && c <= 'Z') return 1; return 0; } bool islower(char c) { if ('a' <= c && c <= 'z') return 1; return 0; } bool iskaibun(string s) { for (int i = 0; i < s.size() / 2; i++) if (s[i] != s[s.size() - i - 1]) return 0; return 1; } bool isnumber(char c) { return ('0' <= c && c <= '9'); } bool isalpha(char c) { return (isupper(c) || islower(c)); } template <typename T> void print(vector<T> v) { for (int i = 0; i < v.size(); i++) { if (i) cout << " "; cout << v[i]; } cout << endl; } int INF = 1e18; template <typename T> void printendl(vector<T> v) { for (auto date : v) cout << date << endl; } template <typename T> void printvv(vector<vector<T>> v) { for (int i = 0; i < v.size(); i++) { for (int j = 0; j < v[i].size(); j++) { if (j) cout << " "; cout << v[i][j]; } cout << endl; } } int ans = 0; int gcd(int a, int b) { ans++; if (a < b) swap(a, b); if (b == 0) return a; else return gcd(b, a % b); } int powl(int n, int p) { int ret = 1; for (int i = 0; i < p; i++) ret *= n; return ret; } struct Edge { int to, cost; }; struct S { int score[3]; char team; }; signed main() { int n, k; cin >> n >> k; vector<int> v(n); rep(i, 0, n) cin >> v[i]; int ans = 0; vector<int> c(n, 0); rep(i, 0, n) { rep(j, i + 1, n) { if (v[i] > v[j]) ans++; } rep(j, 0, n) { if (v[i] > v[j]) c[i]++; } } ans *= k; ans %= MOD; rep(i, 0, n) { ans += c[i] * ((k * (k - 1) / 2) % MOD); ans %= MOD; } cout << ans << endl; } /* */
[]
731,114
731,115
u159757494
cpp
p02928
#include <iostream> #include <set> #include <vector> using namespace std; typedef long long ll; const ll mod = 1e9 + 7; ll modpow(ll a, ll b, ll p = 1e9 + 7) { if (b == 0) return 1; if (b % 2 == 0) { ll d = modpow(a, b / 2, p); return (d * d) % p; } else { return (a % p * modpow(a, b - 1, p)) % p; } } int main() { int n; ll k; cin >> n >> k; k %= mod; if (k == 0) k = mod; 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 cnt = 0; for (int j = i + 1; j < n; j++) { if (v[i] > v[j]) cnt++; } ll tmp = 0; for (int j = 0; j < n; j++) { if (v[i] > v[j]) tmp++; } ll a = 2 * cnt + (k - 1) * tmp; a %= mod; a = a * modpow(2, -1) % mod * k % mod; ans += a; ans %= mod; } cout << ans << endl; return 0; }
#include <iostream> #include <set> #include <vector> using namespace std; typedef long long ll; const ll mod = 1e9 + 7; ll modpow(ll a, ll b, ll p = 1e9 + 7) { if (b == 0) return 1; if (b % 2 == 0) { ll d = modpow(a, b / 2, p); return (d * d) % p; } else { return (a % p * modpow(a, b - 1, p)) % p; } } int main() { int n; ll k; cin >> n >> k; k %= mod; if (k == 0) k = mod; 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 cnt = 0; for (int j = i + 1; j < n; j++) { if (v[i] > v[j]) cnt++; } ll tmp = 0; for (int j = 0; j < n; j++) { if (v[i] > v[j]) tmp++; } ll a = 2 * cnt + (k - 1) * tmp; a %= mod; a = a * modpow(2, mod - 2) % mod * k % mod; ans += a; ans %= mod; } cout << ans << endl; return 0; }
[ "call.arguments.change", "literal.number.change", "assignment.value.change", "expression.operation.binary.change" ]
731,116
731,117
u734519000
cpp
p02928
#include <cstdio> #include <iostream> using namespace std; #define MOD 1000000007 int main() { int n, k; scanf("%d%d", &n, &k); int a[n]; for (int i = 0; i < n; i++) { scanf("%d", &a[i]); } int ans = 0; for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { if (a[i] > a[j]) { ans += k * (k + 1) / 2; ans %= MOD; } else if (a[i] < a[j]) { ans += k * (k - 1) / 2; ans %= MOD; } } } cout << ans << endl; return 0; }
#include <cstdio> #include <iostream> using namespace std; #define MOD 1000000007 int main() { long long n, k; scanf("%lld%lld", &n, &k); int a[n]; for (int i = 0; i < n; i++) { scanf("%d", &a[i]); } long long ans = 0; for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { if (a[i] > a[j]) { ans += k * (k + 1) / 2; ans %= MOD; } else if (a[i] < a[j]) { ans += k * (k - 1) / 2; ans %= MOD; } } } cout << ans << endl; return 0; }
[ "variable_declaration.type.primitive.change", "variable_declaration.type.widen.change", "literal.string.change", "call.arguments.change" ]
731,129
731,130
u765857778
cpp
p02928
#include <bits/stdc++.h> using namespace std; int main() { long long N, K; long long mod = 1e9 + 7; long long ans = 0, tmp = 0, tmp2 = 0, tmp3; cin >> N >> K; vector<int> a(N); for (int i = 0; i < N; i++) { cin >> a[i]; } for (int i = 0; i < N; i++) { for (int j = i; j < N; j++) { if (a[i] > a[j]) tmp++; } } for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { if (a[i] > a[j]) tmp2++; } } tmp3 = (((K - 1) * K) % mod * tmp2) % mod / 2; ans = tmp * K; ans %= mod; ans += tmp3; ans %= mod; cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int main() { long long N, K; long long mod = 1e9 + 7; long long ans = 0, tmp = 0, tmp2 = 0, tmp3; cin >> N >> K; vector<int> a(N); for (int i = 0; i < N; i++) { cin >> a[i]; } for (int i = 0; i < N; i++) { for (int j = i; j < N; j++) { if (a[i] > a[j]) tmp++; } } for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { if (a[i] > a[j]) tmp2++; } } tmp3 = ((((K - 1) * K) / 2) % mod * tmp2) % mod; ans = tmp * K; ans %= mod; ans += tmp3; ans %= mod; cout << ans << endl; }
[ "expression.operation.binary.remove" ]
731,134
731,135
u074306398
cpp
p02928
#include <iostream> using namespace std; using ll = long long; const ll mod = (1e9) + 7; ll n, k; ll a[2005]; ll ans; int main() { cin >> n >> k; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < n; i++) { ll cnt = 0; for (int j = i + 1; j < n; j++) { if (a[i] > a[j]) { cnt++; } } ll cnt2 = 0; for (int j = 0; j < n; j++) { if (a[i] > a[j]) { cnt2++; } } ans += (cnt * k) % mod; ans += cnt2 * (k * (k - 1) / 2) % mod; ans %= mod; } cout << ans << endl; return 0; }
#include <iostream> using namespace std; using ll = long long; const ll mod = (1e9) + 7; ll n, k; ll a[2005]; ll ans; int main() { cin >> n >> k; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < n; i++) { ll cnt = 0; for (int j = i + 1; j < n; j++) { if (a[i] > a[j]) { cnt++; } } ll cnt2 = 0; for (int j = 0; j < n; j++) { if (a[i] > a[j]) { cnt2++; } } ans += (cnt * k) % mod; ans += cnt2 * ((k * (k - 1) / 2) % mod) % mod; ans %= mod; } cout << ans << endl; return 0; }
[ "assignment.change" ]
731,141
731,142
u683588090
cpp
p02928
#include <bits/stdc++.h> using namespace std; #define min(a, b) ((a) < (b) ? (a) : (b)) #define max(a, b) ((a) > (b) ? (a) : (b)) #define REP(i, n) for (ll i = 0; i < n; i++) #define FOR(i, n1, n2) for (ll i = n1; i < n2; i++) #define bFOR(i, n1, n2) for (ll i = n1; i >= n2; i--) #define speed_up \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); typedef long long int ll; typedef pair<ll, ll> Pi; typedef tuple<ll, ll, ll> Tu; const int INF = (ll)(1LL << 30) - 1; const double INFd = 100000000000.0; const ll INFl = (ll)9223372036854775807; const int MAX = 10000; const ll MOD = (ll)1e9 + 7; ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } int dx[4] = {0, -1, 0, 1}, dy[4] = {-1, 0, 1, 0}; int mdx[8] = {0, 1, 0, -1, 1, 1, -1, -1}, mdy[8] = {-1, 0, 1, 0, 1, -1, 1, -1}; template <typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); } ll n, k; ll a[2010]; ll less_all[2010]; ll less_right[2010]; ll ans = 0; int main() { cin >> n >> k; REP(i, n) cin >> a[i]; REP(i, n) { REP(j, n) { if (a[i] > a[j]) { less_all[i]++; if (i < j) { less_right[i]++; } } } } REP(i, n) { ans += less_right[i] * k; ans %= MOD; } REP(i, n) { ans += less_all[i] * (k - 1) * (k) / 2; ans %= MOD; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define min(a, b) ((a) < (b) ? (a) : (b)) #define max(a, b) ((a) > (b) ? (a) : (b)) #define REP(i, n) for (ll i = 0; i < n; i++) #define FOR(i, n1, n2) for (ll i = n1; i < n2; i++) #define bFOR(i, n1, n2) for (ll i = n1; i >= n2; i--) #define speed_up \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); typedef long long int ll; typedef pair<ll, ll> Pi; typedef tuple<ll, ll, ll> Tu; const int INF = (ll)(1LL << 30) - 1; const double INFd = 100000000000.0; const ll INFl = (ll)9223372036854775807; const int MAX = 10000; const ll MOD = (ll)1e9 + 7; ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } int dx[4] = {0, -1, 0, 1}, dy[4] = {-1, 0, 1, 0}; int mdx[8] = {0, 1, 0, -1, 1, 1, -1, -1}, mdy[8] = {-1, 0, 1, 0, 1, -1, 1, -1}; template <typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); } ll n, k; ll a[2010]; ll less_all[2010]; ll less_right[2010]; ll ans = 0; int main() { cin >> n >> k; REP(i, n) cin >> a[i]; REP(i, n) { REP(j, n) { if (a[i] > a[j]) { less_all[i]++; if (i < j) { less_right[i]++; } } } } REP(i, n) { ans += less_right[i] * k; ans %= MOD; } REP(i, n) { ans += less_all[i] * (((k - 1) * (k) / 2) % MOD); ans %= MOD; } cout << ans << endl; return 0; }
[]
731,150
731,151
u055303078
cpp
p02928
/* ░░░░░░░░░░░░░░░░▄▄█▀▀██▄▄░░░░░░░ ░░░░░░░░░░░░░▄█▀▀░░░░░░░▀█░░░░░░ ░░░░░░░░░░░▄▀░░░░░░░░░░░░░█░░░░░ ░░░░░░░░░▄█░░░░░░░░░░░░░░░█░░░░░ ░░░░░░░██▀░░░░░░░▄▄▄░░▄░█▄█▄░░░░ ░░░░░▄▀░░░░░░░░░░████░█▄██░▀▄░░░ ░░░░█▀░░░░░░░░▄▄██▀░░█████░██░░░ ░░░█▀░░░░░░░░░▀█░▀█▀█▀▀▄██▄█▀░░░ ░░░██░░░░░░░░░░█░░█░█░░▀▀▄█▀░░░░ ░░░░█░░░░░█░░░▀█░░░░▄░░░░░▄█░░░░ ░░░░▀█░░░░███▄░█░░░░░░▄▄▄▄█▀█▄░░ ░░░░░▀██░░█▄▀▀██░░░░░░░░▄▄█░░▀▄░ ░░░░░░▀▀█▄░▀▄▄░▄░░░░░░░███▀░░▄██ ░░░░░░░░░▀▀▀███▀█▄░░░░░█▀░▀░░░▀█ ░░░░░░░░░░░░▄▀░░░▀█▄░░░░░▄▄░░▄█▀ ░░░▄▄▄▀▀▀▀▀█▀░░░░░█▄▀▄▄▄▄▄▄█▀▀░░ ░▄█░░░▄██▀░░░░░░░░░█▄░░░░░░░░░░░ █▀▀░▄█░░░░░░░░░░░░░░▀▀█▄░░░░░░░░ █░░░█░░░░░░░░░░░░░░░░░░█▄░░░░░░░ */ #include <bits/stdc++.h> using namespace std; #define pb push_back #define dbg(x) cout << #x << '=' << x << '\n'; #define ll long long #define x first #define y second #define pi pair<int, int> #define vi vector<int> #define L nod << 1 #define R ((nod << 1) | 1) #define int ll const ll mod = 1000000007; const ll nmax = 1000003; #define int ll int n, k, a[2002], ans1, ans2, cnt[2002]; int32_t main() { ios_base ::sync_with_stdio(0); cin.tie(); cout.tie(); cin >> n >> k; for (int i = 1; i <= n; i++) { cin >> a[i]; for (int j = 1; j < i; j++) cnt[i] += (a[i] < a[j]); } for (int i = 1; i <= n; i++) ans1 += cnt[i]; for (int i = 1; i <= n; i++) { for (int j = i + 1; j <= n; j++) cnt[i] += (a[i] < a[j]); } for (int i = 1; i <= n; i++) ans2 += cnt[i]; ans1 *= k, ans1 %= mod; ans2 *= (k - 1) * k / 2, ans2 %= mod; cout << (ans1 + ans2) % mod; }
/* ░░░░░░░░░░░░░░░░▄▄█▀▀██▄▄░░░░░░░ ░░░░░░░░░░░░░▄█▀▀░░░░░░░▀█░░░░░░ ░░░░░░░░░░░▄▀░░░░░░░░░░░░░█░░░░░ ░░░░░░░░░▄█░░░░░░░░░░░░░░░█░░░░░ ░░░░░░░██▀░░░░░░░▄▄▄░░▄░█▄█▄░░░░ ░░░░░▄▀░░░░░░░░░░████░█▄██░▀▄░░░ ░░░░█▀░░░░░░░░▄▄██▀░░█████░██░░░ ░░░█▀░░░░░░░░░▀█░▀█▀█▀▀▄██▄█▀░░░ ░░░██░░░░░░░░░░█░░█░█░░▀▀▄█▀░░░░ ░░░░█░░░░░█░░░▀█░░░░▄░░░░░▄█░░░░ ░░░░▀█░░░░███▄░█░░░░░░▄▄▄▄█▀█▄░░ ░░░░░▀██░░█▄▀▀██░░░░░░░░▄▄█░░▀▄░ ░░░░░░▀▀█▄░▀▄▄░▄░░░░░░░███▀░░▄██ ░░░░░░░░░▀▀▀███▀█▄░░░░░█▀░▀░░░▀█ ░░░░░░░░░░░░▄▀░░░▀█▄░░░░░▄▄░░▄█▀ ░░░▄▄▄▀▀▀▀▀█▀░░░░░█▄▀▄▄▄▄▄▄█▀▀░░ ░▄█░░░▄██▀░░░░░░░░░█▄░░░░░░░░░░░ █▀▀░▄█░░░░░░░░░░░░░░▀▀█▄░░░░░░░░ █░░░█░░░░░░░░░░░░░░░░░░█▄░░░░░░░ */ #include <bits/stdc++.h> using namespace std; #define pb push_back #define dbg(x) cout << #x << '=' << x << '\n'; #define ll long long #define x first #define y second #define pi pair<int, int> #define vi vector<int> #define L nod << 1 #define R ((nod << 1) | 1) #define int ll const ll mod = 1000000007; const ll nmax = 1000003; #define int ll int n, k, a[2002], ans1, ans2, cnt[2002]; int32_t main() { ios_base ::sync_with_stdio(0); cin.tie(); cout.tie(); cin >> n >> k; for (int i = 1; i <= n; i++) { cin >> a[i]; for (int j = 1; j < i; j++) cnt[i] += (a[i] < a[j]); } for (int i = 1; i <= n; i++) ans1 += cnt[i]; for (int i = 1; i <= n; i++) { for (int j = i + 1; j <= n; j++) cnt[i] += (a[i] < a[j]); } for (int i = 1; i <= n; i++) ans2 += cnt[i]; // cout<<ans1<<" "<<ans2<<endl; ans1 *= k; ans1 %= mod; ans2 *= ((k - 1) * k / 2) % mod; ans2 %= mod; cout << (ans1 + ans2) % mod; }
[ "assignment.value.change", "assignment.add" ]
731,152
731,153
u392848063
cpp
p02928
#include <algorithm> #include <iostream> #define ll long long using namespace std; const ll mod = 1000000007; /*ll fast_mul(ll x,ll y) { ll temp=x*y-(ll)((long double)x*y/mod+1.0e-8)*mod; return temp<0?temp+mod:temp; }*/ ll fast_mul(ll x, ll y) { ll temp = (x * y - (ll)((long double)x * y / mod + mod) * mod) % mod; return temp; } int main() { ll n, k, s, i, j, x, y, p = 0, q = 0, a[2005]; cin >> n >> k; for (i = 0; i < n; i++) { cin >> a[i]; } for (i = 0; i < n; i++) { for (j = i + 1; j < n; j++) { if (a[i] > a[j]) { p++; } } } sort(a, a + n); for (i = 0; i < n; i++) { for (j = i + 1; j < n; j++) { if (a[j] > a[i]) { q++; } } } if (k % 2 == 0) { x = k / 2; y = k - 1; } else { x = k; y = (k - 1) / 2; } s = (p * k) % mod + (fast_mul(x, y) * q) % mod; cout << s % mod << endl; return 0; }
#include <algorithm> #include <iostream> #define ll long long using namespace std; const ll mod = 1000000007; /*ll fast_mul(ll x,ll y) { ll temp=x*y-(ll)((long double)x*y/mod+1.0e-8)*mod; return temp<0?temp+mod:temp; }*/ ll fast_mul(ll x, ll y) { ll temp = (x * y - (ll)((long double)x * y / mod) * mod + mod) % mod; return temp; } int main() { ll n, k, s, i, j, x, y, p = 0, q = 0, a[2005]; cin >> n >> k; for (i = 0; i < n; i++) { cin >> a[i]; } for (i = 0; i < n; i++) { for (j = i + 1; j < n; j++) { if (a[i] > a[j]) { p++; } } } sort(a, a + n); for (i = 0; i < n; i++) { for (j = i + 1; j < n; j++) { if (a[j] > a[i]) { q++; } } } if (k % 2 == 0) { x = k / 2; y = k - 1; } else { x = k; y = (k - 1) / 2; } s = (p * k) % mod + (fast_mul(x, y) * q) % mod; cout << s % mod << endl; return 0; }
[ "expression.operation.binary.remove" ]
731,156
731,157
u086925634
cpp
p02925
#include <bits/stdc++.h> using namespace std; const int N = 1010; int n; int indegree[N * N]; vector<int> g[N * N]; int toint(int x, int y) { if (x > y) swap(x, y); return n * x + y; } pair<int, int> demap(int x) { return {x / n, x % n}; } int main() { scanf("%d", &n); for (int i = 0; i < n; i++) { int last; scanf("%d", &last); last--; for (int j = 0; j < n - 2; j++) { int cur; scanf("%d", &cur); cur--; g[toint(i, last)].push_back(toint(i, cur)); indegree[toint(i, cur)]++; last = cur; } } int proc = 0, ans = 0; vector<int> cur_set; for (int i = 0; i < n * (n - 1); i++) if (!indegree[i] && demap(i).first < demap(i).second) cur_set.push_back(i); while ((int)cur_set.size() > 0) { ans++; proc += (int)cur_set.size(); vector<int> nxt; for (int u : cur_set) for (int v : g[u]) { indegree[v]--; if (!indegree[v]) nxt.push_back(v); } cur_set = nxt; } printf("%d\n", proc, (proc == n * (n - 1) / 2 ? ans : -1)); return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 1010; int n; int indegree[N * N]; vector<int> g[N * N]; int toint(int x, int y) { if (x > y) swap(x, y); return n * x + y; } pair<int, int> demap(int x) { return {x / n, x % n}; } int main() { scanf("%d", &n); for (int i = 0; i < n; i++) { int last; scanf("%d", &last); last--; for (int j = 0; j < n - 2; j++) { int cur; scanf("%d", &cur); cur--; g[toint(i, last)].push_back(toint(i, cur)); indegree[toint(i, cur)]++; last = cur; } } int proc = 0, ans = 0; vector<int> cur_set; for (int i = 0; i < n * (n - 1); i++) if (!indegree[i] && demap(i).first < demap(i).second) cur_set.push_back(i); while ((int)cur_set.size() > 0) { ans++; proc += (int)cur_set.size(); vector<int> nxt; for (int u : cur_set) for (int v : g[u]) { indegree[v]--; if (!indegree[v]) nxt.push_back(v); } cur_set = nxt; } printf("%d\n", (proc == n * (n - 1) / 2 ? ans : -1)); return 0; }
[ "call.arguments.change" ]
731,165
731,166
u153798346
cpp
p02925
#include <bits/stdc++.h> using namespace std; const int N = 1010; int n; int indegree[N]; vector<int> g[N * N]; int toint(int x, int y) { if (x > y) swap(x, y); return n * x + y; } pair<int, int> demap(int x) { return {x / n, x % n}; } int main() { scanf("%d", &n); for (int i = 0; i < n; i++) { int last; scanf("%d", &last); last--; for (int j = 0; j < n - 2; j++) { int cur; scanf("%d", &cur); cur--; g[toint(i, last)].push_back(toint(i, cur)); indegree[toint(i, cur)]++; last = cur; } } int proc = 0, ans = 0; vector<int> cur_set; for (int i = 0; i < n * (n - 1); i++) if (!indegree[i] && demap(i).first < demap(i).second) cur_set.push_back(i); while ((int)cur_set.size() > 0) { ans++; proc += (int)cur_set.size(); vector<int> nxt; for (int u : cur_set) for (int v : g[u]) { indegree[v]--; if (!indegree[v]) nxt.push_back(v); } cur_set = nxt; } printf("%d\n", proc, (proc == n * (n - 1) / 2 ? ans : -1)); return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 1010; int n; int indegree[N * N]; vector<int> g[N * N]; int toint(int x, int y) { if (x > y) swap(x, y); return n * x + y; } pair<int, int> demap(int x) { return {x / n, x % n}; } int main() { scanf("%d", &n); for (int i = 0; i < n; i++) { int last; scanf("%d", &last); last--; for (int j = 0; j < n - 2; j++) { int cur; scanf("%d", &cur); cur--; g[toint(i, last)].push_back(toint(i, cur)); indegree[toint(i, cur)]++; last = cur; } } int proc = 0, ans = 0; vector<int> cur_set; for (int i = 0; i < n * (n - 1); i++) if (!indegree[i] && demap(i).first < demap(i).second) cur_set.push_back(i); while ((int)cur_set.size() > 0) { ans++; proc += (int)cur_set.size(); vector<int> nxt; for (int u : cur_set) for (int v : g[u]) { indegree[v]--; if (!indegree[v]) nxt.push_back(v); } cur_set = nxt; } printf("%d\n", (proc == n * (n - 1) / 2 ? ans : -1)); return 0; }
[ "call.arguments.change" ]
731,167
731,166
u153798346
cpp
p02925
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll INF = 1e18; const int BIG = 1e9 + 555; const int maxN = 1000 + 9; int n; int a[maxN][maxN], idx[maxN]; bool mrk[maxN]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; for (int i = 1; i <= n; i++) { for (int j = 1; j <= n - 1; j++) { cin >> a[i][j]; } idx[i] = 1; } vector<int> que[2]; int cur = 0; fill_n(mrk + 1, n, false); for (int i = 1; i <= n; i++) { int j = a[i][idx[i]]; if (mrk[i] || mrk[j]) { continue; } if (a[j][idx[j]] == i) { // cerr << "1 " << i << ' ' << j << '\n'; que[cur].push_back(i); que[cur].push_back(j); idx[i]++; idx[j]++; mrk[i] = mrk[j] = true; } } int ans = 1; while (!que[cur].empty()) { que[1 - cur].clear(); ans++; fill_n(mrk + 1, n, false); for (int i = 0, L = que[cur].size(); i < L; i++) { int x = que[cur][i]; if (idx[x] > n - 1) { continue; } int y = a[x][idx[x]]; if (mrk[x] || mrk[y]) { continue; } if (a[y][idx[y]] == x) { que[1 - cur].push_back(x); que[1 - cur].push_back(y); idx[x]++; idx[y]++; mrk[x] = mrk[y] = true; } } cur = 1 - cur; } for (int i = 1; i <= n; i++) { if (idx[i] <= n - 1) { cout << "-1\n"; return 0; } } cout << ans << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll INF = 1e18; const int BIG = 1e9 + 555; const int maxN = 1000 + 9; int n; int a[maxN][maxN], idx[maxN]; bool mrk[maxN]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; for (int i = 1; i <= n; i++) { for (int j = 1; j <= n - 1; j++) { cin >> a[i][j]; } idx[i] = 1; } vector<int> que[2]; int cur = 0; fill_n(mrk + 1, n, false); for (int i = 1; i <= n; i++) { int j = a[i][idx[i]]; if (mrk[i] || mrk[j]) { continue; } if (a[j][idx[j]] == i) { // cerr << "1 " << i << ' ' << j << '\n'; que[cur].push_back(i); que[cur].push_back(j); idx[i]++; idx[j]++; mrk[i] = mrk[j] = true; } } int ans = 0; while (!que[cur].empty()) { que[1 - cur].clear(); ans++; fill_n(mrk + 1, n, false); for (int i = 0, L = que[cur].size(); i < L; i++) { int x = que[cur][i]; if (idx[x] > n - 1) { continue; } int y = a[x][idx[x]]; if (mrk[x] || mrk[y]) { continue; } if (a[y][idx[y]] == x) { // cerr << ans << ' ' << x << ' ' << y << '\n'; que[1 - cur].push_back(x); que[1 - cur].push_back(y); idx[x]++; idx[y]++; mrk[x] = mrk[y] = true; } } cur = 1 - cur; } for (int i = 1; i <= n; i++) { if (idx[i] <= n - 1) { cout << "-1\n"; return 0; } } cout << ans << '\n'; return 0; }
[ "literal.number.change", "variable_declaration.value.change" ]
731,172
731,173
u482794458
cpp
p02925
#include <bits/stdc++.h> #define ll long long #define F first #define S second #define pii pair<int, int> #define vi vector<int> #define vii vector<pii> #define pb push_back using namespace std; const int N = 1005; void fast() { std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } int n, a[N][N]; queue<int> q[N]; vi v, e; bool check() { for (int i = 0; i < n; i++) { if (!q[i].empty()) { return false; } } return true; } int main() { fast(); cin >> n; for (int i = 0; i < n; i++) for (int j = 0; j < n - 1; j++) cin >> a[i][j], q[i].push(a[i][j] - 1); for (int i = 0; i < n; i++) v.pb(i); for (int ans = 1;; ans++) { e.clear(); vector<bool> use(n); if (check()) { cout << ans - 1 << endl; return 0; } bool ok = false; for (int k = 0; k < v.size(); k++) { int i = v[i]; if (!use[i] && !q[i].empty()) { int nxt = q[i].front(); if (!use[nxt] && !q[nxt].empty() && q[nxt].front() == i) { ok = true; use[nxt] = true; use[i] = true; q[nxt].pop(); q[i].pop(); e.pb(nxt); e.pb(i); } } } if (!ok) { cout << "-1"; return 0; } v = e; } return 0; }
#include <bits/stdc++.h> #define ll long long #define F first #define S second #define pii pair<int, int> #define vi vector<int> #define vii vector<pii> #define pb push_back using namespace std; const int N = 1005; void fast() { std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } int n, a[N][N]; queue<int> q[N]; vi v, e; bool check() { for (int i = 0; i < n; i++) { if (!q[i].empty()) { return false; } } return true; } int main() { fast(); cin >> n; for (int i = 0; i < n; i++) for (int j = 0; j < n - 1; j++) cin >> a[i][j], q[i].push(a[i][j] - 1); for (int i = 0; i < n; i++) v.pb(i); for (int ans = 1;; ans++) { e.clear(); vector<bool> use(n); if (check()) { cout << ans - 1 << endl; return 0; } bool ok = false; for (int k = 0; k < v.size(); k++) { int i = v[k]; if (!use[i] && !q[i].empty()) { int nxt = q[i].front(); if (!use[nxt] && !q[nxt].empty() && q[nxt].front() == i) { ok = true; use[nxt] = true; use[i] = true; q[nxt].pop(); q[i].pop(); e.pb(nxt); e.pb(i); } } } if (!ok) { cout << "-1"; return 0; } v = e; } return 0; }
[ "identifier.change", "variable_access.subscript.index.change" ]
731,174
731,175
u785897267
cpp
p02925
#include <bits/stdc++.h> typedef long long ll; using namespace std; #define DUMP(x) cout << #x << " = " << (x) << endl; #define FOR(i, m, n) for (ll i = m; i < n; i++) #define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--) #define REP(i, n) FOR(i, 0, n) #define IREP(i, n) IFOR(i, 0, n) #define FOREACH(x, a) for (auto &(x) : (a)) #define ALL(v) (v).begin(), (v).end() #define SZ(x) ll(x.size()) void no() { cout << -1 << endl; exit(0); } typedef pair<ll, ll> P; 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; } int main() { ll N; cin >> N; vector<vector<ll>> a(N + 1, vector<ll>(N + 1, 0)); vector<vector<vector<P>>> edge(N + 1, vector<vector<P>>(N + 1)); // map<pair<ll,ll>, vector<pair<ll,ll>> edge; // map<P, ll> deg; vector<vector<ll>> deg(N, vector<ll>(N + 1, 0)); FOR(i, 1, N + 1) FOR(j, 1, N) { cin >> a[i][j]; } FOR(i, 1, N + 1) FOR(j, 1, N - 1) { ll x = a[i][j], y = a[i][j + 1]; ll k = i, l = i; if (i > x) swap(k, x); if (i > y) swap(l, y); edge[k][x].push_back({l, y}); deg[l][y]++; // DUMP(l);DUMP(y); } stack<P> st; FOR(i, 1, N) FOR(j, 1, N + 1) { // if(i<j){ // DUMP(i); DUMP(j); DUMP(deg[i][j]); // } if (i < j && deg[i][j] == 0) st.push({i, j}); } vector<vector<ll>> dp(N + 1, vector<ll>(N + 1, 0)); vector<P> topo; while (!st.empty()) { P p = st.top(); st.pop(); topo.push_back(p); ll i = p.first, j = p.second; // DUMP(i);DUMP(j); REP(k, SZ(edge[i][j])) { P q = edge[i][j][k]; deg[q.first][q.second]--; chmax(dp[q.first][q.second], dp[i][j] + 1); if (deg[q.first][q.second] == 0) st.push(q); } } if (SZ(topo) == N * (N - 1) / 2) no(); ll ans = 0; FOR(i, 1, N) FOR(j, i + 1, N + 1) ans = max(ans, dp[i][j]); cout << ans + 1 << endl; }
#include <bits/stdc++.h> typedef long long ll; using namespace std; #define DUMP(x) cout << #x << " = " << (x) << endl; #define FOR(i, m, n) for (ll i = m; i < n; i++) #define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--) #define REP(i, n) FOR(i, 0, n) #define IREP(i, n) IFOR(i, 0, n) #define FOREACH(x, a) for (auto &(x) : (a)) #define ALL(v) (v).begin(), (v).end() #define SZ(x) ll(x.size()) void no() { cout << -1 << endl; exit(0); } typedef pair<ll, ll> P; 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; } int main() { ll N; cin >> N; vector<vector<ll>> a(N + 1, vector<ll>(N + 1, 0)); vector<vector<vector<P>>> edge(N + 1, vector<vector<P>>(N + 1)); // map<pair<ll,ll>, vector<pair<ll,ll>> edge; // map<P, ll> deg; vector<vector<ll>> deg(N, vector<ll>(N + 1, 0)); FOR(i, 1, N + 1) FOR(j, 1, N) { cin >> a[i][j]; } FOR(i, 1, N + 1) FOR(j, 1, N - 1) { ll x = a[i][j], y = a[i][j + 1]; ll k = i, l = i; if (i > x) swap(k, x); if (i > y) swap(l, y); edge[k][x].push_back({l, y}); deg[l][y]++; // DUMP(l);DUMP(y); } stack<P> st; FOR(i, 1, N) FOR(j, 1, N + 1) { // if(i<j){ // DUMP(i); DUMP(j); DUMP(deg[i][j]); // } if (i < j && deg[i][j] == 0) st.push({i, j}); } vector<vector<ll>> dp(N + 1, vector<ll>(N + 1, 0)); vector<P> topo; while (!st.empty()) { P p = st.top(); st.pop(); topo.push_back(p); ll i = p.first, j = p.second; // DUMP(i);DUMP(j); REP(k, SZ(edge[i][j])) { P q = edge[i][j][k]; deg[q.first][q.second]--; chmax(dp[q.first][q.second], dp[i][j] + 1); if (deg[q.first][q.second] == 0) st.push(q); } } if (SZ(topo) != N * (N - 1) / 2) no(); ll ans = 0; FOR(i, 1, N) FOR(j, i + 1, N + 1) ans = max(ans, dp[i][j]); cout << ans + 1 << endl; }
[ "misc.opposites", "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
731,182
731,183
u708550576
cpp
p02925
#include <bits/stdc++.h> using namespace std; typedef long long signed int LL; typedef long long unsigned int LU; #define incID(i, l, r) for (LL i = (l); i < (r); ++i) #define incII(i, l, r) for (LL i = (l); i <= (r); ++i) #define decID(i, l, r) for (LL i = (r)-1; i >= (l); --i) #define decII(i, l, r) for (LL i = (r); i >= (l); --i) #define inc(i, n) incID(i, 0, n) #define inc1(i, n) incII(i, 1, n) #define dec(i, n) decID(i, 0, n) #define dec1(i, n) decII(i, 1, n) #define inID(v, l, r) ((l) <= (v) && (v) < (r)) #define inII(v, l, r) ((l) <= (v) && (v) <= (r)) #define PB push_back #define EB emplace_back #define MP make_pair #define FI first #define SE second #define ALL(v) v.begin(), v.end() #define RALL(v) v.rbegin(), v.rend() template <typename T> bool setmin(T &a, T b) { if (b < a) { a = b; return true; } else { return false; } } template <typename T> bool setmax(T &a, T b) { if (b > a) { a = b; return true; } else { return false; } } template <typename T> bool setmineq(T &a, T b) { if (b <= a) { a = b; return true; } else { return false; } } template <typename T> bool setmaxeq(T &a, T b) { if (b >= a) { a = b; return true; } else { return false; } } LL mo(LL a, LL b) { assert(b > 0); a %= b; if (a < 0) { a += b; } return a; } LL fl(LL a, LL b) { assert(b > 0); return (a > 0 ? a / b : (a - b + 1) / b); } LL ce(LL a, LL b) { assert(b > 0); return (a < 0 ? a / b : (a + b - 1) / b); } template <typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); } template <typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; } #define bit(b, i) (((b) >> (i)) & 1) #define BC __builtin_popcountll #define SC static_cast #define SI(v) SC<int>(v.size()) #define SL(v) SC<LL>(v.size()) #define RF(e, v) for (auto &e : v) #define ef else if #define UR assert(false) // ---- ---- int n, a[1000][999], p[1000]; set<int> in[1000], w, fin; int main() { cin >> n; inc(i, n) { inc(j, n - 1) { cin >> a[i][j]; a[i][j]--; } } inc(i, n) { w.insert(i); } int ans = -1; inc(i, n * n) { if (SI(fin) == n) { ans = n; break; } RF(e, w) { in[a[e][p[e]]].insert(e); } set<int> nex; RF(e, w) { if (in[e].count(a[e][p[e]]) == 1) { nex.insert(e); nex.insert(a[e][p[e]]); } } w.clear(); RF(e, nex) { in[e].erase(a[e][p[e]]); p[e]++; if (p[e] < n - 1) { w.insert(e); } else { fin.insert(e); } } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long signed int LL; typedef long long unsigned int LU; #define incID(i, l, r) for (LL i = (l); i < (r); ++i) #define incII(i, l, r) for (LL i = (l); i <= (r); ++i) #define decID(i, l, r) for (LL i = (r)-1; i >= (l); --i) #define decII(i, l, r) for (LL i = (r); i >= (l); --i) #define inc(i, n) incID(i, 0, n) #define inc1(i, n) incII(i, 1, n) #define dec(i, n) decID(i, 0, n) #define dec1(i, n) decII(i, 1, n) #define inID(v, l, r) ((l) <= (v) && (v) < (r)) #define inII(v, l, r) ((l) <= (v) && (v) <= (r)) #define PB push_back #define EB emplace_back #define MP make_pair #define FI first #define SE second #define ALL(v) v.begin(), v.end() #define RALL(v) v.rbegin(), v.rend() template <typename T> bool setmin(T &a, T b) { if (b < a) { a = b; return true; } else { return false; } } template <typename T> bool setmax(T &a, T b) { if (b > a) { a = b; return true; } else { return false; } } template <typename T> bool setmineq(T &a, T b) { if (b <= a) { a = b; return true; } else { return false; } } template <typename T> bool setmaxeq(T &a, T b) { if (b >= a) { a = b; return true; } else { return false; } } LL mo(LL a, LL b) { assert(b > 0); a %= b; if (a < 0) { a += b; } return a; } LL fl(LL a, LL b) { assert(b > 0); return (a > 0 ? a / b : (a - b + 1) / b); } LL ce(LL a, LL b) { assert(b > 0); return (a < 0 ? a / b : (a + b - 1) / b); } template <typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); } template <typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; } #define bit(b, i) (((b) >> (i)) & 1) #define BC __builtin_popcountll #define SC static_cast #define SI(v) SC<int>(v.size()) #define SL(v) SC<LL>(v.size()) #define RF(e, v) for (auto &e : v) #define ef else if #define UR assert(false) // ---- ---- int n, a[1000][999], p[1000]; set<int> in[1000], w, fin; int main() { cin >> n; inc(i, n) { inc(j, n - 1) { cin >> a[i][j]; a[i][j]--; } } inc(i, n) { w.insert(i); } int ans = -1; inc(i, n * n) { if (SI(fin) == n) { ans = i; break; } RF(e, w) { in[a[e][p[e]]].insert(e); } set<int> nex; RF(e, w) { if (in[e].count(a[e][p[e]]) == 1) { nex.insert(e); nex.insert(a[e][p[e]]); } } w.clear(); RF(e, nex) { in[e].erase(a[e][p[e]]); p[e]++; if (p[e] < n - 1) { w.insert(e); } else { fin.insert(e); } } } cout << ans << endl; return 0; }
[ "assignment.value.change", "identifier.change" ]
731,193
731,194
u568652083
cpp
p02925
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); ++i) main() { int n; scanf("%d", &n); int a[n][n - 1], b[n][n], vn = 0; rep(i, n) rep(j, n - 1) { scanf("%d", &a[i][j]); a[i][j]--; } rep(i, n) { for (int j = i; j < n; ++j) { b[i][j] = b[j][i] = vn; vn++; } } int deg[n * n]; memset(deg, 0, sizeof deg); vector<int> adj[n * n]; set<int> use_v; rep(i, n) { int prev_v = b[i][a[i][0]]; use_v.insert(prev_v); for (int j = 1; j < n - 1; ++j) { int now_v = b[i][a[i][j]]; use_v.insert(now_v); deg[now_v]++; adj[prev_v].push_back(now_v); prev_v = now_v; } } int sorted[n * n], sidx = 0; memset(sorted, 0, sizeof sorted); queue<int> que; for (const auto &i : use_v) if (deg[i] == 0) que.push(i); while (!que.empty()) { int now_v = que.front(); que.pop(); sorted[sidx] = now_v; sidx++; for (const auto &next_v : adj[now_v]) { deg[next_v]--; if (deg[next_v] == 0) que.push(next_v); } } if (sidx != n * (n - 1) / 2) { puts("-1"); exit(0); } int cost[n * (n - 1) / 2], ans = 0; memset(cost, 0, sizeof cost); for (int i = sidx - 1; i >= 0; --i) { int t = 0, v = sorted[i]; for (const auto &x : adj[v]) t = max(t, cost[x]); cost[v] = t + 1; ans = max(ans, cost[v]); } cout << (ans) << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); ++i) main() { int n; scanf("%d", &n); int a[n][n - 1], b[n][n], vn = 0; rep(i, n) rep(j, n - 1) { scanf("%d", &a[i][j]); a[i][j]--; } rep(i, n) { for (int j = i; j < n; ++j) { b[i][j] = b[j][i] = vn; vn++; } } int deg[n * n]; memset(deg, 0, sizeof deg); vector<int> adj[n * n]; set<int> use_v; rep(i, n) { int prev_v = b[i][a[i][0]]; use_v.insert(prev_v); for (int j = 1; j < n - 1; ++j) { int now_v = b[i][a[i][j]]; use_v.insert(now_v); deg[now_v]++; adj[prev_v].push_back(now_v); prev_v = now_v; } } int sorted[n * n], sidx = 0; memset(sorted, 0, sizeof sorted); queue<int> que; for (const auto &i : use_v) if (deg[i] == 0) que.push(i); while (!que.empty()) { int now_v = que.front(); que.pop(); sorted[sidx] = now_v; sidx++; for (const auto &next_v : adj[now_v]) { deg[next_v]--; if (deg[next_v] == 0) que.push(next_v); } } if (sidx != n * (n - 1) / 2) { puts("-1"); exit(0); } int cost[n * n], ans = 0; memset(cost, 0, sizeof cost); for (int i = sidx - 1; i >= 0; --i) { int t = 0, v = sorted[i]; for (const auto &x : adj[v]) t = max(t, cost[x]); cost[v] = t + 1; ans = max(ans, cost[v]); } cout << (ans) << endl; }
[ "expression.operation.binary.remove" ]
731,197
731,198
u423624748
cpp
p02925
#include <algorithm> #include <bitset> #include <cmath> #include <cstring> #include <deque> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; #define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++) #define rep(i, n) repr(i, 0, n) #define INF 2e9 #define MOD 1000000007 //#define MOD 998244353 #define LINF (long long)4e18 #define jck 3.141592 using ll = long long; using Pi = pair<int, int>; using Pl = pair<ll, ll>; int main() { cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; queue<int> A[N]; rep(i, N) rep(j, N - 1) { int B; cin >> B; A[i].push(B); } int ans = 0; int used[N]; memset(used, 0, sizeof(used)); while (true) { bool ok = false; rep(j, N) { if (A[j].front() - 1 >= 0 && A[A[j].front() - 1].front() == j + 1 && used[j] == 0 && used[A[j].front() - 1] == 0) { used[j] = 1; used[A[j].front() - 1] = 1; A[A[j].front() - 1].pop(); A[j].pop(); ok = true; } } if (!ok) break; rep(i, N) used[i] = 0; ans++; } rep(i, N) { if (A[i].size() != 0) { cout << -1 << endl; return 0; } } cout << ans - 1 << '\n'; }
#include <algorithm> #include <bitset> #include <cmath> #include <cstring> #include <deque> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; #define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++) #define rep(i, n) repr(i, 0, n) #define INF 2e9 #define MOD 1000000007 //#define MOD 998244353 #define LINF (long long)4e18 #define jck 3.141592 using ll = long long; using Pi = pair<int, int>; using Pl = pair<ll, ll>; int main() { cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; queue<int> A[N]; rep(i, N) rep(j, N - 1) { int B; cin >> B; A[i].push(B); } int ans = 0; int used[N]; memset(used, 0, sizeof(used)); while (true) { bool ok = false; rep(j, N) { if (A[j].front() - 1 >= 0 && A[A[j].front() - 1].front() == j + 1 && used[j] == 0 && used[A[j].front() - 1] == 0) { used[j] = 1; used[A[j].front() - 1] = 1; A[A[j].front() - 1].pop(); A[j].pop(); ok = true; } } if (!ok) break; rep(i, N) used[i] = 0; ans++; } rep(i, N) { if (A[i].size() != 0) { cout << -1 << '\n'; return 0; } } cout << ans << '\n'; }
[ "io.output.change", "expression.operation.binary.remove" ]
731,216
731,217
u314008046
cpp
p02925
#include <algorithm> #include <array> #include <iostream> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; int mix_id(int l, int r) { if (l > r) { swap(l, r); } return l * 1000 + r; } bool has_cycle(const vector<vector<int>> &nodes, int id, unordered_set<int> &rec_stack, vector<bool> &visited) { if (rec_stack.count(id) > 0) return true; if (visited[id]) return false; visited[id] = true; rec_stack.insert(id); bool res = false; for (int next_id : nodes[id]) { if (has_cycle(nodes, next_id, rec_stack, visited)) { res = true; break; } } rec_stack.erase(id); return res; } int depth(const vector<vector<int>> &nodes, int id, vector<int> &depth_cache) { if (depth_cache[id] >= 0) return depth_cache[id]; int max_depth = 0; for (int next_id : nodes[id]) { max_depth = max(max_depth, depth(nodes, next_id, depth_cache) + 1); } return depth_cache[id] = max_depth; } int main(int argc, char *argv[]) { vector<vector<int>> nodes(1001000); int n; cin >> n; vector<int> targets(n - 1); for (int i = 0; i < n; i++) { for (int j = 0; j < n - 1; j++) { cin >> targets[j]; targets[j]--; } for (int j = 0; j < n - 2; j++) { nodes[mix_id(i, targets[j])].push_back(mix_id(i, targets[j + 1])); } } unordered_set<int> rec_stack; vector<bool> visited(1001000); for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { int id = mix_id(i, j); if (has_cycle(nodes, id, rec_stack, visited)) { cout << -1 << endl; return 0; } } } int max_depth = 0; vector<int> depth_cache(1001000, -1); for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { max_depth = max(max_depth, depth(nodes, mix_id(i, j), depth_cache)); } } cout << max_depth << endl; }
#include <algorithm> #include <array> #include <iostream> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; int mix_id(int l, int r) { if (l > r) { swap(l, r); } return l * 1000 + r; } bool has_cycle(const vector<vector<int>> &nodes, int id, unordered_set<int> &rec_stack, vector<bool> &visited) { if (rec_stack.count(id) > 0) return true; if (visited[id]) return false; visited[id] = true; rec_stack.insert(id); bool res = false; for (int next_id : nodes[id]) { if (has_cycle(nodes, next_id, rec_stack, visited)) { res = true; break; } } rec_stack.erase(id); return res; } int depth(const vector<vector<int>> &nodes, int id, vector<int> &depth_cache) { if (depth_cache[id] >= 0) return depth_cache[id]; int max_depth = 0; for (int next_id : nodes[id]) { max_depth = max(max_depth, depth(nodes, next_id, depth_cache) + 1); } return depth_cache[id] = max_depth; } int main(int argc, char *argv[]) { vector<vector<int>> nodes(1001000); int n; cin >> n; vector<int> targets(n - 1); for (int i = 0; i < n; i++) { for (int j = 0; j < n - 1; j++) { cin >> targets[j]; targets[j]--; } for (int j = 0; j < n - 2; j++) { nodes[mix_id(i, targets[j])].push_back(mix_id(i, targets[j + 1])); } } unordered_set<int> rec_stack; vector<bool> visited(1001000); for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { int id = mix_id(i, j); if (has_cycle(nodes, id, rec_stack, visited)) { cout << -1 << endl; return 0; } } } int max_depth = 0; vector<int> depth_cache(1001000, -1); for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { max_depth = max(max_depth, depth(nodes, mix_id(i, j), depth_cache)); } } cout << max_depth + 1 << endl; }
[ "expression.operation.binary.add" ]
731,243
731,244
u184819501
cpp
p02925
#include <bits/stdc++.h> using namespace std; #define REP(i, a, b) for (int i = a; i < b; i++) #define rep(i, n) REP(i, 0, n) #define all(x) (x).begin(), (x).end() typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> P; int main() { cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; vector<vector<int>> A(N, vector<int>(N - 1)); rep(i, N) { rep(j, N - 1) { cin >> A[i][j]; A[i][j]--; } reverse(all(A)); } int days = 0; vector<P> q; auto check = [&](int i) { if (A[i].size() == 0) return; int j = A[i].back(); if (A[j].size() == 0) return; if (A[j].back() == i) { P p(i, j); if (p.second < p.first) swap(p.first, p.second); q.push_back(p); } }; rep(i, N) { check(i); } while (q.size() > 0) { sort(all(q)); q.erase(unique(all(q)), q.end()); days++; vector<P> prevQ; swap(prevQ, q); for (P p : prevQ) { int i = p.first, j = p.second; A[i].pop_back(); A[j].pop_back(); check(i); check(j); } } rep(i, N) { if (A[i].size() != 0) { puts("-1"); return 0; } } cout << days << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define REP(i, a, b) for (int i = a; i < b; i++) #define rep(i, n) REP(i, 0, n) #define all(x) (x).begin(), (x).end() typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> P; int main() { cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; vector<vector<int>> A(N, vector<int>(N - 1)); rep(i, N) { rep(j, N - 1) { cin >> A[i][j]; A[i][j]--; } reverse(all(A[i])); } int days = 0; vector<P> q; auto check = [&](int i) { if (A[i].size() == 0) return; int j = A[i].back(); if (A[j].size() == 0) return; if (A[j].back() == i) { P p(i, j); if (p.second < p.first) swap(p.first, p.second); q.push_back(p); } }; rep(i, N) { check(i); } while (q.size() > 0) { sort(all(q)); q.erase(unique(all(q)), q.end()); days++; vector<P> prevQ; swap(prevQ, q); for (P p : prevQ) { int i = p.first, j = p.second; A[i].pop_back(); A[j].pop_back(); check(i); check(j); } } rep(i, N) { if (A[i].size() != 0) { puts("-1"); return 0; } } cout << days << endl; return 0; }
[]
731,265
731,266
u475972508
cpp
p02925
#include <algorithm> #include <cassert> #include <chrono> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; #define rep(i, a, b) for (auto i = (a); i < (b); i++) #define rrep(i, a, b) for (auto i = (a); i > (b); i--) #define all(v) (v).begin(), (v).end() #define print(v) \ { \ for (auto x : v) \ cout << x << ' '; \ cout << endl; \ } #define printn(v, n) \ { \ for (int _i = 0; _i < n; _i++) \ cout << *(v + _i) << ' '; \ cout << endl; \ } typedef unsigned long long ull; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<double, double> pdd; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<vvi> vvvi; typedef vector<pii> vpii; const int MAXN = 1e3 + 20; int n; int a[MAXN][MAXN]; int get_node(int x, int y) { if (x > y) swap(x, y); return x * n + y; } vector<int> graph[MAXN * MAXN]; int tin[MAXN * MAXN], tout[MAXN * MAXN], t; vector<int> order; bool dfs(int node) { tin[node] = t++; for (auto to : graph[node]) { if (tout[to]) continue; if (tin[to]) return false; else { bool tmp = dfs(to); if (!tmp) return false; } } tout[node] = t++; order.push_back(node); return true; } bool tp_sort() { memset(tin, 0, sizeof(tin)); memset(tout, 0, sizeof(tout)); t = 1; // loop through all possible root for (int i = 0; i < n * n; i++) { if (i / n > i % n) continue; if (!tin[i]) { bool tmp = dfs(i); if (!tmp) return false; } } return true; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; for (int i = 0; i < n; i++) { for (int j = 0; j < n - 1; j++) { cin >> a[i][j]; a[i][j]--; if (j) graph[get_node(i, a[i][j - 1])].push_back(get_node(i, a[i][j])); } } int valid = tp_sort(); reverse(order.begin(), order.end()); if (!valid) { cout << -1 << endl; return 0; } vector<int> cur(n, 1); for (int i : order) { int x = i / n, y = i % n; int d = max(cur[x], cur[y]); cur[x] = d + 1; cur[y] = d + 1; } cout << *max_element(cur.begin(), cur.end()) - 1 << endl; // print(order); return 0; }
#include <algorithm> #include <cassert> #include <chrono> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; #define rep(i, a, b) for (auto i = (a); i < (b); i++) #define rrep(i, a, b) for (auto i = (a); i > (b); i--) #define all(v) (v).begin(), (v).end() #define print(v) \ { \ for (auto x : v) \ cout << x << ' '; \ cout << endl; \ } #define printn(v, n) \ { \ for (int _i = 0; _i < n; _i++) \ cout << *(v + _i) << ' '; \ cout << endl; \ } typedef unsigned long long ull; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<double, double> pdd; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<vvi> vvvi; typedef vector<pii> vpii; const int MAXN = 1e3 + 20; int n; int a[MAXN][MAXN]; int get_node(int x, int y) { if (x > y) swap(x, y); return x * n + y; } vector<int> graph[MAXN * MAXN]; int tin[MAXN * MAXN], tout[MAXN * MAXN], t; vector<int> order; bool dfs(int node) { tin[node] = t++; for (auto to : graph[node]) { if (tout[to]) continue; if (tin[to]) return false; else { bool tmp = dfs(to); if (!tmp) return false; } } tout[node] = t++; order.push_back(node); return true; } bool tp_sort() { memset(tin, 0, sizeof(tin)); memset(tout, 0, sizeof(tout)); t = 1; // loop through all possible root for (int i = 0; i < n * n; i++) { if (i / n >= i % n) continue; if (!tin[i]) { bool tmp = dfs(i); if (!tmp) return false; } } return true; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; for (int i = 0; i < n; i++) { for (int j = 0; j < n - 1; j++) { cin >> a[i][j]; a[i][j]--; if (j) graph[get_node(i, a[i][j - 1])].push_back(get_node(i, a[i][j])); } } int valid = tp_sort(); reverse(order.begin(), order.end()); if (!valid) { cout << -1 << endl; return 0; } vector<int> cur(n, 1); for (int i : order) { int x = i / n, y = i % n; int d = max(cur[x], cur[y]); cur[x] = d + 1; cur[y] = d + 1; } cout << *max_element(cur.begin(), cur.end()) - 1 << endl; // print(order); return 0; }
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
731,267
731,268
u096453658
cpp
p02925
#include <bits/stdc++.h> #define REP(i, e) for (int(i) = 0; (i) < (e); ++(i)) #define FOR(i, b, e) for (int(i) = (b); (i) < (e); ++(i)) #define ALL(c) (c).begin(), (c).end() #define ACC(c) (accumulate(ALL(c), 0LL)) #define PRINT(x) cout << (x) << "\n" using namespace std; using ll = long long; using pint = pair<int, int>; using pll = pair<ll, ll>; inline int in(int &a) { return scanf("%d", &a); } auto pint_compare = [](pint x, pint y) -> bool { return (x.first < y.first); }; int N; int A[1000][1000]; vector<int> edge[1000000]; bool loop = false; bool visited[1000000]; int dist[1000000]; int dfs(int index) { if (dist[index] > 0) { return dist[index]; } else if (visited[index]) { loop = true; return -1; } visited[index] = true; int m = 1; for (auto next : edge[index]) { m = max(m, dfs(next) + 1); } return dist[index] = m; } signed main() { cin >> N; REP(i, N) REP(j, N - 1) { cin >> A[i][j]; A[i][j]--; } REP(i, N) { REP(j, N - 2) { int a = min(i, A[i][j]), b = max(i, A[i][j]), c = min(i, A[i][j + 1]), d = max(i, A[i][j + 1]); edge[a * (N - 1) + b].push_back(c * (N - 1) + d); } } REP(i, N * N) dist[i] = -1, visited[i] = false; int ans = 0; REP(i, N) { REP(j, N - 1) { ans = max(ans, dfs(i * N + j)); if (loop) { PRINT("-1"); return 0; } } } PRINT(ans); return 0; }
#include <bits/stdc++.h> #define REP(i, e) for (int(i) = 0; (i) < (e); ++(i)) #define FOR(i, b, e) for (int(i) = (b); (i) < (e); ++(i)) #define ALL(c) (c).begin(), (c).end() #define ACC(c) (accumulate(ALL(c), 0LL)) #define PRINT(x) cout << (x) << "\n" using namespace std; using ll = long long; using pint = pair<int, int>; using pll = pair<ll, ll>; inline int in(int &a) { return scanf("%d", &a); } auto pint_compare = [](pint x, pint y) -> bool { return (x.first < y.first); }; int N; int A[1000][1000]; vector<int> edge[1000000]; bool loop = false; bool visited[1000000]; int dist[1000000]; int dfs(int index) { if (dist[index] > 0) { return dist[index]; } else if (visited[index]) { loop = true; return -1; } visited[index] = true; int m = 1; for (auto next : edge[index]) { m = max(m, dfs(next) + 1); } return dist[index] = m; } signed main() { cin >> N; REP(i, N) REP(j, N - 1) { cin >> A[i][j]; A[i][j]--; } REP(i, N) { REP(j, N - 2) { int a = min(i, A[i][j]), b = max(i, A[i][j]), c = min(i, A[i][j + 1]), d = max(i, A[i][j + 1]); edge[a * (N - 1) + b].push_back(c * (N - 1) + d); } } REP(i, N * N) dist[i] = -1, visited[i] = false; int ans = 0; REP(i, N) { REP(j, N - 1) { ans = max(ans, dfs(i * (N - 1) + j)); if (loop) { PRINT("-1"); return 0; } } } PRINT(ans); return 0; }
[ "call.arguments.change" ]
731,295
731,296
u569690172
cpp
p02925
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; typedef long long ll; const int MAXN = 1005; const int MAXV = MAXN * (MAXN - 1) / 2; vector<int> to[MAXV]; int id[MAXN][MAXN]; int toId(int i, int j) { if (i > j) swap(i, j); return id[i][j]; } bool visited[MAXV]; bool calculated[MAXV]; int dp[MAXV]; // max length of path from v int dfs(int v) { if (visited[v]) { if (!calculated[v]) return -1; return dp[v]; } visited[v] = true; dp[v] = 0; for (int u : to[v]) { int res = dfs(u); if (res == -1) return -1; dp[v] = max(dp[v], res + 1); } calculated[v] = true; return dp[v]; } int main() { int n; cin >> n; vector<vector<int>> a(n, vector<int>(n - 1)); rep(i, n) { rep(j, n - 1) { cin >> a[i][j]; a[i][j]--; } } int V = 0; rep(i, n) rep(j, n) { if (i < j) { id[i][j] = V++; } } rep(i, n) { rep(j, n - 1) { a[i][j] = toId(i, a[i][j]); } rep(j, n - 2) { to[a[i][j + 1]].push_back(a[i][j]); } } int ans = 0; rep(i, V) { int res = dfs(i); if (res == -1) { puts("-1"); return 0; } ans = max(ans, res); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; typedef long long ll; const int MAXN = 1005; const int MAXV = MAXN * (MAXN - 1) / 2; vector<int> to[MAXV]; int id[MAXN][MAXN]; int toId(int i, int j) { if (i > j) swap(i, j); return id[i][j]; } bool visited[MAXV]; bool calculated[MAXV]; int dp[MAXV]; // max length of path from v int dfs(int v) { if (visited[v]) { if (!calculated[v]) return -1; return dp[v]; } visited[v] = true; dp[v] = 1; for (int u : to[v]) { int res = dfs(u); if (res == -1) return -1; dp[v] = max(dp[v], res + 1); } calculated[v] = true; return dp[v]; } int main() { int n; cin >> n; vector<vector<int>> a(n, vector<int>(n - 1)); rep(i, n) { rep(j, n - 1) { cin >> a[i][j]; a[i][j]--; } } int V = 0; rep(i, n) rep(j, n) { if (i < j) { id[i][j] = V++; } } rep(i, n) { rep(j, n - 1) { a[i][j] = toId(i, a[i][j]); } rep(j, n - 2) { to[a[i][j + 1]].push_back(a[i][j]); } } int ans = 0; rep(i, V) { int res = dfs(i); if (res == -1) { puts("-1"); return 0; } ans = max(ans, res); } cout << ans << endl; return 0; }
[ "literal.number.change", "assignment.value.change" ]
731,299
731,300
u457283867
cpp
p02925
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; typedef long long ll; const int MAXN = 1005; const int MAXV = MAXN * (MAXN - 1) / 2; vector<int> to[MAXV]; int id[MAXN][MAXN]; int toId(int i, int j) { if (i > j) swap(i, j); return id[i][j]; } bool visited[MAXV]; bool calculated[MAXV]; int dp[MAXV]; // max length of path from v int dfs(int v) { if (visited[v]) { if (!calculated[v]) return -1; return dp[v]; } visited[v] = true; dp[v] = 0; for (int u : to[v]) { int res = dfs(u); if (res == -1) return -1; dp[v] = max(dp[v], res + 1); } calculated[v] = true; return dp[v]; } int main() { int n; cin >> n; vector<vector<int>> a(n, vector<int>(n - 1)); rep(i, n) { rep(j, n - 1) { cin >> a[i][j]; a[i][j]--; } } int V = 0; rep(i, n) rep(j, n) { if (i < j) { id[i][j] = V++; } } rep(i, n) { rep(j, n - 1) { a[i][j] = toId(i, a[i][j]); } rep(j, n - 2) { to[a[i][j + 1]].push_back(a[i][j]); } } int ans = 0; rep(i, n) { int res = dfs(i); if (res == -1) { puts("-1"); return 0; } ans = max(ans, res); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; typedef long long ll; const int MAXN = 1005; const int MAXV = MAXN * (MAXN - 1) / 2; vector<int> to[MAXV]; int id[MAXN][MAXN]; int toId(int i, int j) { if (i > j) swap(i, j); return id[i][j]; } bool visited[MAXV]; bool calculated[MAXV]; int dp[MAXV]; // max length of path from v int dfs(int v) { if (visited[v]) { if (!calculated[v]) return -1; return dp[v]; } visited[v] = true; dp[v] = 1; for (int u : to[v]) { int res = dfs(u); if (res == -1) return -1; dp[v] = max(dp[v], res + 1); } calculated[v] = true; return dp[v]; } int main() { int n; cin >> n; vector<vector<int>> a(n, vector<int>(n - 1)); rep(i, n) { rep(j, n - 1) { cin >> a[i][j]; a[i][j]--; } } int V = 0; rep(i, n) rep(j, n) { if (i < j) { id[i][j] = V++; } } rep(i, n) { rep(j, n - 1) { a[i][j] = toId(i, a[i][j]); } rep(j, n - 2) { to[a[i][j + 1]].push_back(a[i][j]); } } int ans = 0; rep(i, V) { int res = dfs(i); if (res == -1) { puts("-1"); return 0; } ans = max(ans, res); } cout << ans << endl; return 0; }
[ "literal.number.change", "assignment.value.change" ]
731,301
731,300
u457283867
cpp
p02925
#include <bits/stdc++.h> using namespace std; int n, a[1025][1025], vis[1025]; bool flag; bool ok() { for (int i = 1; i <= n; i++) if (a[i][0] != n) return 0; return 1; } int main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); cin >> n; for (int i = 1; i <= n; i++) { for (int j = 1; j <= n - 1; ++j) cin >> a[i][j]; a[i][0] = 1; } for (int z = 0; z <= 0x3f3f3f3f; z++) { if (ok()) { cout << z << '\n'; return 0; } flag = 0; memset(vis, 0, sizeof vis); for (int i = 1; i <= n; i++) { if (vis[i] || a[i][0] == n) continue; int x = a[i][a[i][0]]; if (a[x][a[x][0]] == i && vis[i] != 0 && vis[x] < 1) { a[i][0]++; a[x][0]++; vis[i] = vis[x] = 2 - 1; flag = 1; } } if (!flag) { cout << -1 << '\n'; return 0; } } return 0; }
#include <bits/stdc++.h> using namespace std; int n, a[1025][1025], vis[1025]; bool flag; bool ok() { for (int i = 1; i <= n; i++) if (a[i][0] != n) return 0; return 1; } int main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); cin >> n; for (int i = 1; i <= n; i++) { for (int j = 1; j <= n - 1; ++j) cin >> a[i][j]; a[i][0] = 1; } for (int z = 0; z <= 0x3f3f3f3f; z++) { if (ok()) { cout << z << '\n'; return 0; } flag = 0; memset(vis, 0, sizeof vis); for (int i = 1; i <= n; i++) { if (vis[i] || a[i][0] == n) continue; int x = a[i][a[i][0]]; if (a[x][a[x][0]] == i && vis[i] == 0 && vis[x] < 1) { a[i][0]++; a[x][0]++; vis[i] = vis[x] = 2 - 1; flag = 1; } } if (!flag) { cout << -1 << '\n'; return 0; } } return 0; }
[ "misc.opposites", "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
731,311
731,312
u667714875
cpp
p02925
#include <bits/stdc++.h> using namespace std; int n, a[1025][1025], vis[1025]; bool flag; bool ok() { for (int i = 1; i <= n; i++) if (a[i][0] != n) return 0; return 1; } int main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); cin >> n; for (int i = 1; i <= n; i++) { for (int j = 1; j <= n - 1; ++j) cin >> a[i][j]; a[i][0] = 1; } for (int z = 0; z <= 0x3f3f3f3f; z++) { if (ok()) { cout << z << '\n'; return 0; } flag = 0; // memset(vis, 0, sizeof vis); for (int i = 1; i <= n; i++) { if (vis[i] == z || a[i][0] == n) continue; int x = a[i][a[i][0]]; if (a[x][a[x][0]] == i && vis[i] != z && vis[x] != z) { a[i][0]++; a[x][0]++; vis[i] = vis[x] = z; flag = 1; } } if (!flag) { cout << -1 << '\n'; return 0; } } return 0; }
#include <bits/stdc++.h> using namespace std; int n, a[1025][1025], vis[1025]; bool flag; bool ok() { for (int i = 1; i <= n; i++) if (a[i][0] != n) return 0; return 1; } int main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); cin >> n; for (int i = 1; i <= n; i++) { for (int j = 1; j <= n - 1; ++j) cin >> a[i][j]; a[i][0] = 1; } for (int z = 1; z <= 0x3f3f3f3f; z++) { if (ok()) { cout << z - 1 << '\n'; return 0; } flag = 0; // memset(vis, 0, sizeof vis); for (int i = 1; i <= n; i++) { if (vis[i] == z || a[i][0] == n) continue; int x = a[i][a[i][0]]; if (a[x][a[x][0]] == i && vis[i] != z && vis[x] != z) { a[i][0]++; a[x][0]++; vis[i] = vis[x] = z; flag = 1; } } if (!flag) { cout << -1 << '\n'; return 0; } } return 0; }
[ "literal.number.change", "variable_declaration.value.change", "control_flow.loop.for.initializer.change", "expression.off_by_one" ]
731,313
731,314
u667714875
cpp
p02925
#include <bits/stdc++.h> using namespace std; int n, a[1025][1025]; bool vis[1025], flag; bool ok() { for (int i = 1; i <= n; i++) if (a[i][0] != n) return 0; return 1; } int main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); cin >> n; for (int i = 1; i <= n; i++) { for (int j = 1; j <= n - 1; ++j) cin >> a[i][j]; a[i][0] = 1; } for (int z = 0; z <= 0x3f3f3f3f; z++) { if (ok()) { cout << z << '\n'; return 0; } flag = 0; z++; memset(vis, 0, sizeof vis); for (int i = 1; i <= n; i++) { if (vis[i] || a[i][0] == n) continue; int x = a[i][a[i][0]]; if (a[x][a[x][0]] == i && !vis[i] && !vis[x]) { a[i][0]++; a[x][0]++; vis[i] = vis[x] = 1; flag = 1; } } if (!flag) { cout << -1 << '\n'; return 0; } } return 0; }
#include <bits/stdc++.h> using namespace std; int n, a[1025][1025]; bool vis[1025], flag; bool ok() { for (int i = 1; i <= n; i++) if (a[i][0] != n) return 0; return 1; } int main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); cin >> n; for (int i = 1; i <= n; i++) { for (int j = 1; j <= n - 1; ++j) cin >> a[i][j]; a[i][0] = 1; } for (int z = 0; z <= 0x3f3f3f3f; z++) { if (ok()) { cout << z << '\n'; return 0; } flag = 0; memset(vis, 0, sizeof vis); for (int i = 1; i <= n; i++) { if (vis[i] || a[i][0] == n) continue; int x = a[i][a[i][0]]; if (a[x][a[x][0]] == i && !vis[i] && !vis[x]) { a[i][0]++; a[x][0]++; vis[i] = vis[x] = 1; flag = 1; } } if (!flag) { cout << -1 << '\n'; return 0; } } return 0; }
[ "expression.unary.arithmetic.remove" ]
731,315
731,316
u667714875
cpp
p02925
#include <bits/stdc++.h> using namespace std; int n, a[20000][20000], t = 0; bool flag[20000], fl = 0; bool judge() { for (int i = 1; i <= n; ++i) if (a[i][0] != n) return 0; return 1; } int main() { cin >> n; for (int i = 1; i <= n; ++i) { for (int j = 1; j < n; ++j) cin >> a[i][j]; a[i][0] = 1; } while (1) { if (judge()) { printf("%d\n", t); return 0; } fl = 0; memset(flag, 0, sizeof(flag)); ++t; for (int i = 1; i <= n; ++i) { if (flag[i] || a[i][0] == n) continue; int x = a[i][a[i][0]], y = a[x][a[x][0]]; if (!flag[x] && !flag[i] && i == y) { fl = 1; flag[x] = 1; flag[i] = 1; ++a[i][0]; ++a[x][0]; } } if (!fl) { printf("-1\n"); return 0; } } return 0; }
#include <bits/stdc++.h> using namespace std; int n, a[11000][11000], t = 0; bool flag[11000], fl = 0; bool judge() { for (int i = 1; i <= n; ++i) if (a[i][0] != n) return 0; return 1; } int main() { cin >> n; for (int i = 1; i <= n; ++i) { for (int j = 1; j < n; ++j) cin >> a[i][j]; a[i][0] = 1; } while (1) { if (judge()) { printf("%d\n", t); return 0; } fl = 0; memset(flag, 0, sizeof(flag)); ++t; for (int i = 1; i <= n; ++i) { if (flag[i] || a[i][0] == n) continue; int x = a[i][a[i][0]], y = a[x][a[x][0]]; if (!flag[x] && !flag[i] && i == y) { fl = 1; flag[x] = 1; flag[i] = 1; ++a[i][0]; ++a[x][0]; } } if (!fl) { printf("-1\n"); return 0; } } }
[ "literal.number.change", "variable_declaration.array_dimensions.change" ]
731,319
731,320
u667714875
cpp
p02925
#include <bits/stdc++.h> using namespace std; int n, a[20000][20000], t = 0; bool flag[20000], fl = 0; bool judge() { for (int i = 1; i <= n; ++i) if (a[i][0] != n) return 0; return 1; } int main() { cin >> n; for (int i = 1; i <= n; ++i) { for (int j = 1; j < n; ++j) cin >> a[i][j]; a[i][0] = 1; } while (1) { if (judge()) { printf("%d\n", t); return 0; } fl = 0; memset(flag, 0, sizeof(flag)); ++t; for (int i = 1; i <= n; ++i) { if (flag[i] || a[i][0] == n) continue; int x = a[i][a[i][0]], y = a[x][a[x][0]]; if (!flag[x] && !flag[i] && i == y) { fl = 1; flag[x] = 1; flag[i] = 1; ++a[i][0]; ++a[x][0]; } } if (!fl) { printf("-1\n"); return 0; } } return 0; }
#include <bits/stdc++.h> using namespace std; int n, a[11000][11000], t = 0; bool flag[11000], fl = 0; bool judge() { for (int i = 1; i <= n; ++i) if (a[i][0] != n) return 0; return 1; } int main() { cin >> n; for (int i = 1; i <= n; ++i) { for (int j = 1; j < n; ++j) cin >> a[i][j]; a[i][0] = 1; } while (1) { if (judge()) { printf("%d\n", t); return 0; } fl = 0; memset(flag, 0, sizeof(flag)); ++t; for (int i = 1; i <= n; ++i) { if (flag[i] || a[i][0] == n) continue; int x = a[i][a[i][0]], y = a[x][a[x][0]]; if (!flag[x] && !flag[i] && i == y) { fl = 1; flag[x] = 1; flag[i] = 1; ++a[i][0]; ++a[x][0]; } } if (!fl) { printf("-1\n"); return 0; } } return 0; }
[ "literal.number.change", "variable_declaration.array_dimensions.change" ]
731,319
731,329
u667714875
cpp
p02925
#include <bits/stdc++.h> using namespace std; #define ll long long #define mod 998244353 #define pb push_back #define pi pair<int, int> #define vi vector<int> #define vpi vector<pi> const int N = 1010; vi v[N * N]; int st[N * N], tim[N * N]; int main() { // memset(d,1,sizeof d) int n, lst, x; cin >> n; for (int i = 1; i <= n; i++) { cin >> lst; for (int j = 2; j < n; j++) { cin >> x; int f = min(i, lst) * N + max(i, lst); int s = min(i, x) * N + max(i, x); lst = x; v[f].pb(s); tim[s] += 1; } } vector<int> ans; for (int i = 1; i <= n; i++) { for (int j = i + 1; j <= n; j++) { if (!tim[i * N + j]) ans.pb(i * N + j); } } int res = 0, cnt = 0; while (ans.size()) { res++; cnt += ans.size(); vi w; for (int z : ans) { for (int y : v[z]) { tim[y]--; if (tim[y] == 0) w.pb(y); } } ans = w; // for(int y: ans) cout<<y<<' ';cout<<"\n"; } if (cnt == n * (n - 1) / 2) printf("%d", res); else cout << cnt; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define mod 998244353 #define pb push_back #define pi pair<int, int> #define vi vector<int> #define vpi vector<pi> const int N = 1010; vi v[N * N]; int st[N * N], tim[N * N]; int main() { // memset(d,1,sizeof d) int n, lst, x; cin >> n; for (int i = 1; i <= n; i++) { cin >> lst; for (int j = 2; j < n; j++) { cin >> x; int f = min(i, lst) * N + max(i, lst); int s = min(i, x) * N + max(i, x); lst = x; v[f].pb(s); tim[s] += 1; } } vector<int> ans; for (int i = 1; i <= n; i++) { for (int j = i + 1; j <= n; j++) { if (!tim[i * N + j]) ans.pb(i * N + j); } } int res = 0, cnt = 0; while (ans.size()) { res++; cnt += ans.size(); vi w; for (int z : ans) { for (int y : v[z]) { tim[y]--; if (tim[y] == 0) w.pb(y); } } ans = w; // for(int y: ans) cout<<y<<' ';cout<<"\n"; } if (cnt == n * (n - 1) / 2) printf("%d", res); else cout << "-1"; return 0; }
[ "io.output.change" ]
731,340
731,341
u105709069
cpp
p02925
#include <bits/stdc++.h> using namespace std; const int maxn = 2e6 + 10; int n, m = 1003; int b[1010]; int deg[maxn]; int ct[1010]; vector<int> a[maxn], all; bool vis[maxn], d[maxn], ok; void topsort(int nod) { vis[nod] = true; d[nod] = true; for (int i : a[nod]) { if (!vis[i]) { topsort(i); } else if (d[i]) { ok = false; } } d[nod] = false; // topo.push_back(nod); } int main() { int x, y; scanf("%d", &n); for (int i = 1; i <= n; i++) { for (int j = 1; j < n; j++) { scanf("%d", &b[j]); x = i, y = b[j]; if (x > y) swap(x, y); b[j] = (n + 1) * x + y; all.push_back(b[j]); } for (int j = 1; j + 1 < n; j++) { a[b[j]].push_back(b[j + 1]); deg[b[j + 1]]++; } } vector<int> cur; for (int i = 1; i < maxn; i++) { if (deg[i] == 0) { cur.push_back(i); } } for (int i : all) if (!vis[i]) { topsort(i); if (!ok) return !printf("-1"); } int ans = 0; while (!cur.empty()) { ans++; vector<int> nxt; for (int i : cur) { for (int j : a[i]) { deg[j]--; if (deg[j] == 0) nxt.push_back(j); } } cur = nxt; } printf("%d\n", ans); } /* Good Luck -Lucina */
#include <bits/stdc++.h> using namespace std; const int maxn = 2e6 + 10; int n, m = 1003; int b[1010]; int deg[maxn]; int ct[1010]; vector<int> a[maxn], all; bool vis[maxn], d[maxn], ok; void topsort(int nod) { vis[nod] = true; d[nod] = true; for (int i : a[nod]) { if (!vis[i]) { topsort(i); } else if (d[i]) { ok = false; } } d[nod] = false; // topo.push_back(nod); } int main() { int x, y; scanf("%d", &n); for (int i = 1; i <= n; i++) { for (int j = 1; j < n; j++) { scanf("%d", &b[j]); x = i, y = b[j]; if (x > y) swap(x, y); b[j] = (n + 1) * x + y; all.push_back(b[j]); } for (int j = 1; j + 1 < n; j++) { a[b[j]].push_back(b[j + 1]); deg[b[j + 1]]++; } } vector<int> cur; for (int i = 1; i < maxn; i++) { if (deg[i] == 0) { cur.push_back(i); } } ok = true; for (int i : all) if (!vis[i]) { topsort(i); if (!ok) return !printf("-1"); } int ans = 0; while (!cur.empty()) { ans++; vector<int> nxt; for (int i : cur) { for (int j : a[i]) { deg[j]--; if (deg[j] == 0) nxt.push_back(j); } } cur = nxt; } printf("%d\n", ans); } /* Good Luck -Lucina */
[ "assignment.add" ]
731,342
731,343
u047398677
cpp
p02925
#define _USE_MATH_DEFINES #include <algorithm> #include <bitset> #include <cassert> #include <climits> #include <cmath> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <vector> using namespace std; #define MOD 1000000007 #define rep(i, m, n) for (int(i) = (int)(m); i < (int)(n); i++) #define REP(i, n) rep(i, 0, n) #define FOR(i, c) \ for (decltype((c).begin()) i = (c).begin(); i != (c).end(); ++i) #define ll long long #define ull unsigned long long #define all(hoge) (hoge).begin(), (hoge).end() typedef pair<ll, ll> P; const long long INF = 1LL << 60; typedef vector<ll> Array; typedef vector<Array> Matrix; string operator*(const string &s, int k) { if (k == 0) return ""; string p = (s + s) * (k / 2); if (k % 2 == 1) p += s; return p; } // priority_queue<ll> max;//大きい順 // priority_queue<ll, Array, greater<ll>> min;//小さい順 /*firstについては昇順 secondについては降順 sort(all(wh), [&](P x, P y) { if (x.first == y.first)return x.second > y.second; return x.first < y.first; }); */ 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; } // substr 文字列取り出し // upper_bound // ある値より大きい一番左のイテレータを返す、lowerは以上(setに対して使うとO(N)なので、setのメンバ関数を使う // stoi struct Edge { //グラフ ll to, cap, rev; Edge(ll _to, ll _cap, ll _rev) { to = _to; cap = _cap; rev = _rev; } }; typedef vector<Edge> Edges; typedef vector<Edges> Graph; void add_edge(Graph &G, ll from, ll to, ll cap, bool revFlag, ll revCap) { //最大フロー求める Ford-fulkerson G[from].push_back(Edge(to, cap, (ll)G[to].size())); if (revFlag) G[to].push_back(Edge( from, revCap, (ll)G[from].size() - 1)); //最小カットの場合逆辺は0にする } ll max_flow_dfs(Graph &G, ll v, ll t, ll f, vector<bool> &used) { if (v == t) return f; used[v] = true; for (int i = 0; i < G[v].size(); ++i) { Edge &e = G[v][i]; if (!used[e.to] && e.cap > 0) { ll d = max_flow_dfs(G, e.to, t, min(f, e.cap), used); if (d > 0) { e.cap -= d; G[e.to][e.rev].cap += d; return d; } } } return 0; } //二分グラフの最大マッチングを求めたりも出来る また二部グラフの最大独立集合は頂点数-最大マッチングのサイズ ll max_flow(Graph &G, ll s, ll t) // O(V(V+E)) { ll flow = 0; for (;;) { vector<bool> used(G.size()); REP(i, used.size()) used[i] = false; ll f = max_flow_dfs(G, s, t, INF, used); if (f == 0) { return flow; } flow += f; } } void BellmanFord(Graph &G, ll s, Array &d, Array &negative) { // O(|E||V|) d.resize(G.size()); negative.resize(G.size()); REP(i, d.size()) d[i] = INF; REP(i, d.size()) negative[i] = false; d[s] = 0; REP(k, G.size() - 1) { REP(i, G.size()) { REP(j, G[i].size()) { if (d[i] != INF && d[G[i][j].to] > d[i] + G[i][j].cap) { d[G[i][j].to] = d[i] + G[i][j].cap; } } } } REP(k, G.size() - 1) { REP(i, G.size()) { REP(j, G[i].size()) { if (d[i] != INF && d[G[i][j].to] > d[i] + G[i][j].cap) { d[G[i][j].to] = d[i] + G[i][j].cap; negative[G[i][j].to] = true; } if (negative[i] == true) negative[G[i][j].to] = true; } } } } void Dijkstra(Graph &G, ll s, Array &d) { // O(|E|log|V|) d.resize(G.size()); REP(i, d.size()) d[i] = INF; d[s] = 0; priority_queue<P, vector<P>, greater<P>> q; q.push(make_pair(0, s)); while (!q.empty()) { P a = q.top(); q.pop(); if (d[a.second] < a.first) continue; REP(i, G[a.second].size()) { Edge e = G[a.second][i]; if (d[e.to] > d[a.second] + e.cap) { d[e.to] = d[a.second] + e.cap; q.push(make_pair(d[e.to], e.to)); } } } } void WarshallFloyd(Graph &G, Matrix &d) { // O(V^3) d.resize(G.size()); REP(i, d.size()) d[i].resize(G.size()); REP(i, d.size()) { REP(j, d[i].size()) { d[i][j] = INF; } } REP(i, G.size()) { REP(j, G[i].size()) { d[i][G[i][j].to] = G[i][j].cap; } } REP(i, G.size()) { REP(j, G.size()) { REP(k, G.size()) { chmin(d[j][k], d[j][i] + d[i][k]); } } } } bool tsort(Graph &graph, vector<int> &order) { //トポロジカルソートO(E+V) int n = graph.size(), k = 0; Array in(n); for (auto &es : graph) for (auto &e : es) in[e.to]++; priority_queue<ll, Array, greater<ll>> que; REP(i, n) if (in[i] == 0) que.push(i); while (que.size()) { int v = que.top(); que.pop(); order.push_back(v); for (auto &e : graph[v]) if (--in[e.to] == 0) que.push(e.to); } if (order.size() != n) return false; else return true; } class lca { public: const int n = 0; const int log2_n = 0; std::vector<std::vector<int>> parent; std::vector<int> depth; lca() {} lca(const Graph &g, int root) : n(g.size()), log2_n(log2(n) + 1), parent(log2_n, std::vector<int>(n)), depth(n) { dfs(g, root, -1, 0); for (int k = 0; k + 1 < log2_n; k++) { for (int v = 0; v < (int)g.size(); v++) { if (parent[k][v] < 0) parent[k + 1][v] = -1; else parent[k + 1][v] = parent[k][parent[k][v]]; } } } void dfs(const Graph &g, int v, int p, int d) { parent[0][v] = p; depth[v] = d; for (auto &e : g[v]) { if (e.to != p) dfs(g, e.to, v, d + 1); } } int get(int u, int v) { if (depth[u] > depth[v]) std::swap(u, v); for (int k = 0; k < log2_n; k++) { if ((depth[v] - depth[u]) >> k & 1) { v = parent[k][v]; } } if (u == v) return u; for (int k = log2_n - 1; k >= 0; k--) { if (parent[k][u] != parent[k][v]) { u = parent[k][u]; v = parent[k][v]; } } return parent[0][u]; } }; class UnionFind { vector<int> data; ll num; public: UnionFind(int size) : data(size, -1), num(size) {} bool unionSet(int x, int y) { // xとyの集合を統合する x = root(x); y = root(y); if (x != y) { if (data[y] < data[x]) swap(x, y); data[x] += data[y]; data[y] = x; } num -= (x != y); return x != y; } bool findSet(int x, int y) { // xとyが同じ集合か返す return root(x) == root(y); } int root(int x) { // xのルートを返す return data[x] < 0 ? x : data[x] = root(data[x]); } int size(int x) { // xの集合のサイズを返す return -data[root(x)]; } int numSet() { //集合の数を返す return num; } }; class SumSegTree { private: int _sum(int a, int b, int k, int l, int r) { if (r <= a || b <= l) return 0; // 交差しない if (a <= l && r <= b) return dat[k]; // a,l,r,bの順で完全に含まれる else { int s1 = _sum(a, b, 2 * k + 1, l, (l + r) / 2); // 左の子 int s2 = _sum(a, b, 2 * k + 2, (l + r) / 2, r); // 右の子 return s1 + s2; } } public: int n, height; vector<int> dat; // 初期化(_nは最大要素数) SumSegTree(int _n) { n = 1; height = 1; while (n < _n) { n *= 2; height++; } dat = vector<int>(2 * n - 1, 0); } // 場所i(0-indexed)にxを足す void add(int i, int x) { i += n - 1; // i番目の葉ノードへ dat[i] += x; while (i > 0) { // 下から上がっていく i = (i - 1) / 2; dat[i] += x; } } // 区間[a,b)の総和。ノードk=[l,r)に着目している。 int sum(int a, int b) { return _sum(a, b, 0, 0, n); } }; class RmqTree { private: ll _find(ll a, ll b, ll k, ll l, ll r) { if (r <= a || b <= l) return INF; // 交差しない if (a <= l && r <= b) return dat[k]; // a,l,r,bの順で完全に含まれる else { ll s1 = _find(a, b, 2 * k + 1, l, (l + r) / 2); // 左の子 ll s2 = _find(a, b, 2 * k + 2, (l + r) / 2, r); // 右の子 return min(s1, s2); } } public: ll n, height; vector<ll> dat; // 初期化(_nは最大要素数) RmqTree(ll _n) { n = 1; height = 1; while (n < _n) { n *= 2; height++; } dat = vector<ll>(2 * n - 1, INF); } // 場所i(0-indexed)をxにする void update(ll i, ll x) { i += n - 1; // i番目の葉ノードへ dat[i] = x; while (i > 0) { // 下から上がっていく i = (i - 1) / 2; dat[i] = min(dat[i * 2 + 1], dat[i * 2 + 2]); } } // 区間[a,b)の最小値。ノードk=[l,r)に着目している。 ll find(ll a, ll b) { return _find(a, b, 0, 0, n); } }; //約数求める //約数 void divisor(ll n, vector<ll> &ret) { for (ll 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()); } vector<ll> lis_fast(const vector<ll> &a) { //最長部分増加列 const ll n = a.size(); vector<ll> A(n, INT_MAX); vector<ll> id(n); for (int i = 0; i < n; ++i) { id[i] = distance(A.begin(), lower_bound(A.begin(), A.end(), a[i])); A[id[i]] = a[i]; } ll m = *max_element(id.begin(), id.end()); vector<ll> b(m + 1); for (int i = n - 1; i >= 0; --i) if (id[i] == m) b[m--] = a[i]; return b; } bool z_algorithm(string &str, vector<int> &z, ll s) { // s&tを渡してtにsが含まれるかを返す const int L = str.size(); z.resize(str.size()); for (int i = 1, left = 0, right = 0; i < L; i++) { if (i > right) { left = right = i; for (; right < L && str[right - left] == str[right]; right++) ; z[i] = right - left; right--; } else { int k = i - left; if (z[k] < right - i + 1) { z[i] = z[k]; } else { left = i; for (; right < L && str[right - left] == str[right]; right++) ; z[i] = right - left; right--; } } if (z[i] == s) return true; } return false; } bool z_algorithm(string &str, vector<int> &z) { // z[i]==|s|のときstr[i]からsが含まれる const int L = str.size(); z.resize(str.size()); for (int i = 1, left = 0, right = 0; i < L; i++) { if (i > right) { left = right = i; for (; right < L && str[right - left] == str[right]; right++) ; z[i] = right - left; right--; } else { int k = i - left; if (z[k] < right - i + 1) { z[i] = z[k]; } else { left = i; for (; right < L && str[right - left] == str[right]; right++) ; z[i] = right - left; right--; } } } return true; } ll ModPow(ll x, ll n) { ll res = 1LL; while (n > 0) { if (n & 1) res = res * x % MOD; x = x * x % MOD; n >>= 1; } return res; } // nCrとか class Combination { public: Array fact; Array inv; ll mod; ll mod_inv(ll x) { ll n = mod - 2LL; ll res = 1LL; while (n > 0) { if (n & 1) res = res * x % mod; x = x * x % mod; n >>= 1; } return res; } ll nCr(ll n, ll r) { return ((fact[n] * inv[r] % mod) * inv[n - r]) % mod; } ll nPr(ll n, ll r) { return (fact[n] * inv[n - r]) % mod; } ll nHr(ll n, ll r) { return nCr(r + n - 1, r); } Combination(ll n, ll _mod) { mod = _mod; fact.resize(n + 1); fact[0] = 1; REP(i, n) { fact[i + 1] = (fact[i] * (i + 1LL)) % mod; } inv.resize(n + 1); REP(i, n + 1) { inv[i] = mod_inv(fact[i]); } } }; ll gcd(ll m, ll n) { if (n == 0) return m; return gcd(n, m % n); } // gcd ll lcm(ll m, ll n) { return m / gcd(m, n) * n; } Matrix mIdentity(ll n) { Matrix A(n, Array(n)); for (int i = 0; i < n; ++i) A[i][i] = 1; return A; } Matrix mMul(const Matrix &A, const Matrix &B) { Matrix C(A.size(), Array(B[0].size())); for (int i = 0; i < C.size(); ++i) for (int j = 0; j < C[i].size(); ++j) for (int k = 0; k < A[i].size(); ++k) (C[i][j] += (A[i][k] % MOD) * (B[k][j] % MOD)) %= MOD; return C; } // O( n^3 log e ) Matrix mPow(const Matrix &A, ll e) { return e == 0 ? mIdentity(A.size()) : e % 2 == 0 ? mPow(mMul(A, A), e / 2) : mMul(A, mPow(A, e - 1)); } template <class T> class RectangleSum { public: vector<vector<T>> sum; T GetSum(int left, int right, int top, int bottom) { //[left, right], [top, bottom] T res = sum[bottom][right]; if (left > 0) res -= sum[bottom][left - 1]; if (top > 0) res -= sum[top - 1][right]; if (left > 0 && top > 0) res += sum[top - 1][left - 1]; return res; } RectangleSum(const vector<vector<T>> &s, int h, int w) { sum.resize(h); for (int i = 0; i < h; i++) sum[i].resize(w, 0); for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { sum[y][x] = s[y][x]; if (y > 0) sum[y][x] += sum[y - 1][x]; if (x > 0) sum[y][x] += sum[y][x - 1]; if (y > 0 && x > 0) sum[y][x] -= sum[y - 1][x - 1]; } } } }; int main() { ios::sync_with_stdio(false); cin.tie(0); ll n; cin >> n; Matrix mat(n); REP(i, n) { mat[i].resize(n - 1); REP(j, n - 1) { cin >> mat[i][j]; mat[i][j]--; } } Array num(n, 0); ll ans = 0; set<ll> can; REP(i, n) can.insert(i); while (true) { Array next; set<ll> used; for (auto itr : can) { ll me = itr; if (num[me] >= n - 1) continue; ll to = mat[me][num[me]]; if (used.count(me) == 1) continue; if (used.count(to) == 1) continue; ll tome = mat[to][num[to]]; if (me == tome) { num[me]++; num[to]++; if (num[me] < n - 1) next.push_back(me); if (num[to] < n - 1) next.push_back(to); } used.insert(me); used.insert(to); } can.clear(); REP(i, next.size()) can.insert(next[i]); ans++; if (next.size() == 0) break; } ll flag = 1; REP(i, n) { if (num[i] != n - 1) flag = 0; } if (flag == 1) cout << ans << endl; else cout << -1 << endl; return 0; }
#define _USE_MATH_DEFINES #include <algorithm> #include <bitset> #include <cassert> #include <climits> #include <cmath> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <vector> using namespace std; #define MOD 1000000007 #define rep(i, m, n) for (int(i) = (int)(m); i < (int)(n); i++) #define REP(i, n) rep(i, 0, n) #define FOR(i, c) \ for (decltype((c).begin()) i = (c).begin(); i != (c).end(); ++i) #define ll long long #define ull unsigned long long #define all(hoge) (hoge).begin(), (hoge).end() typedef pair<ll, ll> P; const long long INF = 1LL << 60; typedef vector<ll> Array; typedef vector<Array> Matrix; string operator*(const string &s, int k) { if (k == 0) return ""; string p = (s + s) * (k / 2); if (k % 2 == 1) p += s; return p; } // priority_queue<ll> max;//大きい順 // priority_queue<ll, Array, greater<ll>> min;//小さい順 /*firstについては昇順 secondについては降順 sort(all(wh), [&](P x, P y) { if (x.first == y.first)return x.second > y.second; return x.first < y.first; }); */ 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; } // substr 文字列取り出し // upper_bound // ある値より大きい一番左のイテレータを返す、lowerは以上(setに対して使うとO(N)なので、setのメンバ関数を使う // stoi struct Edge { //グラフ ll to, cap, rev; Edge(ll _to, ll _cap, ll _rev) { to = _to; cap = _cap; rev = _rev; } }; typedef vector<Edge> Edges; typedef vector<Edges> Graph; void add_edge(Graph &G, ll from, ll to, ll cap, bool revFlag, ll revCap) { //最大フロー求める Ford-fulkerson G[from].push_back(Edge(to, cap, (ll)G[to].size())); if (revFlag) G[to].push_back(Edge( from, revCap, (ll)G[from].size() - 1)); //最小カットの場合逆辺は0にする } ll max_flow_dfs(Graph &G, ll v, ll t, ll f, vector<bool> &used) { if (v == t) return f; used[v] = true; for (int i = 0; i < G[v].size(); ++i) { Edge &e = G[v][i]; if (!used[e.to] && e.cap > 0) { ll d = max_flow_dfs(G, e.to, t, min(f, e.cap), used); if (d > 0) { e.cap -= d; G[e.to][e.rev].cap += d; return d; } } } return 0; } //二分グラフの最大マッチングを求めたりも出来る また二部グラフの最大独立集合は頂点数-最大マッチングのサイズ ll max_flow(Graph &G, ll s, ll t) // O(V(V+E)) { ll flow = 0; for (;;) { vector<bool> used(G.size()); REP(i, used.size()) used[i] = false; ll f = max_flow_dfs(G, s, t, INF, used); if (f == 0) { return flow; } flow += f; } } void BellmanFord(Graph &G, ll s, Array &d, Array &negative) { // O(|E||V|) d.resize(G.size()); negative.resize(G.size()); REP(i, d.size()) d[i] = INF; REP(i, d.size()) negative[i] = false; d[s] = 0; REP(k, G.size() - 1) { REP(i, G.size()) { REP(j, G[i].size()) { if (d[i] != INF && d[G[i][j].to] > d[i] + G[i][j].cap) { d[G[i][j].to] = d[i] + G[i][j].cap; } } } } REP(k, G.size() - 1) { REP(i, G.size()) { REP(j, G[i].size()) { if (d[i] != INF && d[G[i][j].to] > d[i] + G[i][j].cap) { d[G[i][j].to] = d[i] + G[i][j].cap; negative[G[i][j].to] = true; } if (negative[i] == true) negative[G[i][j].to] = true; } } } } void Dijkstra(Graph &G, ll s, Array &d) { // O(|E|log|V|) d.resize(G.size()); REP(i, d.size()) d[i] = INF; d[s] = 0; priority_queue<P, vector<P>, greater<P>> q; q.push(make_pair(0, s)); while (!q.empty()) { P a = q.top(); q.pop(); if (d[a.second] < a.first) continue; REP(i, G[a.second].size()) { Edge e = G[a.second][i]; if (d[e.to] > d[a.second] + e.cap) { d[e.to] = d[a.second] + e.cap; q.push(make_pair(d[e.to], e.to)); } } } } void WarshallFloyd(Graph &G, Matrix &d) { // O(V^3) d.resize(G.size()); REP(i, d.size()) d[i].resize(G.size()); REP(i, d.size()) { REP(j, d[i].size()) { d[i][j] = INF; } } REP(i, G.size()) { REP(j, G[i].size()) { d[i][G[i][j].to] = G[i][j].cap; } } REP(i, G.size()) { REP(j, G.size()) { REP(k, G.size()) { chmin(d[j][k], d[j][i] + d[i][k]); } } } } bool tsort(Graph &graph, vector<int> &order) { //トポロジカルソートO(E+V) int n = graph.size(), k = 0; Array in(n); for (auto &es : graph) for (auto &e : es) in[e.to]++; priority_queue<ll, Array, greater<ll>> que; REP(i, n) if (in[i] == 0) que.push(i); while (que.size()) { int v = que.top(); que.pop(); order.push_back(v); for (auto &e : graph[v]) if (--in[e.to] == 0) que.push(e.to); } if (order.size() != n) return false; else return true; } class lca { public: const int n = 0; const int log2_n = 0; std::vector<std::vector<int>> parent; std::vector<int> depth; lca() {} lca(const Graph &g, int root) : n(g.size()), log2_n(log2(n) + 1), parent(log2_n, std::vector<int>(n)), depth(n) { dfs(g, root, -1, 0); for (int k = 0; k + 1 < log2_n; k++) { for (int v = 0; v < (int)g.size(); v++) { if (parent[k][v] < 0) parent[k + 1][v] = -1; else parent[k + 1][v] = parent[k][parent[k][v]]; } } } void dfs(const Graph &g, int v, int p, int d) { parent[0][v] = p; depth[v] = d; for (auto &e : g[v]) { if (e.to != p) dfs(g, e.to, v, d + 1); } } int get(int u, int v) { if (depth[u] > depth[v]) std::swap(u, v); for (int k = 0; k < log2_n; k++) { if ((depth[v] - depth[u]) >> k & 1) { v = parent[k][v]; } } if (u == v) return u; for (int k = log2_n - 1; k >= 0; k--) { if (parent[k][u] != parent[k][v]) { u = parent[k][u]; v = parent[k][v]; } } return parent[0][u]; } }; class UnionFind { vector<int> data; ll num; public: UnionFind(int size) : data(size, -1), num(size) {} bool unionSet(int x, int y) { // xとyの集合を統合する x = root(x); y = root(y); if (x != y) { if (data[y] < data[x]) swap(x, y); data[x] += data[y]; data[y] = x; } num -= (x != y); return x != y; } bool findSet(int x, int y) { // xとyが同じ集合か返す return root(x) == root(y); } int root(int x) { // xのルートを返す return data[x] < 0 ? x : data[x] = root(data[x]); } int size(int x) { // xの集合のサイズを返す return -data[root(x)]; } int numSet() { //集合の数を返す return num; } }; class SumSegTree { private: int _sum(int a, int b, int k, int l, int r) { if (r <= a || b <= l) return 0; // 交差しない if (a <= l && r <= b) return dat[k]; // a,l,r,bの順で完全に含まれる else { int s1 = _sum(a, b, 2 * k + 1, l, (l + r) / 2); // 左の子 int s2 = _sum(a, b, 2 * k + 2, (l + r) / 2, r); // 右の子 return s1 + s2; } } public: int n, height; vector<int> dat; // 初期化(_nは最大要素数) SumSegTree(int _n) { n = 1; height = 1; while (n < _n) { n *= 2; height++; } dat = vector<int>(2 * n - 1, 0); } // 場所i(0-indexed)にxを足す void add(int i, int x) { i += n - 1; // i番目の葉ノードへ dat[i] += x; while (i > 0) { // 下から上がっていく i = (i - 1) / 2; dat[i] += x; } } // 区間[a,b)の総和。ノードk=[l,r)に着目している。 int sum(int a, int b) { return _sum(a, b, 0, 0, n); } }; class RmqTree { private: ll _find(ll a, ll b, ll k, ll l, ll r) { if (r <= a || b <= l) return INF; // 交差しない if (a <= l && r <= b) return dat[k]; // a,l,r,bの順で完全に含まれる else { ll s1 = _find(a, b, 2 * k + 1, l, (l + r) / 2); // 左の子 ll s2 = _find(a, b, 2 * k + 2, (l + r) / 2, r); // 右の子 return min(s1, s2); } } public: ll n, height; vector<ll> dat; // 初期化(_nは最大要素数) RmqTree(ll _n) { n = 1; height = 1; while (n < _n) { n *= 2; height++; } dat = vector<ll>(2 * n - 1, INF); } // 場所i(0-indexed)をxにする void update(ll i, ll x) { i += n - 1; // i番目の葉ノードへ dat[i] = x; while (i > 0) { // 下から上がっていく i = (i - 1) / 2; dat[i] = min(dat[i * 2 + 1], dat[i * 2 + 2]); } } // 区間[a,b)の最小値。ノードk=[l,r)に着目している。 ll find(ll a, ll b) { return _find(a, b, 0, 0, n); } }; //約数求める //約数 void divisor(ll n, vector<ll> &ret) { for (ll 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()); } vector<ll> lis_fast(const vector<ll> &a) { //最長部分増加列 const ll n = a.size(); vector<ll> A(n, INT_MAX); vector<ll> id(n); for (int i = 0; i < n; ++i) { id[i] = distance(A.begin(), lower_bound(A.begin(), A.end(), a[i])); A[id[i]] = a[i]; } ll m = *max_element(id.begin(), id.end()); vector<ll> b(m + 1); for (int i = n - 1; i >= 0; --i) if (id[i] == m) b[m--] = a[i]; return b; } bool z_algorithm(string &str, vector<int> &z, ll s) { // s&tを渡してtにsが含まれるかを返す const int L = str.size(); z.resize(str.size()); for (int i = 1, left = 0, right = 0; i < L; i++) { if (i > right) { left = right = i; for (; right < L && str[right - left] == str[right]; right++) ; z[i] = right - left; right--; } else { int k = i - left; if (z[k] < right - i + 1) { z[i] = z[k]; } else { left = i; for (; right < L && str[right - left] == str[right]; right++) ; z[i] = right - left; right--; } } if (z[i] == s) return true; } return false; } bool z_algorithm(string &str, vector<int> &z) { // z[i]==|s|のときstr[i]からsが含まれる const int L = str.size(); z.resize(str.size()); for (int i = 1, left = 0, right = 0; i < L; i++) { if (i > right) { left = right = i; for (; right < L && str[right - left] == str[right]; right++) ; z[i] = right - left; right--; } else { int k = i - left; if (z[k] < right - i + 1) { z[i] = z[k]; } else { left = i; for (; right < L && str[right - left] == str[right]; right++) ; z[i] = right - left; right--; } } } return true; } ll ModPow(ll x, ll n) { ll res = 1LL; while (n > 0) { if (n & 1) res = res * x % MOD; x = x * x % MOD; n >>= 1; } return res; } // nCrとか class Combination { public: Array fact; Array inv; ll mod; ll mod_inv(ll x) { ll n = mod - 2LL; ll res = 1LL; while (n > 0) { if (n & 1) res = res * x % mod; x = x * x % mod; n >>= 1; } return res; } ll nCr(ll n, ll r) { return ((fact[n] * inv[r] % mod) * inv[n - r]) % mod; } ll nPr(ll n, ll r) { return (fact[n] * inv[n - r]) % mod; } ll nHr(ll n, ll r) { return nCr(r + n - 1, r); } Combination(ll n, ll _mod) { mod = _mod; fact.resize(n + 1); fact[0] = 1; REP(i, n) { fact[i + 1] = (fact[i] * (i + 1LL)) % mod; } inv.resize(n + 1); REP(i, n + 1) { inv[i] = mod_inv(fact[i]); } } }; ll gcd(ll m, ll n) { if (n == 0) return m; return gcd(n, m % n); } // gcd ll lcm(ll m, ll n) { return m / gcd(m, n) * n; } Matrix mIdentity(ll n) { Matrix A(n, Array(n)); for (int i = 0; i < n; ++i) A[i][i] = 1; return A; } Matrix mMul(const Matrix &A, const Matrix &B) { Matrix C(A.size(), Array(B[0].size())); for (int i = 0; i < C.size(); ++i) for (int j = 0; j < C[i].size(); ++j) for (int k = 0; k < A[i].size(); ++k) (C[i][j] += (A[i][k] % MOD) * (B[k][j] % MOD)) %= MOD; return C; } // O( n^3 log e ) Matrix mPow(const Matrix &A, ll e) { return e == 0 ? mIdentity(A.size()) : e % 2 == 0 ? mPow(mMul(A, A), e / 2) : mMul(A, mPow(A, e - 1)); } template <class T> class RectangleSum { public: vector<vector<T>> sum; T GetSum(int left, int right, int top, int bottom) { //[left, right], [top, bottom] T res = sum[bottom][right]; if (left > 0) res -= sum[bottom][left - 1]; if (top > 0) res -= sum[top - 1][right]; if (left > 0 && top > 0) res += sum[top - 1][left - 1]; return res; } RectangleSum(const vector<vector<T>> &s, int h, int w) { sum.resize(h); for (int i = 0; i < h; i++) sum[i].resize(w, 0); for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { sum[y][x] = s[y][x]; if (y > 0) sum[y][x] += sum[y - 1][x]; if (x > 0) sum[y][x] += sum[y][x - 1]; if (y > 0 && x > 0) sum[y][x] -= sum[y - 1][x - 1]; } } } }; int main() { ios::sync_with_stdio(false); cin.tie(0); ll n; cin >> n; Matrix mat(n); REP(i, n) { mat[i].resize(n - 1); REP(j, n - 1) { cin >> mat[i][j]; mat[i][j]--; } } Array num(n, 0); ll ans = 0; set<ll> can; REP(i, n) can.insert(i); while (true) { Array next; set<ll> used; for (auto itr : can) { ll me = itr; if (num[me] >= n - 1) continue; ll to = mat[me][num[me]]; if (used.count(me) == 1) continue; if (used.count(to) == 1) continue; ll tome = mat[to][num[to]]; if (me == tome) { num[me]++; num[to]++; if (num[me] < n - 1) next.push_back(me); if (num[to] < n - 1) next.push_back(to); used.insert(me); used.insert(to); } } can.clear(); REP(i, next.size()) can.insert(next[i]); ans++; if (next.size() == 0) break; } ll flag = 1; REP(i, n) { if (num[i] != n - 1) flag = 0; } if (flag == 1) cout << ans << endl; else cout << -1 << endl; return 0; }
[]
731,354
731,355
u051493691
cpp
p02928
#include <bits/stdc++.h> using namespace std; int main() { int N, K; cin >> N >> K; vector<int> A(N); for (int i = 0; i < N; i++) { cin >> A[i]; } long long int INF = 1000000007; long long int acnt = 0; for (int i = 0; i < N - 1; i++) { for (int j = i + 1; j < N; j++) { if (A[i] > A[j]) acnt++; } } sort(A.begin(), A.end(), greater<int>()); vector<int> B(N); long long int acnt3 = 0; for (int i = 0; i < N - 1; i++) { for (int j = 0; j < N; j++) { if (A[i] > A[j]) B[i]++; } } for (int i = 0; i < N; i++) { acnt3 += (B[i] * ((K % INF * (K - 1) % INF / 2) % INF)) % INF; } long long int ans = (acnt * K) % INF + acnt3; ans %= INF; cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int N, K; cin >> N >> K; vector<int> A(N); for (int i = 0; i < N; i++) { cin >> A[i]; } long long int INF = 1000000007; long long int acnt = 0; for (int i = 0; i < N - 1; i++) { for (int j = i + 1; j < N; j++) { if (A[i] > A[j]) acnt++; } } sort(A.begin(), A.end(), greater<int>()); vector<int> B(N); long long int acnt3 = 0; for (int i = 0; i < N - 1; i++) { for (int j = 0; j < N; j++) { if (A[i] > A[j]) B[i]++; } } for (int i = 0; i < N; i++) { acnt3 += (B[i] * (((K % INF) * ((K - 1) % INF) / 2) % INF)) % INF; } long long int ans = (acnt * K) % INF + acnt3; ans %= INF; cout << ans << endl; }
[]
731,360
731,361
u665871498
cpp
p02928
#include <algorithm> #include <bitset> #include <climits> #include <cmath> // abs() for float, and fabs() #include <cstdlib> // abs() for integer #include <functional> #include <iomanip> #include <iostream> #include <map> // pair #include <math.h> #include <numeric> #include <queue> #include <stack> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <string> #include <utility> #include <vector> typedef std::stack<int> IntStack; typedef std::stack<char> charStack; //#define PRIME_NUMBER 1000000007 using namespace std; using ll = long long; typedef pair<ll, ll> pll; bool comp(const pll &a, const pll &b) { return a.first < b.first; } //********************************************************* // 最大公約数(Greatest Common Divisor)を返す。 // 引数に0がある場合は0を返す。 //********************************************************* ll gcd(ll a, ll b) { ll tmp, r; if (a < b) { tmp = a; a = b; b = tmp; } /* ユークリッドの互除法 */ r = a % b; while (r != 0) { a = b; b = r; r = a % b; } return b; //// 引数に0がある場合は0を返す // if ((0 == m) || (0 == n)) // return 0; //// ユークリッドの方法 // while (m != n) //{ // if (m > n) m = m - n; // else n = n - m; //} // return m; } // gcd int factorial(int k); //階乗 ll nCr(ll n, ll r); //コンビネーション int permutation(int n, int r); // nPk パーミュテーション int main() { ll a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, h = 0, ans = 0; ll x[100004] = {}; ll y[100004] = {}; ll z[100004] = {{}}; vector<tuple<ll, ll>> vec; string s; string t; // IntStack yStack; // charStack Stack; // vector<pair<int, int> > pairs(a); // cout << LLONG_MAX<< endl; ll k = 0, n = 0; ll A[10004] = {}; ll PRIME_NUMBER = 1000000007; cin >> n; cin >> k; for (int i = 0; i < n; i++) { cin >> A[i]; } for (int i = 0; i < n; i++) { a = 0; for (int l = 0; l < i; l++) { if (A[i] > A[l]) { a++; } } ans += ((a) * ((k * (k - 1) / 2)) % PRIME_NUMBER) % PRIME_NUMBER; ans %= PRIME_NUMBER; a = 0; for (int l = i + 1; l < n; l++) { if (A[i] > A[l]) { a++; } } // ans += (k)*(a*(a + 1) / 2); ans += ((a) * ((k * (k + 1) / 2)) % PRIME_NUMBER) % PRIME_NUMBER; ans %= PRIME_NUMBER; } // cout << std::setprecision(20) << answer << endl; cout << ans << endl; // cout << "Yes" << endl; ////std::cout << std::fixed; // cout << std::setprecision(20) << << endl; // cout << d+1 << endl; // cout << "" << endl; return 0; } // sort(x, x + a, std::greater<ll>()); // char型の文字数字は、-'0'で数値に変換できる // accumulate(x, x + a, 0);//int型までの配列の合計 // memcpy(x, visited, sizeof(ll)*n); // void kansuu(ll num, ll visited[10]) {} // kansuu(1, zz); // cout << setprecision(15) << v << endl; // cout << char(z - 'a'); // ll(log10(i) + 1) //10進数の桁数を取得 // // int temp; // for (int i = 0; i < n - 1; i++) { // for (int j = n - 1; j > i; j--) { // if (w[j - 1] < w[j]) { /* 前の要素の方が大きかったら */ // temp = w[j]; /* 交換する */ // w[j] = w[j - 1]; // w[j - 1] = temp; // } // } //} // //最小公倍数 // ll x = a * b; // ll tmp; ///* 自然数 a > b を確認・入替 */ // if (a<b) { // tmp = a; // a = b; // b = tmp; //} ///* ユークリッドの互除法 */ // ll r = a % b; // while (r != 0) { // a = b; // b = r; // r = a % b; //} // a = x / b;//答え /*vector<pair<ll, ll> > hoges(a); for (int i = 0; i < a; i++) { cin >> x[i]; cin >> y[i]; hoges[i] = make_pair(x[i], y[i]); } sort(hoges.begin(),hoges.end(),comp); for (int i = 0; i < a; i++) { if (hoges[i].second>=b) { ans += hoges[i].first*b; break; } else { ans += hoges[i].first*hoges[i].second; b -= hoges[i].second; } }*/ int permutation(int n, int r) { int n_sum, r_sum; int i; r = n - r; n_sum = factorial(n); r_sum = factorial(r); return n_sum / r_sum; } ll nCr(ll n, ll r) { ll ans = 1; for (ll i = n; i > n - r; --i) { ans = ans * i; } for (ll i = 1; i < r + 1; ++i) { ans = ans / i; } return ans; } int factorial(int k) { int sum = 1; for (int i = 1; i <= k; ++i) { sum *= i; } return sum; }
#include <algorithm> #include <bitset> #include <climits> #include <cmath> // abs() for float, and fabs() #include <cstdlib> // abs() for integer #include <functional> #include <iomanip> #include <iostream> #include <map> // pair #include <math.h> #include <numeric> #include <queue> #include <stack> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <string> #include <utility> #include <vector> typedef std::stack<int> IntStack; typedef std::stack<char> charStack; //#define PRIME_NUMBER 1000000007 using namespace std; using ll = long long; typedef pair<ll, ll> pll; bool comp(const pll &a, const pll &b) { return a.first < b.first; } //********************************************************* // 最大公約数(Greatest Common Divisor)を返す。 // 引数に0がある場合は0を返す。 //********************************************************* ll gcd(ll a, ll b) { ll tmp, r; if (a < b) { tmp = a; a = b; b = tmp; } /* ユークリッドの互除法 */ r = a % b; while (r != 0) { a = b; b = r; r = a % b; } return b; //// 引数に0がある場合は0を返す // if ((0 == m) || (0 == n)) // return 0; //// ユークリッドの方法 // while (m != n) //{ // if (m > n) m = m - n; // else n = n - m; //} // return m; } // gcd int factorial(int k); //階乗 ll nCr(ll n, ll r); //コンビネーション int permutation(int n, int r); // nPk パーミュテーション int main() { ll a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, h = 0, ans = 0; ll x[100004] = {}; ll y[100004] = {}; ll z[100004] = {{}}; vector<tuple<ll, ll>> vec; string s; string t; // IntStack yStack; // charStack Stack; // vector<pair<int, int> > pairs(a); // cout << LLONG_MAX<< endl; ll k = 0, n = 0; ll A[10004] = {}; ll PRIME_NUMBER = 1000000007; cin >> n; cin >> k; for (int i = 0; i < n; i++) { cin >> A[i]; } for (int i = 0; i < n; i++) { a = 0; for (int l = 0; l < i; l++) { if (A[i] > A[l]) { a++; } } ans += (a) * (((k * (k - 1) / 2)) % PRIME_NUMBER) % PRIME_NUMBER; ans %= PRIME_NUMBER; a = 0; for (int l = i + 1; l < n; l++) { if (A[i] > A[l]) { a++; } } // ans += (k)*(a*(a + 1) / 2); ans += (a) * (((k * (k + 1) / 2)) % PRIME_NUMBER) % PRIME_NUMBER; ans %= PRIME_NUMBER; } // cout << std::setprecision(20) << answer << endl; cout << ans << endl; // cout << "Yes" << endl; ////std::cout << std::fixed; // cout << std::setprecision(20) << << endl; // cout << d+1 << endl; // cout << "" << endl; return 0; } // sort(x, x + a, std::greater<ll>()); // char型の文字数字は、-'0'で数値に変換できる // accumulate(x, x + a, 0);//int型までの配列の合計 // memcpy(x, visited, sizeof(ll)*n); // void kansuu(ll num, ll visited[10]) {} // kansuu(1, zz); // cout << setprecision(15) << v << endl; // cout << char(z - 'a'); // ll(log10(i) + 1) //10進数の桁数を取得 // // int temp; // for (int i = 0; i < n - 1; i++) { // for (int j = n - 1; j > i; j--) { // if (w[j - 1] < w[j]) { /* 前の要素の方が大きかったら */ // temp = w[j]; /* 交換する */ // w[j] = w[j - 1]; // w[j - 1] = temp; // } // } //} // //最小公倍数 // ll x = a * b; // ll tmp; ///* 自然数 a > b を確認・入替 */ // if (a<b) { // tmp = a; // a = b; // b = tmp; //} ///* ユークリッドの互除法 */ // ll r = a % b; // while (r != 0) { // a = b; // b = r; // r = a % b; //} // a = x / b;//答え /*vector<pair<ll, ll> > hoges(a); for (int i = 0; i < a; i++) { cin >> x[i]; cin >> y[i]; hoges[i] = make_pair(x[i], y[i]); } sort(hoges.begin(),hoges.end(),comp); for (int i = 0; i < a; i++) { if (hoges[i].second>=b) { ans += hoges[i].first*b; break; } else { ans += hoges[i].first*hoges[i].second; b -= hoges[i].second; } }*/ int permutation(int n, int r) { int n_sum, r_sum; int i; r = n - r; n_sum = factorial(n); r_sum = factorial(r); return n_sum / r_sum; } ll nCr(ll n, ll r) { ll ans = 1; for (ll i = n; i > n - r; --i) { ans = ans * i; } for (ll i = 1; i < r + 1; ++i) { ans = ans / i; } return ans; } int factorial(int k) { int sum = 1; for (int i = 1; i <= k; ++i) { sum *= i; } return sum; }
[]
731,362
731,363
u142996493
cpp
p02928
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ll N, K; cin >> N >> K; ll d = 1000000000 + 7; vector<ll> A(N); for (ll i = 0; i < N; i++) { cin >> A[i]; } ll ans1 = 0; for (ll i = 0; i < N; i++) { for (ll j = i + 1; j < N; j++) { if (A[i] > A[j]) ans1++; } } ans1 = ((ans1 % d) * (K % d)) % d; vector<pair<ll, ll>> p; for (ll i = 0; i < N; i++) { ll c = 0; for (ll j = 0; j < N; j++) { if (A[i] > A[j]) c++; } p.push_back(make_pair(A[i], c)); } ll ans2 = ((K % d) * (K - 1) % d / 2) % d; ll sum = 0; for (ll i = 0; i < N; i++) { sum = (sum + p[i].second) % d; } ans2 = ((sum % d) * (ans2 % d)) % d; cout << (ans1 + ans2) % d << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ll N, K; cin >> N >> K; ll d = 1000000000 + 7; vector<ll> A(N); for (ll i = 0; i < N; i++) { cin >> A[i]; } ll ans1 = 0; for (ll i = 0; i < N; i++) { for (ll j = i + 1; j < N; j++) { if (A[i] > A[j]) ans1++; } } ans1 = ((ans1 % d) * (K % d)) % d; vector<pair<ll, ll>> p; for (ll i = 0; i < N; i++) { ll c = 0; for (ll j = 0; j < N; j++) { if (A[i] > A[j]) c++; } p.push_back(make_pair(A[i], c)); } ll ans2 = ((K % d) * ((K - 1) % d) / 2) % d; ll sum = 0; for (ll i = 0; i < N; i++) { sum = (sum + p[i].second) % d; } ans2 = ((sum % d) * (ans2 % d)) % d; cout << (ans1 + ans2) % d << endl; }
[]
731,364
731,365
u037276799
cpp
p02928
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int N; cin >> N; long long a[2100], c; long long K; cin >> K; long long ans = 0, cnt = 0; for (int i = 0; i < N; i++) { cin >> a[i]; } for (int i = 0; i < N; i++) { long long z = 0; for (int j = 0; j < i; j++) { if (a[j] > a[i]) { z++; } } c = 0; for (int j = i + 1; j < N; j++) { if (a[j] > a[i]) { c++; } } cnt += c + z; ans -= c; } ans = ans * K % 1000000007; K = (K + 1) * K / 2 % 1000000007; ans += cnt * K; ans %= 1000000007; if (ans < 0) { ans -= ans; } cout << ans; }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int N; cin >> N; long long a[2100], c; long long K; cin >> K; long long ans = 0, cnt = 0; for (int i = 0; i < N; i++) { cin >> a[i]; } for (int i = 0; i < N; i++) { long long z = 0; for (int j = 0; j < i; j++) { if (a[j] > a[i]) { z++; } } c = 0; for (int j = i + 1; j < N; j++) { if (a[j] > a[i]) { c++; } } cnt += c + z; ans -= c; } ans = ans * K % 1000000007; K = (K + 1) * K / 2 % 1000000007; ans += cnt * K; ans %= 1000000007; if (ans < 0) ans = 1000000007 + ans; cout << ans; }
[ "assignment.value.change", "assignment.change" ]
731,366
731,367
u126833093
cpp
p02928
#include <stdio.h> int main() { int n, i, j; long long int k, d = 0, f = 0; scanf("%d %lld", &n, &k); int a[n]; for (i = 0; i < n; i++) { scanf("%d", &a[i]); } for (i = 0; i < n - 1; i++) { for (j = i + 1; j < n; j++) { if (a[i] > a[j]) { d++; } if (a[i] < a[j]) { f++; } } } d = (d * ((k * k + k) / 2) + f * ((k * k - k) / 2)) % 1000000007; printf("%lld", d); }
#include <stdio.h> int main() { int n, i, j; long long int k, d = 0, f = 0; scanf("%d %lld", &n, &k); int a[n]; for (i = 0; i < n; i++) { scanf("%d", &a[i]); } for (i = 0; i < n - 1; i++) { for (j = i + 1; j < n; j++) { if (a[i] > a[j]) { d++; } if (a[i] < a[j]) { f++; } } } d = (d * ((k * k + k) / 2 % 1000000007) + f * ((k * k - k) / 2 % 1000000007)) % 1000000007; printf("%lld", d); }
[ "assignment.change" ]
731,383
731,384
u222643545
cpp
p02928
#include <iostream> #include <vector> using namespace std; int main() { const long long int M = 1000000007; long long int N, K; cin >> N >> K; vector<long long int> A(N); for (long long int i = 0; i < N; ++i) { cin >> A[i]; } vector<long long int> cnt(2001, 0); for (long long int i = 1; i < N; ++i) { for (long long int j = 0; j < i; ++j) { if (A[i] > A[j]) { ++cnt[A[i]]; } } } long long int ans = 0; long long int k; if (K & 1) { k = (K + 1) / 2; k *= K; k %= M; } else { k = K / 2; k *= K + 1; k %= M; } for (long long int i = 0; i < N; ++i) { long long int x = 0; for (long long int j = i + 1; j < N; ++j) { if (A[i] > A[j]) { ++x; x %= M; } } x *= k; x %= M; ans += x; ans %= M; x = cnt[A[i]]; x *= ((K * (K - 1)) / 2) % M; x %= M; // x *= k; // x %= M; // long long int a = K*cnt[A[i]]; // a %= M; // x -= a; // if(x <= 0){ // x += M; // } // x %= M; ans += x; ans %= M; } cout << ans << endl; }
#include <iostream> #include <vector> using namespace std; int main() { const long long int M = 1000000007; long long int N, K; cin >> N >> K; vector<long long int> A(N); for (long long int i = 0; i < N; ++i) { cin >> A[i]; } vector<long long int> cnt(2001, 0); for (long long int i = 1; i < N; ++i) { for (long long int j = 0; j < i; ++j) { if (A[i] > A[j]) { ++cnt[i]; } } } long long int ans = 0; long long int k; if (K & 1) { k = (K + 1) / 2; k *= K; k %= M; } else { k = K / 2; k *= K + 1; k %= M; } for (long long int i = 0; i < N; ++i) { long long int x = 0; for (long long int j = i + 1; j < N; ++j) { if (A[i] > A[j]) { ++x; x %= M; } } x *= k; x %= M; ans += x; ans %= M; x = cnt[i]; x *= ((K * (K - 1)) / 2) % M; x %= M; // x *= k; // x %= M; // long long int a = K*cnt[A[i]]; // a %= M; // x -= a; // if(x <= 0){ // x += M; // } // x %= M; ans += x; ans %= M; } cout << ans << endl; }
[]
731,385
731,386
u982123883
cpp
p02928
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll n, k; ll a[2005]; ll ansm, kk, kkk; ll const BAD = 1e9 + 7; ll add(ll x, ll y) { ll a = (x % BAD + y % BAD) % BAD; return a; } ll multiply(ll x, ll y) { ll b = (x % BAD * y % BAD) % BAD; return b; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> k; kkk = multiply(k, k + 1) / 2; kk = multiply(k - 1, k) / 2; for (ll i = 0; i < n; i++) { cin >> a[i]; } for (ll i = 0; i < n; i++) { for (ll j = 0; j < n; j++) { if (a[j] < a[i]) { if (j > i) { // coming after ansm = add(ansm, kkk); } else { ansm = add(ansm, kk); } } } } // if (a[n-1] < a[0]){ // ansm = add(ansm, kk); // } ansm = add(ansm, 0); cout << ansm; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll n, k; ll a[2005]; ll ansm, kk, kkk; ll const BAD = 1e9 + 7; ll add(ll x, ll y) { ll a = (x % BAD + y % BAD) % BAD; return a; } ll multiply(ll x, ll y) { ll b = (x * y); return b; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> k; kkk = multiply(k, k + 1) / 2; kk = multiply(k - 1, k) / 2; for (ll i = 0; i < n; i++) { cin >> a[i]; } for (ll i = 0; i < n; i++) { for (ll j = 0; j < n; j++) { if (a[j] < a[i]) { if (j > i) { // coming after ansm = add(ansm, kkk); } else { ansm = add(ansm, kk); } } } } // if (a[n-1] < a[0]){ // ansm = add(ansm, kk); // } ansm = add(ansm, 0); cout << ansm; }
[ "expression.operation.binary.remove" ]
731,387
731,388
u928313240
cpp
p02928
#include <bits/stdc++.h> using namespace std; template <class T> using V = vector<T>; template <class S, class T> using P = pair<S, T>; using ll = long long; using ull = unsigned long long; using vll = V<ll>; using vvll = V<vll>; using vvvll = V<vvll>; using pl = P<ll, ll>; using vpl = V<pl>; using vvpl = V<vpl>; using vs = V<string>; using qll = queue<ll>; using qpl = queue<pl>; using mapll = map<ll, ll>; using setll = set<ll>; using pqll = priority_queue<ll>; #define int ll #define fi first #define se second #define mp make_pair #define pb push_back #define pob pop_back() #define pf push_front #define pof pop_front() #define sz size() #define bgn begin() #define en end() #define emp empty() #define fr front() #define bk back() #define res resize #define tp top() #define p_q priority_queue #define inv inverse() #define FOR(i, a, b) for (ll i = (a); i <= (ll)(b); i++) #define rFOR(i, a, b) for (ll i = (b); i >= (ll)(a); i--) #define REP(i, a) FOR((i), 0, (ll)(a)-1) #define REP0(i, a) FOR((i), 0, (ll)(a)) #define REP1(i, a) FOR((i), 1, (ll)(a)) #define rREP(i, a) rFOR((i), 0, (ll)(a)-1) #define rREP0(i, a) rFOR((i), 0, (ll)(a)) #define rREP1(i, a) rFOR((i), 1, (ll)(a)) #define IOTA(a, n) iota((a).bgn, (a).en, (n)) #define SORT(a) sort((a).bgn, (a).en) #define rSORT(a) sort((a).rbegin(), (a).rend()) #define UNIQUE(a) (a).erase(unique((a).bgn, (a).en), (a).en) #define BINS(a, b) binary_search((a).bgn, (a).en, (b)) #define LOWB(a, b) (lower_bound((a).bgn, (a).en, (b)) - (a).bgn) #define UPB(a, b) (upper_bound((a).bgn, (a).en, (b)) - (a).bgn) #define CNT(a, b) count((a).bgn, (a).en, b) #define SUM(a) accumulate((a).bgn, (a).en, 0) #define REV(a) reverse((a).bgn, (a).en) #define yn(a) cout << ((a) ? "yes" : "no") << "\n"; #define Yn(a) cout << ((a) ? "Yes" : "No") << "\n"; #define YN(a) cout << ((a) ? "YES" : "NO") << "\n"; #define imp(a) cout << ((a) ? "possible" : "impossible") << "\n"; #define Imp(a) cout << ((a) ? "Possible" : "Impossible") << "\n"; #define IMP(a) cout << ((a) ? "POSSIBLE" : "IMPOSSIBLE") << "\n"; #define dbg(a) cerr << (#a) << ": " << (a) << "\n"; #define DigN2(a) ((llabs(a) == 0) ? (1) : ((ll)(log2(double(llabs(a)))) + 1)) #define DigN10(a) ((llabs(a) == 0) ? (1) : ((ll)(log10(double(llabs(a)))) + 1)) #define Dig2(a, b) (((a) >> (b)) & 1) #define Dig10(a, b) (ll)(((a) / ((ll)(pow(10.0, (double)(b))))) % 10) #define Pow2(a) ((ll)(1) << (a)) #define Pow10(a) ((ll)(pow(10.0, double(a)))) #define powll(a, b) (ll)(pow((double)(a), (double)(b))) #define li(...) \ ll __VA_ARGS__; \ Input(__VA_ARGS__); #define si(...) \ string __VA_ARGS__; \ Input(__VA_ARGS__); #define vli(size, ...) \ vll __VA_ARGS__; \ vInput(size, __VA_ARGS__); #define vsi(size, ...) \ vs __VA_ARGS__; \ vInput(size, __VA_ARGS__); const ll MOD = 1e9 + 7; // const ll MOD = 998244353; // const ll MOD = 924844033; // const ll MOD = 9007199254740881; const ll INF = 1LL << 60; // 1.15e18 const double PI = acos(-1.0); const string alp = "abcdefghijklmnopqrstuvwxyz"; const string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; void Input() {} template <class Var, class... Args> void Input(Var &var, Args &...args) { cin >> var; Input(args...); } void vInit(ll size) {} template <class T, class... Args> void vInit(ll size, V<T> &v, Args &...args) { v.res(size); vInit(size, args...); } void vInputNum(ll num) {} template <class T, class... Args> void vInputNum(ll num, V<T> &v, Args &...args) { cin >> v[num]; vInputNum(num, args...); } void vInput(ll size) {} template <class... Args> void vInput(ll size, Args &...args) { vInit(size, args...); REP(i, size) vInputNum(i, args...); } template <class S, class T> ostream &operator<<(ostream &out, const P<S, T> &p) { return out << "[" << p.fi << ", " << p.se << "]"; } template <class T> ostream &operator<<(ostream &out, V<T> &v) { if (v.emp) return out << "{}"; else { auto itr = v.bgn; out << "{" << *itr; itr++; while (itr != v.en) { out << ", " << *itr; itr++; } out << "}"; return out; } } template <class S, class T> ostream &operator<<(ostream &out, const map<S, T> &m) { if (m.emp) return out << "<[]>"; else { auto itr = m.bgn; out << "< [" << (itr->fi) << ": " << (itr->se); itr++; while (itr != m.en) { out << "], [" << (itr->fi) << ": " << (itr->se); itr++; } out << "] >"; return out; } } template <class T> ostream &operator<<(ostream &out, const set<T> &s) { if (s.emp) return out << "<>"; else { auto itr = s.bgn; out << "<" << *itr; itr++; while (itr != s.en) { out << ", " << *itr; itr++; } out << ">"; return out; } } ll gcd(ll a, ll b) { if (a < b) { a ^= b; b ^= a; a ^= b; } return b ? gcd(b, a % b) : a; } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } struct UFT { public: ll tsize; ll mode; vll par; vll rank; UFT() {} UFT(const UFT &uft) {} UFT(ll tsizeget, ll modeget = 0) { tsize = tsizeget; mode = modeget; par.assign(tsize, -1); if (!mode) rank.res(tsize, 0); } ll root(ll x) { return par[x] < 0 ? x : par[x] = root(par[x]); } bool isRoot(ll x) { return x == root(x); } bool same(ll x, ll y) { return root(x) == root(y); } void merge(ll x, ll y) { x = root(x); y = root(y); if (x == y) return; if (mode) { par[x] += par[y]; par[y] = x; } else { if (rank[x] < rank[y]) { par[y] += par[x]; par[x] = y; } else { par[x] += par[y]; par[y] = x; if (rank[x] == rank[y]) rank[x]++; } } } ll size(ll x) { return -par[root(x)]; } }; ll isP(ll n) { if (n <= 1) return 0; FOR(i, 2, (ll)sqrt(n) + 1) { if (n % i == 0) return 0; } return 1; } vvll CombMemo(3000, vll(3000, -1)); ll Comb(ll n, ll k) { if ((n < 0) || (k < 0)) return 0; if (CombMemo[n][k] == -1) { if (n < k) CombMemo[n][k] = 0; else { if (n == 0) CombMemo[n][k] = 1; else if (k == 0) CombMemo[n][k] = 1; else if (n == k) CombMemo[n][k] = 1; else CombMemo[n][k] = Comb(n - 1, k - 1) + Comb(n - 1, k); } } return CombMemo[n][k]; } void Solve(); signed main() { cin.tie(0); ios::sync_with_stdio(false); cout << setprecision(20) << fixed; Solve(); } void Solve() { li(n, k); vli(n, a); ll c; vpl p; REP(i, n) { p.pb(mp(a[i], i)); } SORT(p); vll aaa(n); ll now = p[0].fi, mimi = 0; REP(i, n) { if (now < p[i].fi) { mimi = i; } now = p[i].fi; aaa[i] = mimi; } ll r = 0; REP(i, n) { FOR(j, 0, i - 1) { if (a[i] >= a[j]) r += MOD * 2 - k; r %= MOD; } } ll mi; REP(i, n) { mi = k * (k + 1) / 2; r += (aaa[i] * mi) % MOD; r %= MOD; } cout << r; }
#include <bits/stdc++.h> using namespace std; template <class T> using V = vector<T>; template <class S, class T> using P = pair<S, T>; using ll = long long; using ull = unsigned long long; using vll = V<ll>; using vvll = V<vll>; using vvvll = V<vvll>; using pl = P<ll, ll>; using vpl = V<pl>; using vvpl = V<vpl>; using vs = V<string>; using qll = queue<ll>; using qpl = queue<pl>; using mapll = map<ll, ll>; using setll = set<ll>; using pqll = priority_queue<ll>; #define int ll #define fi first #define se second #define mp make_pair #define pb push_back #define pob pop_back() #define pf push_front #define pof pop_front() #define sz size() #define bgn begin() #define en end() #define emp empty() #define fr front() #define bk back() #define res resize #define tp top() #define p_q priority_queue #define inv inverse() #define FOR(i, a, b) for (ll i = (a); i <= (ll)(b); i++) #define rFOR(i, a, b) for (ll i = (b); i >= (ll)(a); i--) #define REP(i, a) FOR((i), 0, (ll)(a)-1) #define REP0(i, a) FOR((i), 0, (ll)(a)) #define REP1(i, a) FOR((i), 1, (ll)(a)) #define rREP(i, a) rFOR((i), 0, (ll)(a)-1) #define rREP0(i, a) rFOR((i), 0, (ll)(a)) #define rREP1(i, a) rFOR((i), 1, (ll)(a)) #define IOTA(a, n) iota((a).bgn, (a).en, (n)) #define SORT(a) sort((a).bgn, (a).en) #define rSORT(a) sort((a).rbegin(), (a).rend()) #define UNIQUE(a) (a).erase(unique((a).bgn, (a).en), (a).en) #define BINS(a, b) binary_search((a).bgn, (a).en, (b)) #define LOWB(a, b) (lower_bound((a).bgn, (a).en, (b)) - (a).bgn) #define UPB(a, b) (upper_bound((a).bgn, (a).en, (b)) - (a).bgn) #define CNT(a, b) count((a).bgn, (a).en, b) #define SUM(a) accumulate((a).bgn, (a).en, 0) #define REV(a) reverse((a).bgn, (a).en) #define yn(a) cout << ((a) ? "yes" : "no") << "\n"; #define Yn(a) cout << ((a) ? "Yes" : "No") << "\n"; #define YN(a) cout << ((a) ? "YES" : "NO") << "\n"; #define imp(a) cout << ((a) ? "possible" : "impossible") << "\n"; #define Imp(a) cout << ((a) ? "Possible" : "Impossible") << "\n"; #define IMP(a) cout << ((a) ? "POSSIBLE" : "IMPOSSIBLE") << "\n"; #define dbg(a) cerr << (#a) << ": " << (a) << "\n"; #define DigN2(a) ((llabs(a) == 0) ? (1) : ((ll)(log2(double(llabs(a)))) + 1)) #define DigN10(a) ((llabs(a) == 0) ? (1) : ((ll)(log10(double(llabs(a)))) + 1)) #define Dig2(a, b) (((a) >> (b)) & 1) #define Dig10(a, b) (ll)(((a) / ((ll)(pow(10.0, (double)(b))))) % 10) #define Pow2(a) ((ll)(1) << (a)) #define Pow10(a) ((ll)(pow(10.0, double(a)))) #define powll(a, b) (ll)(pow((double)(a), (double)(b))) #define li(...) \ ll __VA_ARGS__; \ Input(__VA_ARGS__); #define si(...) \ string __VA_ARGS__; \ Input(__VA_ARGS__); #define vli(size, ...) \ vll __VA_ARGS__; \ vInput(size, __VA_ARGS__); #define vsi(size, ...) \ vs __VA_ARGS__; \ vInput(size, __VA_ARGS__); const ll MOD = 1e9 + 7; // const ll MOD = 998244353; // const ll MOD = 924844033; // const ll MOD = 9007199254740881; const ll INF = 1LL << 60; // 1.15e18 const double PI = acos(-1.0); const string alp = "abcdefghijklmnopqrstuvwxyz"; const string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; void Input() {} template <class Var, class... Args> void Input(Var &var, Args &...args) { cin >> var; Input(args...); } void vInit(ll size) {} template <class T, class... Args> void vInit(ll size, V<T> &v, Args &...args) { v.res(size); vInit(size, args...); } void vInputNum(ll num) {} template <class T, class... Args> void vInputNum(ll num, V<T> &v, Args &...args) { cin >> v[num]; vInputNum(num, args...); } void vInput(ll size) {} template <class... Args> void vInput(ll size, Args &...args) { vInit(size, args...); REP(i, size) vInputNum(i, args...); } template <class S, class T> ostream &operator<<(ostream &out, const P<S, T> &p) { return out << "[" << p.fi << ", " << p.se << "]"; } template <class T> ostream &operator<<(ostream &out, V<T> &v) { if (v.emp) return out << "{}"; else { auto itr = v.bgn; out << "{" << *itr; itr++; while (itr != v.en) { out << ", " << *itr; itr++; } out << "}"; return out; } } template <class S, class T> ostream &operator<<(ostream &out, const map<S, T> &m) { if (m.emp) return out << "<[]>"; else { auto itr = m.bgn; out << "< [" << (itr->fi) << ": " << (itr->se); itr++; while (itr != m.en) { out << "], [" << (itr->fi) << ": " << (itr->se); itr++; } out << "] >"; return out; } } template <class T> ostream &operator<<(ostream &out, const set<T> &s) { if (s.emp) return out << "<>"; else { auto itr = s.bgn; out << "<" << *itr; itr++; while (itr != s.en) { out << ", " << *itr; itr++; } out << ">"; return out; } } ll gcd(ll a, ll b) { if (a < b) { a ^= b; b ^= a; a ^= b; } return b ? gcd(b, a % b) : a; } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } struct UFT { public: ll tsize; ll mode; vll par; vll rank; UFT() {} UFT(const UFT &uft) {} UFT(ll tsizeget, ll modeget = 0) { tsize = tsizeget; mode = modeget; par.assign(tsize, -1); if (!mode) rank.res(tsize, 0); } ll root(ll x) { return par[x] < 0 ? x : par[x] = root(par[x]); } bool isRoot(ll x) { return x == root(x); } bool same(ll x, ll y) { return root(x) == root(y); } void merge(ll x, ll y) { x = root(x); y = root(y); if (x == y) return; if (mode) { par[x] += par[y]; par[y] = x; } else { if (rank[x] < rank[y]) { par[y] += par[x]; par[x] = y; } else { par[x] += par[y]; par[y] = x; if (rank[x] == rank[y]) rank[x]++; } } } ll size(ll x) { return -par[root(x)]; } }; ll isP(ll n) { if (n <= 1) return 0; FOR(i, 2, (ll)sqrt(n) + 1) { if (n % i == 0) return 0; } return 1; } vvll CombMemo(3000, vll(3000, -1)); ll Comb(ll n, ll k) { if ((n < 0) || (k < 0)) return 0; if (CombMemo[n][k] == -1) { if (n < k) CombMemo[n][k] = 0; else { if (n == 0) CombMemo[n][k] = 1; else if (k == 0) CombMemo[n][k] = 1; else if (n == k) CombMemo[n][k] = 1; else CombMemo[n][k] = Comb(n - 1, k - 1) + Comb(n - 1, k); } } return CombMemo[n][k]; } void Solve(); signed main() { cin.tie(0); ios::sync_with_stdio(false); cout << setprecision(20) << fixed; Solve(); } void Solve() { li(n, k); vli(n, a); ll c; vpl p; REP(i, n) { p.pb(mp(a[i], i)); } SORT(p); vll aaa(n); ll now = p[0].fi, mimi = 0; REP(i, n) { if (now < p[i].fi) { mimi = i; } now = p[i].fi; aaa[i] = mimi; } ll r = 0; REP(i, n) { FOR(j, 0, i - 1) { if (a[i] > a[j]) r += MOD * 2 - k; r %= MOD; } } ll mi; REP(i, n) { mi = (k * (k + 1) / 2) % MOD; r += (aaa[i] * mi) % MOD; r %= MOD; } cout << r; }
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change", "assignment.change" ]
731,393
731,394
u172929647
cpp
p02928
#include <bits/stdc++.h> using namespace std; template <class T> using V = vector<T>; template <class S, class T> using P = pair<S, T>; using ll = long long; using ull = unsigned long long; using vll = V<ll>; using vvll = V<vll>; using vvvll = V<vvll>; using pl = P<ll, ll>; using vpl = V<pl>; using vvpl = V<vpl>; using vs = V<string>; using qll = queue<ll>; using qpl = queue<pl>; using mapll = map<ll, ll>; using setll = set<ll>; using pqll = priority_queue<ll>; #define int ll #define fi first #define se second #define mp make_pair #define pb push_back #define pob pop_back() #define pf push_front #define pof pop_front() #define sz size() #define bgn begin() #define en end() #define emp empty() #define fr front() #define bk back() #define res resize #define tp top() #define p_q priority_queue #define inv inverse() #define FOR(i, a, b) for (ll i = (a); i <= (ll)(b); i++) #define rFOR(i, a, b) for (ll i = (b); i >= (ll)(a); i--) #define REP(i, a) FOR((i), 0, (ll)(a)-1) #define REP0(i, a) FOR((i), 0, (ll)(a)) #define REP1(i, a) FOR((i), 1, (ll)(a)) #define rREP(i, a) rFOR((i), 0, (ll)(a)-1) #define rREP0(i, a) rFOR((i), 0, (ll)(a)) #define rREP1(i, a) rFOR((i), 1, (ll)(a)) #define IOTA(a, n) iota((a).bgn, (a).en, (n)) #define SORT(a) sort((a).bgn, (a).en) #define rSORT(a) sort((a).rbegin(), (a).rend()) #define UNIQUE(a) (a).erase(unique((a).bgn, (a).en), (a).en) #define BINS(a, b) binary_search((a).bgn, (a).en, (b)) #define LOWB(a, b) (lower_bound((a).bgn, (a).en, (b)) - (a).bgn) #define UPB(a, b) (upper_bound((a).bgn, (a).en, (b)) - (a).bgn) #define CNT(a, b) count((a).bgn, (a).en, b) #define SUM(a) accumulate((a).bgn, (a).en, 0) #define REV(a) reverse((a).bgn, (a).en) #define yn(a) cout << ((a) ? "yes" : "no") << "\n"; #define Yn(a) cout << ((a) ? "Yes" : "No") << "\n"; #define YN(a) cout << ((a) ? "YES" : "NO") << "\n"; #define imp(a) cout << ((a) ? "possible" : "impossible") << "\n"; #define Imp(a) cout << ((a) ? "Possible" : "Impossible") << "\n"; #define IMP(a) cout << ((a) ? "POSSIBLE" : "IMPOSSIBLE") << "\n"; #define dbg(a) cerr << (#a) << ": " << (a) << "\n"; #define DigN2(a) ((llabs(a) == 0) ? (1) : ((ll)(log2(double(llabs(a)))) + 1)) #define DigN10(a) ((llabs(a) == 0) ? (1) : ((ll)(log10(double(llabs(a)))) + 1)) #define Dig2(a, b) (((a) >> (b)) & 1) #define Dig10(a, b) (ll)(((a) / ((ll)(pow(10.0, (double)(b))))) % 10) #define Pow2(a) ((ll)(1) << (a)) #define Pow10(a) ((ll)(pow(10.0, double(a)))) #define powll(a, b) (ll)(pow((double)(a), (double)(b))) #define li(...) \ ll __VA_ARGS__; \ Input(__VA_ARGS__); #define si(...) \ string __VA_ARGS__; \ Input(__VA_ARGS__); #define vli(size, ...) \ vll __VA_ARGS__; \ vInput(size, __VA_ARGS__); #define vsi(size, ...) \ vs __VA_ARGS__; \ vInput(size, __VA_ARGS__); const ll MOD = 1e9 + 7; // const ll MOD = 998244353; // const ll MOD = 924844033; // const ll MOD = 9007199254740881; const ll INF = 1LL << 60; // 1.15e18 const double PI = acos(-1.0); const string alp = "abcdefghijklmnopqrstuvwxyz"; const string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; void Input() {} template <class Var, class... Args> void Input(Var &var, Args &...args) { cin >> var; Input(args...); } void vInit(ll size) {} template <class T, class... Args> void vInit(ll size, V<T> &v, Args &...args) { v.res(size); vInit(size, args...); } void vInputNum(ll num) {} template <class T, class... Args> void vInputNum(ll num, V<T> &v, Args &...args) { cin >> v[num]; vInputNum(num, args...); } void vInput(ll size) {} template <class... Args> void vInput(ll size, Args &...args) { vInit(size, args...); REP(i, size) vInputNum(i, args...); } template <class S, class T> ostream &operator<<(ostream &out, const P<S, T> &p) { return out << "[" << p.fi << ", " << p.se << "]"; } template <class T> ostream &operator<<(ostream &out, V<T> &v) { if (v.emp) return out << "{}"; else { auto itr = v.bgn; out << "{" << *itr; itr++; while (itr != v.en) { out << ", " << *itr; itr++; } out << "}"; return out; } } template <class S, class T> ostream &operator<<(ostream &out, const map<S, T> &m) { if (m.emp) return out << "<[]>"; else { auto itr = m.bgn; out << "< [" << (itr->fi) << ": " << (itr->se); itr++; while (itr != m.en) { out << "], [" << (itr->fi) << ": " << (itr->se); itr++; } out << "] >"; return out; } } template <class T> ostream &operator<<(ostream &out, const set<T> &s) { if (s.emp) return out << "<>"; else { auto itr = s.bgn; out << "<" << *itr; itr++; while (itr != s.en) { out << ", " << *itr; itr++; } out << ">"; return out; } } ll gcd(ll a, ll b) { if (a < b) { a ^= b; b ^= a; a ^= b; } return b ? gcd(b, a % b) : a; } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } struct UFT { public: ll tsize; ll mode; vll par; vll rank; UFT() {} UFT(const UFT &uft) {} UFT(ll tsizeget, ll modeget = 0) { tsize = tsizeget; mode = modeget; par.assign(tsize, -1); if (!mode) rank.res(tsize, 0); } ll root(ll x) { return par[x] < 0 ? x : par[x] = root(par[x]); } bool isRoot(ll x) { return x == root(x); } bool same(ll x, ll y) { return root(x) == root(y); } void merge(ll x, ll y) { x = root(x); y = root(y); if (x == y) return; if (mode) { par[x] += par[y]; par[y] = x; } else { if (rank[x] < rank[y]) { par[y] += par[x]; par[x] = y; } else { par[x] += par[y]; par[y] = x; if (rank[x] == rank[y]) rank[x]++; } } } ll size(ll x) { return -par[root(x)]; } }; ll isP(ll n) { if (n <= 1) return 0; FOR(i, 2, (ll)sqrt(n) + 1) { if (n % i == 0) return 0; } return 1; } vvll CombMemo(3000, vll(3000, -1)); ll Comb(ll n, ll k) { if ((n < 0) || (k < 0)) return 0; if (CombMemo[n][k] == -1) { if (n < k) CombMemo[n][k] = 0; else { if (n == 0) CombMemo[n][k] = 1; else if (k == 0) CombMemo[n][k] = 1; else if (n == k) CombMemo[n][k] = 1; else CombMemo[n][k] = Comb(n - 1, k - 1) + Comb(n - 1, k); } } return CombMemo[n][k]; } void Solve(); signed main() { cin.tie(0); ios::sync_with_stdio(false); cout << setprecision(20) << fixed; Solve(); } void Solve() { li(n, k); vli(n, a); ll c; vpl p; REP(i, n) { p.pb(mp(a[i], i)); } SORT(p); vll aaa(n); ll now = p[0].fi, mimi = 0; REP(i, n) { if (now < p[i].fi) { mimi = i; } now = p[i].fi; aaa[i] = mimi; } ll r = 0; REP(i, n) { FOR(j, 0, i - 1) { if (a[i] > a[j]) r += MOD * 2 - k; r %= MOD; } } ll mi; REP(i, n) { mi = k * (k + 1) / 2; r += (aaa[i] * mi) % MOD; r %= MOD; } cout << r; }
#include <bits/stdc++.h> using namespace std; template <class T> using V = vector<T>; template <class S, class T> using P = pair<S, T>; using ll = long long; using ull = unsigned long long; using vll = V<ll>; using vvll = V<vll>; using vvvll = V<vvll>; using pl = P<ll, ll>; using vpl = V<pl>; using vvpl = V<vpl>; using vs = V<string>; using qll = queue<ll>; using qpl = queue<pl>; using mapll = map<ll, ll>; using setll = set<ll>; using pqll = priority_queue<ll>; #define int ll #define fi first #define se second #define mp make_pair #define pb push_back #define pob pop_back() #define pf push_front #define pof pop_front() #define sz size() #define bgn begin() #define en end() #define emp empty() #define fr front() #define bk back() #define res resize #define tp top() #define p_q priority_queue #define inv inverse() #define FOR(i, a, b) for (ll i = (a); i <= (ll)(b); i++) #define rFOR(i, a, b) for (ll i = (b); i >= (ll)(a); i--) #define REP(i, a) FOR((i), 0, (ll)(a)-1) #define REP0(i, a) FOR((i), 0, (ll)(a)) #define REP1(i, a) FOR((i), 1, (ll)(a)) #define rREP(i, a) rFOR((i), 0, (ll)(a)-1) #define rREP0(i, a) rFOR((i), 0, (ll)(a)) #define rREP1(i, a) rFOR((i), 1, (ll)(a)) #define IOTA(a, n) iota((a).bgn, (a).en, (n)) #define SORT(a) sort((a).bgn, (a).en) #define rSORT(a) sort((a).rbegin(), (a).rend()) #define UNIQUE(a) (a).erase(unique((a).bgn, (a).en), (a).en) #define BINS(a, b) binary_search((a).bgn, (a).en, (b)) #define LOWB(a, b) (lower_bound((a).bgn, (a).en, (b)) - (a).bgn) #define UPB(a, b) (upper_bound((a).bgn, (a).en, (b)) - (a).bgn) #define CNT(a, b) count((a).bgn, (a).en, b) #define SUM(a) accumulate((a).bgn, (a).en, 0) #define REV(a) reverse((a).bgn, (a).en) #define yn(a) cout << ((a) ? "yes" : "no") << "\n"; #define Yn(a) cout << ((a) ? "Yes" : "No") << "\n"; #define YN(a) cout << ((a) ? "YES" : "NO") << "\n"; #define imp(a) cout << ((a) ? "possible" : "impossible") << "\n"; #define Imp(a) cout << ((a) ? "Possible" : "Impossible") << "\n"; #define IMP(a) cout << ((a) ? "POSSIBLE" : "IMPOSSIBLE") << "\n"; #define dbg(a) cerr << (#a) << ": " << (a) << "\n"; #define DigN2(a) ((llabs(a) == 0) ? (1) : ((ll)(log2(double(llabs(a)))) + 1)) #define DigN10(a) ((llabs(a) == 0) ? (1) : ((ll)(log10(double(llabs(a)))) + 1)) #define Dig2(a, b) (((a) >> (b)) & 1) #define Dig10(a, b) (ll)(((a) / ((ll)(pow(10.0, (double)(b))))) % 10) #define Pow2(a) ((ll)(1) << (a)) #define Pow10(a) ((ll)(pow(10.0, double(a)))) #define powll(a, b) (ll)(pow((double)(a), (double)(b))) #define li(...) \ ll __VA_ARGS__; \ Input(__VA_ARGS__); #define si(...) \ string __VA_ARGS__; \ Input(__VA_ARGS__); #define vli(size, ...) \ vll __VA_ARGS__; \ vInput(size, __VA_ARGS__); #define vsi(size, ...) \ vs __VA_ARGS__; \ vInput(size, __VA_ARGS__); const ll MOD = 1e9 + 7; // const ll MOD = 998244353; // const ll MOD = 924844033; // const ll MOD = 9007199254740881; const ll INF = 1LL << 60; // 1.15e18 const double PI = acos(-1.0); const string alp = "abcdefghijklmnopqrstuvwxyz"; const string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; void Input() {} template <class Var, class... Args> void Input(Var &var, Args &...args) { cin >> var; Input(args...); } void vInit(ll size) {} template <class T, class... Args> void vInit(ll size, V<T> &v, Args &...args) { v.res(size); vInit(size, args...); } void vInputNum(ll num) {} template <class T, class... Args> void vInputNum(ll num, V<T> &v, Args &...args) { cin >> v[num]; vInputNum(num, args...); } void vInput(ll size) {} template <class... Args> void vInput(ll size, Args &...args) { vInit(size, args...); REP(i, size) vInputNum(i, args...); } template <class S, class T> ostream &operator<<(ostream &out, const P<S, T> &p) { return out << "[" << p.fi << ", " << p.se << "]"; } template <class T> ostream &operator<<(ostream &out, V<T> &v) { if (v.emp) return out << "{}"; else { auto itr = v.bgn; out << "{" << *itr; itr++; while (itr != v.en) { out << ", " << *itr; itr++; } out << "}"; return out; } } template <class S, class T> ostream &operator<<(ostream &out, const map<S, T> &m) { if (m.emp) return out << "<[]>"; else { auto itr = m.bgn; out << "< [" << (itr->fi) << ": " << (itr->se); itr++; while (itr != m.en) { out << "], [" << (itr->fi) << ": " << (itr->se); itr++; } out << "] >"; return out; } } template <class T> ostream &operator<<(ostream &out, const set<T> &s) { if (s.emp) return out << "<>"; else { auto itr = s.bgn; out << "<" << *itr; itr++; while (itr != s.en) { out << ", " << *itr; itr++; } out << ">"; return out; } } ll gcd(ll a, ll b) { if (a < b) { a ^= b; b ^= a; a ^= b; } return b ? gcd(b, a % b) : a; } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } struct UFT { public: ll tsize; ll mode; vll par; vll rank; UFT() {} UFT(const UFT &uft) {} UFT(ll tsizeget, ll modeget = 0) { tsize = tsizeget; mode = modeget; par.assign(tsize, -1); if (!mode) rank.res(tsize, 0); } ll root(ll x) { return par[x] < 0 ? x : par[x] = root(par[x]); } bool isRoot(ll x) { return x == root(x); } bool same(ll x, ll y) { return root(x) == root(y); } void merge(ll x, ll y) { x = root(x); y = root(y); if (x == y) return; if (mode) { par[x] += par[y]; par[y] = x; } else { if (rank[x] < rank[y]) { par[y] += par[x]; par[x] = y; } else { par[x] += par[y]; par[y] = x; if (rank[x] == rank[y]) rank[x]++; } } } ll size(ll x) { return -par[root(x)]; } }; ll isP(ll n) { if (n <= 1) return 0; FOR(i, 2, (ll)sqrt(n) + 1) { if (n % i == 0) return 0; } return 1; } vvll CombMemo(3000, vll(3000, -1)); ll Comb(ll n, ll k) { if ((n < 0) || (k < 0)) return 0; if (CombMemo[n][k] == -1) { if (n < k) CombMemo[n][k] = 0; else { if (n == 0) CombMemo[n][k] = 1; else if (k == 0) CombMemo[n][k] = 1; else if (n == k) CombMemo[n][k] = 1; else CombMemo[n][k] = Comb(n - 1, k - 1) + Comb(n - 1, k); } } return CombMemo[n][k]; } void Solve(); signed main() { cin.tie(0); ios::sync_with_stdio(false); cout << setprecision(20) << fixed; Solve(); } void Solve() { li(n, k); vli(n, a); ll c; vpl p; REP(i, n) { p.pb(mp(a[i], i)); } SORT(p); vll aaa(n); ll now = p[0].fi, mimi = 0; REP(i, n) { if (now < p[i].fi) { mimi = i; } now = p[i].fi; aaa[i] = mimi; } ll r = 0; REP(i, n) { FOR(j, 0, i - 1) { if (a[i] > a[j]) r += MOD * 2 - k; r %= MOD; } } ll mi; REP(i, n) { mi = (k * (k + 1) / 2) % MOD; r += (aaa[i] * mi) % MOD; r %= MOD; } cout << r; }
[ "assignment.change" ]
731,395
731,394
u172929647
cpp
p02928
#include <algorithm> #include <bitset> #include <cassert> #include <cctype> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdio.h> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; typedef long long ll; const double EPS = 1e-9; typedef vector<int> vint; typedef vector<vector<int>> v2int; typedef vector<ll> vll; typedef vector<vector<ll>> v2ll; typedef list<int> liint; typedef pair<int, int> pint; const int INF = int(2e9); const ll LINF = ll(2e9) * ll(2e9); #define rep(i, n) REP(i, 0, n) #define ALL(v) v.begin(), v.end() #define MSG(a) cout << #a << " " << a << endl; #define REP(i, x, n) for (int i = x; i < n; i++) template <class T, class C> void chmax(T &a, C b) { a > b ?: a = b; } template <class T, class C> void chmin(T &a, C b) { a < b ?: a = b; } int main() { ll N, K; cin >> N >> K; vint A(N); rep(i, N) cin >> A[i]; ll ans = 0; ll p = 1000000007; rep(i, N) { REP(j, i + 1, N) { if (A[i] > A[j]) { ans++; ans %= p; } } } ans *= ll(K); ans %= p; ll s = ((K - 1) * K) / 2; sort(A.begin(), A.end()); int num = 1; REP(i, 1, N) { if (A[i] > A[i - 1]) num = i + 1; ans += (ll(num - 1) * ((ll(K) * ll(K - 1)) / 2) % p) % p; ans %= p; } cout << ans << endl; return 0; }
#include <algorithm> #include <bitset> #include <cassert> #include <cctype> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdio.h> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; typedef long long ll; const double EPS = 1e-9; typedef vector<int> vint; typedef vector<vector<int>> v2int; typedef vector<ll> vll; typedef vector<vector<ll>> v2ll; typedef list<int> liint; typedef pair<int, int> pint; const int INF = int(2e9); const ll LINF = ll(2e9) * ll(2e9); #define rep(i, n) REP(i, 0, n) #define ALL(v) v.begin(), v.end() #define MSG(a) cout << #a << " " << a << endl; #define REP(i, x, n) for (int i = x; i < n; i++) template <class T, class C> void chmax(T &a, C b) { a > b ?: a = b; } template <class T, class C> void chmin(T &a, C b) { a < b ?: a = b; } int main() { ll N, K; cin >> N >> K; vint A(N); rep(i, N) cin >> A[i]; ll ans = 0; ll p = 1000000007; rep(i, N) { REP(j, i + 1, N) { if (A[i] > A[j]) { ans++; ans %= p; } } } ans *= ll(K); ans %= p; ll s = ((K - 1) * K) / 2; sort(A.begin(), A.end()); int num = 1; REP(i, 1, N) { if (A[i] > A[i - 1]) num = i + 1; ans += (ll(num - 1) * (((ll(K) * ll(K - 1)) - s) % p)) % p; ans %= p; } cout << ans << endl; return 0; }
[]
731,401
731,402
u391331433
cpp
p02928
#include <algorithm> #include <bitset> #include <cassert> #include <cctype> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdio.h> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; typedef long long ll; const double EPS = 1e-9; typedef vector<int> vint; typedef vector<vector<int>> v2int; typedef vector<ll> vll; typedef vector<vector<ll>> v2ll; typedef list<int> liint; typedef pair<int, int> pint; const int INF = int(2e9); const ll LINF = ll(2e9) * ll(2e9); #define rep(i, n) REP(i, 0, n) #define ALL(v) v.begin(), v.end() #define MSG(a) cout << #a << " " << a << endl; #define REP(i, x, n) for (int i = x; i < n; i++) template <class T, class C> void chmax(T &a, C b) { a > b ?: a = b; } template <class T, class C> void chmin(T &a, C b) { a < b ?: a = b; } int main() { int N, K; cin >> N >> K; vint A(N); rep(i, N) cin >> A[i]; ll ans = 0; ll p = 1000000007; rep(i, N) { REP(j, i + 1, N) { if (A[i] > A[j]) { ans++; ans %= p; } } } ans *= ll(K); ans %= p; ll s = ((K - 1) * K) / 2; sort(A.begin(), A.end()); int num = 1; REP(i, 1, N) { if (A[i] > A[i - 1]) num = i + 1; ans += (ll(num - 1) * ((ll(K) * ll(K - 1)) / 2) % p) % p; ans %= p; } cout << ans << endl; return 0; }
#include <algorithm> #include <bitset> #include <cassert> #include <cctype> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdio.h> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; typedef long long ll; const double EPS = 1e-9; typedef vector<int> vint; typedef vector<vector<int>> v2int; typedef vector<ll> vll; typedef vector<vector<ll>> v2ll; typedef list<int> liint; typedef pair<int, int> pint; const int INF = int(2e9); const ll LINF = ll(2e9) * ll(2e9); #define rep(i, n) REP(i, 0, n) #define ALL(v) v.begin(), v.end() #define MSG(a) cout << #a << " " << a << endl; #define REP(i, x, n) for (int i = x; i < n; i++) template <class T, class C> void chmax(T &a, C b) { a > b ?: a = b; } template <class T, class C> void chmin(T &a, C b) { a < b ?: a = b; } int main() { ll N, K; cin >> N >> K; vint A(N); rep(i, N) cin >> A[i]; ll ans = 0; ll p = 1000000007; rep(i, N) { REP(j, i + 1, N) { if (A[i] > A[j]) { ans++; ans %= p; } } } ans *= ll(K); ans %= p; ll s = ((K - 1) * K) / 2; sort(A.begin(), A.end()); int num = 1; REP(i, 1, N) { if (A[i] > A[i - 1]) num = i + 1; ans += (ll(num - 1) * (((ll(K) * ll(K - 1)) - s) % p)) % p; ans %= p; } cout << ans << endl; return 0; }
[ "variable_declaration.type.change" ]
731,403
731,402
u391331433
cpp
p02928
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define pll pair<long long, long long> #define pb push_back #define ll long long #define ff first #define ss second #define D(x) cerr << #x " = " << (x) << endl #define vll vector<ll> #define IOS \ ios_base::sync_with_stdio(0); \ cin.tie(NULL); #define endl '\n' using namespace std; using namespace __gnu_pbds; #define os \ tree<int, null_type, less<int>, rb_tree_tag, \ tree_order_statistics_node_update> const ll MOD = 1e9 + 7; ll add(ll a, ll b) { return (a % MOD + b % MOD) % MOD; } ll mult(ll a, ll b) { return (a % MOD * b % MOD) % MOD; } int main() { IOS os o_set; ll n, k; cin >> n >> k; ll a[n]; ll r[n]; ll tot[n]; map<ll, ll> mp; for (ll i = 0; i < n; i++) { cin >> a[i]; ll small = o_set.order_of_key(a[i]) + mp[a[i]]; ll gt = i - small; r[i] = gt; o_set.insert(a[i]); mp[a[i]]++; } for (ll i = 0; i < n; i++) { ll small = o_set.order_of_key(a[i]) + mp[a[i]]; ll gt = n - small; tot[i] = gt; } ll ans = 0; ll t = k * (k - 1); t /= 2; for (ll i = 0; i < n; i++) { ans = add(ans, mult(k, r[i])); ans = add(ans, mult(t, tot[i])); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define pll pair<long long, long long> #define pb push_back #define ll long long #define ff first #define ss second #define D(x) cerr << #x " = " << (x) << endl #define vll vector<ll> #define IOS \ ios_base::sync_with_stdio(0); \ cin.tie(NULL); #define endl '\n' using namespace std; using namespace __gnu_pbds; #define os \ tree<long long, null_type, less_equal<long long>, rb_tree_tag, \ tree_order_statistics_node_update> const ll MOD = 1e9 + 7; ll add(ll a, ll b) { return (a % MOD + b % MOD) % MOD; } ll mult(ll a, ll b) { return (a % MOD * b % MOD) % MOD; } int main() { IOS os o_set; ll n, k; cin >> n >> k; ll a[n]; ll r[n]; ll tot[n]; map<ll, ll> mp; for (ll i = 0; i < n; i++) { cin >> a[i]; ll small = o_set.order_of_key(a[i]) + mp[a[i]]; ll gt = i - small; r[i] = gt; o_set.insert(a[i]); // cout<<o_set.size()<<endl; mp[a[i]]++; } for (ll i = 0; i < n; i++) { ll small = o_set.order_of_key(a[i]) + mp[a[i]]; ll gt = n - small; tot[i] = gt; } ll ans = 0; ll t = k * (k - 1); t /= 2; for (ll i = 0; i < n; i++) { // cout<<a[i]<<" "<<r[i]<<endl; ans = add(ans, mult(k, r[i])); ans = add(ans, mult(t, tot[i])); } cout << ans << endl; return 0; }
[ "preprocessor.define.value.change" ]
731,410
731,411
u244472647
cpp
p02928
#include "bits/stdc++.h" using namespace std; int main() { int n; long long k; cin >> n >> k; vector<int> a(n); for (auto &e : a) { cin >> e; } long long cnt = 0; for (int i = 0; i < n; i++) { int under_num = 0; int under_num_back = 0; for (int j = 0; j < n; j++) { if (a[i] > a[j]) { under_num++; if (i < j) { under_num_back++; } } } cnt += (under_num_back * k) % 1000000007 + (under_num * (k * (k - 1) % 1000000007) / 2) % 1000000007; cnt %= 1000000007; } cout << cnt << endl; return 0; }
#include "bits/stdc++.h" using namespace std; int main() { int n; long long k; cin >> n >> k; vector<int> a(n); for (auto &e : a) { cin >> e; } long long cnt = 0; for (int i = 0; i < n; i++) { int under_num = 0; int under_num_back = 0; for (int j = 0; j < n; j++) { if (a[i] > a[j]) { under_num++; if (i < j) { under_num_back++; } } } cnt += (under_num_back * k) % 1000000007 + (under_num * ((k * (k - 1) / 2) % 1000000007)) % 1000000007; cnt %= 1000000007; } cout << cnt << endl; return 0; }
[ "assignment.change" ]
731,412
731,413
u056633659
cpp
p02928
#include "bits/stdc++.h" using namespace std; int main() { int n; long long k; cin >> n >> k; vector<int> a(n); for (auto &e : a) { cin >> e; } long long cnt = 0; for (int i = 0; i < n; i++) { int under_num = 0; int under_num_back = 0; for (int j = 0; j < n; j++) { if (a[i] > a[j]) { under_num++; if (i < j) { under_num_back++; } } } cnt += (under_num_back * k) % 1000000007 + (under_num * k * (k - 1) / 2) % 1000000007; cnt %= 1000000007; } cout << cnt << endl; return 0; }
#include "bits/stdc++.h" using namespace std; int main() { int n; long long k; cin >> n >> k; vector<int> a(n); for (auto &e : a) { cin >> e; } long long cnt = 0; for (int i = 0; i < n; i++) { int under_num = 0; int under_num_back = 0; for (int j = 0; j < n; j++) { if (a[i] > a[j]) { under_num++; if (i < j) { under_num_back++; } } } cnt += (under_num_back * k) % 1000000007 + (under_num * ((k * (k - 1) / 2) % 1000000007)) % 1000000007; cnt %= 1000000007; } cout << cnt << endl; return 0; }
[ "assignment.change" ]
731,414
731,413
u056633659
cpp
p02928
#include <bits/stdc++.h> using namespace std; #define int long long #define float long double #define M 1000000007 int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; int n; cin >> n; int k; cin >> k; int a[n]; int c = 0; for (int i = 0; i < n; i++) { cin >> a[i]; } int a1[n], a2[n]; memset(a1, 0, sizeof(a1)); memset(a2, 0, sizeof(a2)); for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { if (a[i] > a[j]) { a1[i]++; } } for (int j = 0; j < n; j++) { if (a[i] > a[j]) { a2[i]++; } } } for (int i = 0; i < n; i++) { c += (k * a1[i]) % M + (a2[i] * (((k * (k - 1)) / 2)) % M) % M; c = c % M; } cout << c << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long #define float long double #define M 1000000007 int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; int n; cin >> n; int k; cin >> k; int a[n]; int c = 0; for (int i = 0; i < n; i++) { cin >> a[i]; } int a1[n], a2[n]; memset(a1, 0, sizeof(a1)); memset(a2, 0, sizeof(a2)); for (int i = 0; i < n; i++) { for (int j = i; j < n; j++) { if (a[i] > a[j]) { a1[i]++; } } for (int j = 0; j < n; j++) { if (a[i] > a[j]) { a2[i]++; } } } for (int i = 0; i < n; i++) { c += (k * a1[i]) % M + (a2[i] * (((k * (k - 1)) / 2) % M)) % M; c = c % M; } cout << c << endl; return 0; }
[ "control_flow.loop.for.initializer.change", "expression.operation.binary.remove" ]
731,415
731,416
u270945478
cpp
p02928
#include <bits/stdc++.h> using namespace std; #define int long long #define float long double #define M 1000000007 int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; int n; cin >> n; int k; cin >> k; int a[n]; int c = 0; for (int i = 0; i < n; i++) { cin >> a[i]; } int a1[n], a2[n]; memset(a1, 0, sizeof(a1)); memset(a2, 0, sizeof(a2)); for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { if (a[i] > a[j]) { a1[i]++; } } for (int j = 0; j < n; j++) { if (a[i] > a[j]) { a2[i]++; } } } for (int i = 0; i < n; i++) { c += (k * a1[i]) % M + (a2[i] * ((k * (k - 1)) / 2) % M) % M; c = c % M; } cout << c << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long #define float long double #define M 1000000007 int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; int n; cin >> n; int k; cin >> k; int a[n]; int c = 0; for (int i = 0; i < n; i++) { cin >> a[i]; } int a1[n], a2[n]; memset(a1, 0, sizeof(a1)); memset(a2, 0, sizeof(a2)); for (int i = 0; i < n; i++) { for (int j = i; j < n; j++) { if (a[i] > a[j]) { a1[i]++; } } for (int j = 0; j < n; j++) { if (a[i] > a[j]) { a2[i]++; } } } for (int i = 0; i < n; i++) { c += (k * a1[i]) % M + (a2[i] * (((k * (k - 1)) / 2) % M)) % M; c = c % M; } cout << c << endl; return 0; }
[ "control_flow.loop.for.initializer.change", "expression.operation.binary.remove" ]
731,417
731,416
u270945478
cpp
p02928
/* vrrtll==???>;::::~~~~~~......`.`````````````````````...-?777!_.._?7u,~~~::::;>>??=lllttrrzu rtll==??>>;::::~~~~......`.`````````````````` ..J77!`````````...`..._T,~~~~:::;;>??==lttrrv tll=??>>;:::~~~~......``````````````````..J7^ ` `` ` `` .,```````...._4,.~~~::;;>>?===lttr l=???>;;::~~~......`````HTSu,.`` `..J7! ` `` .J"~N```````````..?&.~~~~::;;>>?==llt =??>;;::~~~~.....``````.@????7SJ.?= ` ` `` .J=....J; ``````````..h..~~~~::;;>??=ll ?>>;::~~~~.....````````.D?>>?>?>?8+.`` `.J"_......_b` ````````.S_.~~~~::;;>??=l >;;::~~~~....``````````.C>??>>>?>>>?8J.` ```..Y~..........J; ` ` ``````` G...~~~~::;>??= ;;::~~~....```````` `..W1>>?>>>>?>>>>>?S,.`.7^.............-N`` ` ``````` 6...~~~~::;>?? ;:~~~~....``````` ..7` d??>>?>?>>?>>?>>1udMgggNNNNggJ.......([ `````.L...~~~~::;>? :~~~.....`````` .7` `K>?>?>>>>>>+ugNMMMB""7<!~~<?7TWMNNa,..w.` ` ` ` `````,)....~~:::;> ~~~....``````.J^ ` #>>?>>>?jgMMM9=_................-?TMMa,b` ` ` ` ````(,...~~~~:;; ~~~....``` .7`` ` @?>>?1uMM#=.........................(TMNa...... ` ``````4....~~~::; ~~~...`` .=`` ` ` .b>>jgNH".................`.............?HNmx??17TYY9SA+(..L....~~~:: ~....` ,^`` ` ` .b+dN#^............6..-(,-...`............(HMm+>>>>>?>>????zOM_.~~~:: .... .=``` `` ` ...JNMM^..........`..._n.(MMN,....`..`.........?MNe<>>?>??>????d^...~~~: ~...v```` ` ..-Z""!_..(M@_........`........?7MMMMp.................-TNN+?>>>????1d4-..-(Jk9 ..(^`...zY"!_........(MD..............`......JMMMMp....`..`..`......./MNx>??>>?1d!.h7=~(??= (v_`,R_.............(NF..(/..(&,...`..........?MMMM;..................(MMs>>?1&T"!``....(1= t..`` 4,...........(N@....?,(NMNR_.....`..`....(WMM$..`....`..`..`....._HMe7=```````....~_1 ...````.4,........-dM:.....(7MMMNR-.....................`............(.?^ `` ``````....~~~ ...``````,4,....`.(NF........(MMMMb..`....--................`....(.7! ` ````....~~: ..````` ` `.5J_...JMt.........?NMMM[...`.HH5._(J7[...`...`...--?^` ` `````....~~~: ...````` ` ` 7a,.dM{....`...../MMMN......(J=` .>......._(/= ` ` `````...~~~: ....```` `` (4MN{..........._7"^...(/^ `.C....-(J=` ` ` ```....~~~: ....````` ` JdM[...`...`........`_3.. ..?!..(-7! ` ` ``````....~~~:: r...`````` ` ``(CJMb..............`......__..-(?^ ` ` `````....~~::; J/...````` ` `,3>+MN-.`..`...`..........._(J=`` ` ` ```````....~~~::; _j,..`.```` ``.5>>?dNb...`......`......_-?'` ` `````....~~~::;; ~~j,..```````.D??>>>MM/....`........(-=` ` ` ` ```````...~~~:::;> ~~~j,...````.E??>??>?MN-.........(J= ` ` ` ``````....~~~~::;?? :~~~?,...``.@>?>?>>??dMN_....-(?^ ` ` ` ` ````````...~~~~:;;>?? ::~~~?/....K??????>>?>dMN-_(7! ` ` ` ````````....~~~:::>>??l ;:::~~/e.(K==?????????<dM"! ` ` ` ` `` ``````...~~~~:::;>??=l */ #include "bits/stdc++.h" using namespace std; #define ok1 printf("ok1\n"); #define ok2 printf("ok2\n"); #define M 1000000000000000000LL #define rep(i, n) for (int i = 0; i < n; ++i) #define REP(i, s, n) for (int i = (s); i < (n); ++i) #define repr(i, n) for (int i = n - 1; i >= 0; --i) #define REPR(i, s, n) for (int i = (s); i >= (n); --(i)) #define all(a) (a).begin(), (a).end() #define reall(a) (a).rbegin(), (a).rend() #define pb push_back #define pf push_front #define MIN(a, b) a = min((a), (b)) #define MAX(a, b) a = max((a), (b)) #define SIZE(v) (int)v.size() #define DOUBLE fixed << setprecision(15) #define fi first #define se second const double pi = acos(-1.0); typedef vector<int> vi; typedef vector<string> vs; typedef long long ll; typedef vector<ll> vll; typedef vector<vi> vvi; typedef vector<vll> vvll; typedef vector<char> vc; typedef vector<double> vd; typedef vector<bool> vb; typedef deque<ll> dll; typedef pair<ll, ll> P; typedef vector<P> vP; const ll mod = 1e9 + 7; // const ll mod = 998244353; ll dx[4] = {1, 0, -1, 0}; ll dy[4] = {0, 1, 0, -1}; struct edge { int to; int cost; }; void Pvll(vll v) { cout << "------------------------------------------------\n"; rep(i, v.size()) cout << v[i] << " "; cout << endl; cout << "------------------------------------------------\n"; } void Pvvll(vvll v) { cout << "------------------------------------------------\n"; rep(i, v.size()) { rep(j, v[i].size()) { cout << v[i][j] << " "; } cout << endl; } cout << "------------------------------------------------\n"; } void Ps(string s) { cout << "------------------------------------------------\n"; rep(i, s.size()) cout << s[i] << " "; cout << endl; cout << "------------------------------------------------\n"; } void Pvs(vs s) { cout << "------------------------------------------------\n"; rep(i, s.size()) { rep(j, s[i].size()) { cout << s[i][j] << " "; } cout << endl; } cout << "------------------------------------------------\n"; } void Yes(bool x) { if (x) cout << "Yes\n"; else cout << "No\n"; } void YES(bool x) { if (x) cout << "YES\n"; else cout << "NO\n"; } void yes(bool x) { if (x) cout << "yes\n"; else cout << "no\n"; } void Yay(bool x) { if (x) cout << "Yay!\n"; else cout << ":(\n"; } ll n, d, r, l, k, h, ans = 0, ret = M; bool flag = false, flag2 = false, flag3 = false; string s, t, u; void INIT() { cin.tie(0); ios::sync_with_stdio(false); cout << DOUBLE; } int main() { INIT(); cin >> n >> k; vll v(n); rep(i, n) cin >> v[i]; ret = 0; rep(i, n) { rep(j, n) { if (i == j) continue; // cout << i << " " << j << " " << v[i] << " " << v[j] << endl; if (v[i] > v[j]) { if (i > j) { ret++; // ans++; } else { ans++; } } } } // cout << ans << " " << ret << " " << ((k*(k+1)) / 2)%mod << endl; cout << ((((k * (k + 1)) / 2) % mod * ans) + (((k * (k - 1)) / 2) * ret)) % mod << endl; return 0; } /* 10 2 10 9 8 7 5 6 3 4 2 1*/
/* vrrtll==???>;::::~~~~~~......`.`````````````````````...-?777!_.._?7u,~~~::::;>>??=lllttrrzu rtll==??>>;::::~~~~......`.`````````````````` ..J77!`````````...`..._T,~~~~:::;;>??==lttrrv tll=??>>;:::~~~~......``````````````````..J7^ ` `` ` `` .,```````...._4,.~~~::;;>>?===lttr l=???>;;::~~~......`````HTSu,.`` `..J7! ` `` .J"~N```````````..?&.~~~~::;;>>?==llt =??>;;::~~~~.....``````.@????7SJ.?= ` ` `` .J=....J; ``````````..h..~~~~::;;>??=ll ?>>;::~~~~.....````````.D?>>?>?>?8+.`` `.J"_......_b` ````````.S_.~~~~::;;>??=l >;;::~~~~....``````````.C>??>>>?>>>?8J.` ```..Y~..........J; ` ` ``````` G...~~~~::;>??= ;;::~~~....```````` `..W1>>?>>>>?>>>>>?S,.`.7^.............-N`` ` ``````` 6...~~~~::;>?? ;:~~~~....``````` ..7` d??>>?>?>>?>>?>>1udMgggNNNNggJ.......([ `````.L...~~~~::;>? :~~~.....`````` .7` `K>?>?>>>>>>+ugNMMMB""7<!~~<?7TWMNNa,..w.` ` ` ` `````,)....~~:::;> ~~~....``````.J^ ` #>>?>>>?jgMMM9=_................-?TMMa,b` ` ` ` ````(,...~~~~:;; ~~~....``` .7`` ` @?>>?1uMM#=.........................(TMNa...... ` ``````4....~~~::; ~~~...`` .=`` ` ` .b>>jgNH".................`.............?HNmx??17TYY9SA+(..L....~~~:: ~....` ,^`` ` ` .b+dN#^............6..-(,-...`............(HMm+>>>>>?>>????zOM_.~~~:: .... .=``` `` ` ...JNMM^..........`..._n.(MMN,....`..`.........?MNe<>>?>??>????d^...~~~: ~...v```` ` ..-Z""!_..(M@_........`........?7MMMMp.................-TNN+?>>>????1d4-..-(Jk9 ..(^`...zY"!_........(MD..............`......JMMMMp....`..`..`......./MNx>??>>?1d!.h7=~(??= (v_`,R_.............(NF..(/..(&,...`..........?MMMM;..................(MMs>>?1&T"!``....(1= t..`` 4,...........(N@....?,(NMNR_.....`..`....(WMM$..`....`..`..`....._HMe7=```````....~_1 ...````.4,........-dM:.....(7MMMNR-.....................`............(.?^ `` ``````....~~~ ...``````,4,....`.(NF........(MMMMb..`....--................`....(.7! ` ````....~~: ..````` ` `.5J_...JMt.........?NMMM[...`.HH5._(J7[...`...`...--?^` ` `````....~~~: ...````` ` ` 7a,.dM{....`...../MMMN......(J=` .>......._(/= ` ` `````...~~~: ....```` `` (4MN{..........._7"^...(/^ `.C....-(J=` ` ` ```....~~~: ....````` ` JdM[...`...`........`_3.. ..?!..(-7! ` ` ``````....~~~:: r...`````` ` ``(CJMb..............`......__..-(?^ ` ` `````....~~::; J/...````` ` `,3>+MN-.`..`...`..........._(J=`` ` ` ```````....~~~::; _j,..`.```` ``.5>>?dNb...`......`......_-?'` ` `````....~~~::;; ~~j,..```````.D??>>>MM/....`........(-=` ` ` ` ```````...~~~:::;> ~~~j,...````.E??>??>?MN-.........(J= ` ` ` ``````....~~~~::;?? :~~~?,...``.@>?>?>>??dMN_....-(?^ ` ` ` ` ````````...~~~~:;;>?? ::~~~?/....K??????>>?>dMN-_(7! ` ` ` ````````....~~~:::>>??l ;:::~~/e.(K==?????????<dM"! ` ` ` ` `` ``````...~~~~:::;>??=l */ #include "bits/stdc++.h" using namespace std; #define ok1 printf("ok1\n"); #define ok2 printf("ok2\n"); #define M 1000000000000000000LL #define rep(i, n) for (int i = 0; i < n; ++i) #define REP(i, s, n) for (int i = (s); i < (n); ++i) #define repr(i, n) for (int i = n - 1; i >= 0; --i) #define REPR(i, s, n) for (int i = (s); i >= (n); --(i)) #define all(a) (a).begin(), (a).end() #define reall(a) (a).rbegin(), (a).rend() #define pb push_back #define pf push_front #define MIN(a, b) a = min((a), (b)) #define MAX(a, b) a = max((a), (b)) #define SIZE(v) (int)v.size() #define DOUBLE fixed << setprecision(15) #define fi first #define se second const double pi = acos(-1.0); typedef vector<int> vi; typedef vector<string> vs; typedef long long ll; typedef vector<ll> vll; typedef vector<vi> vvi; typedef vector<vll> vvll; typedef vector<char> vc; typedef vector<double> vd; typedef vector<bool> vb; typedef deque<ll> dll; typedef pair<ll, ll> P; typedef vector<P> vP; const ll mod = 1e9 + 7; // const ll mod = 998244353; ll dx[4] = {1, 0, -1, 0}; ll dy[4] = {0, 1, 0, -1}; struct edge { int to; int cost; }; void Pvll(vll v) { cout << "------------------------------------------------\n"; rep(i, v.size()) cout << v[i] << " "; cout << endl; cout << "------------------------------------------------\n"; } void Pvvll(vvll v) { cout << "------------------------------------------------\n"; rep(i, v.size()) { rep(j, v[i].size()) { cout << v[i][j] << " "; } cout << endl; } cout << "------------------------------------------------\n"; } void Ps(string s) { cout << "------------------------------------------------\n"; rep(i, s.size()) cout << s[i] << " "; cout << endl; cout << "------------------------------------------------\n"; } void Pvs(vs s) { cout << "------------------------------------------------\n"; rep(i, s.size()) { rep(j, s[i].size()) { cout << s[i][j] << " "; } cout << endl; } cout << "------------------------------------------------\n"; } void Yes(bool x) { if (x) cout << "Yes\n"; else cout << "No\n"; } void YES(bool x) { if (x) cout << "YES\n"; else cout << "NO\n"; } void yes(bool x) { if (x) cout << "yes\n"; else cout << "no\n"; } void Yay(bool x) { if (x) cout << "Yay!\n"; else cout << ":(\n"; } ll n, d, r, l, k, h, ans = 0, ret = M; bool flag = false, flag2 = false, flag3 = false; string s, t, u; void INIT() { cin.tie(0); ios::sync_with_stdio(false); cout << DOUBLE; } int main() { INIT(); cin >> n >> k; vll v(n); rep(i, n) cin >> v[i]; ret = 0; rep(i, n) { rep(j, n) { if (i == j) continue; // cout << i << " " << j << " " << v[i] << " " << v[j] << endl; if (v[i] > v[j]) { if (i > j) { ret++; // ans++; } else { ans++; } } } } // cout << ans << " " << ret << " " << ((k*(k+1)) / 2)%mod << endl; cout << ((((k * (k + 1)) / 2) % mod * ans) + ((((k * (k - 1)) / 2) % mod) * ret)) % mod << endl; return 0; } /* 10 2 10 9 8 7 5 6 3 4 2 1*/
[]
731,428
731,429
u373958718
cpp
p02928
#include <algorithm> #include <bits/stdc++.h> #include <math.h> using namespace std; template <class T> using V = vector<T>; template <class S, class T> using P = pair<S, T>; template <class... T> using TP = tuple<T...>; using ll = long long; using db = double; using ldb = long db; using str = string; using vll = V<ll>; using vvll = V<V<ll>>; using pll = P<ll, ll>; using tpll = TP<ll, ll, ll>; using vpll = V<pll>; using vtpll = V<tpll>; using vst = V<str>; using vch = V<char>; #define FOR(i, a, b) for (ll i = (a); i < (ll)(b); i++) #define rFOR(i, a, b) for (ll i = (b); i > (ll)(a); i--) #define oFOR(i, a, b) for (ll i = (a); i < (ll)(b); i += 2) #define bgn begin() #define en end() #define SORT(a) sort((a).bgn, (a).en) #define REV(a) reverse((a).bgn, (a).en) #define fi first #define se second #define sz size() #define gcd(a, b) __gcd(a, b) #define lcm(a, b) __lcm(a, b) #define co(a) cout << a << endl #define ci(a) cin >> a #define pb(a) push_back(a) #define pob pop_back() #define mp make_pair #define mt make_tuple #define pbmp(a, b) push_back(mp(a, b)) #define subs(a, b) substr(a, b) #define cfs(a) cout << fixed << setprecision(a) #define INF 1e16 #define mod 1e9 + 7 // vvll v(n,vll(m)) n行m列 // A.erase(A.begin()+i) 配列Aのi番目を消せる // std::binary_search(v.bgn,v.en,a); // abs(a,b) pow(a,n) to_string stoll // auto Iter=lower_bound(v.bgn,v.en,a); // lower//upper co(*Iter)co(Iter-v.bgn); const int MAX = 510000; const int MOD = 1000000007; long long fac[MAX], finv[MAX], inv[MAX]; void Comuse() { 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; } } #define comuse Comuse() ll combi(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; vll v(n); FOR(i, 0, n) { cin >> v[i]; } vll c(n); vll d(n); ll ans = 0; FOR(i, 1, n) { for (ll j = i - 1; j >= 0; j--) { if (v[i] < v[j]) { c[j]++; } } FOR(j, i, n) { if (v[i] < v[j]) { d[j]++; } } } FOR(i, 0, n) { ans += c[i] * (k * (k + 1) / 2 % MOD) % MOD; ans %= MOD; } FOR(i, 0, n) { ans += d[i] * (k * (k - 1) / 2 % MOD) % MOD; ans %= MOD; } co(ans); }
#include <algorithm> #include <bits/stdc++.h> #include <math.h> using namespace std; template <class T> using V = vector<T>; template <class S, class T> using P = pair<S, T>; template <class... T> using TP = tuple<T...>; using ll = long long; using db = double; using ldb = long db; using str = string; using vll = V<ll>; using vvll = V<V<ll>>; using pll = P<ll, ll>; using tpll = TP<ll, ll, ll>; using vpll = V<pll>; using vtpll = V<tpll>; using vst = V<str>; using vch = V<char>; #define FOR(i, a, b) for (ll i = (a); i < (ll)(b); i++) #define rFOR(i, a, b) for (ll i = (b); i > (ll)(a); i--) #define oFOR(i, a, b) for (ll i = (a); i < (ll)(b); i += 2) #define bgn begin() #define en end() #define SORT(a) sort((a).bgn, (a).en) #define REV(a) reverse((a).bgn, (a).en) #define fi first #define se second #define sz size() #define gcd(a, b) __gcd(a, b) #define lcm(a, b) __lcm(a, b) #define co(a) cout << a << endl #define ci(a) cin >> a #define pb(a) push_back(a) #define pob pop_back() #define mp make_pair #define mt make_tuple #define pbmp(a, b) push_back(mp(a, b)) #define subs(a, b) substr(a, b) #define cfs(a) cout << fixed << setprecision(a) #define INF 1e16 #define mod 1e9 + 7 // vvll v(n,vll(m)) n行m列 // A.erase(A.begin()+i) 配列Aのi番目を消せる // std::binary_search(v.bgn,v.en,a); // abs(a,b) pow(a,n) to_string stoll // auto Iter=lower_bound(v.bgn,v.en,a); // lower//upper co(*Iter)co(Iter-v.bgn); const int MAX = 510000; const int MOD = 1000000007; long long fac[MAX], finv[MAX], inv[MAX]; void Comuse() { 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; } } #define comuse Comuse() ll combi(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; vll v(n); FOR(i, 0, n) { cin >> v[i]; } vll c(n); vll d(n); ll ans = 0; FOR(i, 0, n) { for (ll j = i; j >= 0; j--) { if (v[i] < v[j]) { c[j]++; } } FOR(j, i, n) { // co(v[i]<<" "<<v[j]); if (v[i] < v[j]) { d[j]++; } } } FOR(i, 0, n) { // co(c[i]); ans += c[i] * (k * (k + 1) / 2 % MOD) % MOD; ans %= MOD; } FOR(i, 0, n) { // co(d[i]); ans += d[i] * (k * (k - 1) / 2 % MOD) % MOD; ans %= MOD; } co(ans); }
[ "literal.number.change", "call.arguments.change", "control_flow.loop.for.initializer.change", "expression.operation.binary.remove" ]
731,434
731,435
u177143886
cpp
p02928
#include <bits/stdc++.h> using namespace std; const long long MOD = 1000000007; typedef long long int ll; int main() { long long N, K; cin >> N >> K; vector<long long> v(N); for (int i = 0; i < N; i++) { cin >> v[i]; } ll P = 0; for (int i = 0; i < v.size() - 1; i++) { for (int j = i + 1; j < v.size(); j++) { if (v.at(i) > v.at(j)) P++; } } ll Q = 0; for (int i = 0; i < v.size(); i++) { for (int j = 0; j < v.size(); j++) { if (v.at(i) > v.at(j)) Q++; } } long long ans = (P * K) % MOD + (Q * ((((K * (K - 1)) % MOD) / 2) % MOD) % MOD); ans %= MOD; cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; const long long MOD = 1000000007; typedef long long int ll; int main() { long long N, K; cin >> N >> K; vector<long long> v(N); for (int i = 0; i < N; i++) { cin >> v[i]; } ll P = 0; for (int i = 0; i < v.size() - 1; i++) { for (int j = i + 1; j < v.size(); j++) { if (v.at(i) > v.at(j)) P++; } } ll Q = 0; for (int i = 0; i < v.size(); i++) { for (int j = 0; j < v.size(); j++) { if (v.at(i) > v.at(j)) Q++; } } long long ans = (P * K) % MOD + (Q * ((K * (K - 1) / 2) % MOD) % MOD); ans %= MOD; cout << ans << endl; }
[ "expression.operation.binary.remove" ]
731,436
731,437
u598710706
cpp
p02928
#include <bits/stdc++.h> using namespace std; const long long MOD = 1000000007; typedef long long int ll; int main() { long long N, K; cin >> N >> K; vector<long long> v(N); for (int i = 0; i < N; i++) { cin >> v[i]; } ll P = 0; for (int i = 0; i < v.size() - 1; i++) { for (int j = i + 1; j < v.size(); j++) { if (v.at(i) > v.at(j)) P++; } } ll Q = 0; for (int i = 0; i < v.size(); i++) { for (int j = 0; j < v.size(); j++) { if (v.at(i) > v.at(j)) Q++; } } long long ans = (P * K) % MOD + (Q * ((K * (K - 1) % MOD) / 2)) % MOD; ans %= MOD; cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; const long long MOD = 1000000007; typedef long long int ll; int main() { long long N, K; cin >> N >> K; vector<long long> v(N); for (int i = 0; i < N; i++) { cin >> v[i]; } ll P = 0; for (int i = 0; i < v.size() - 1; i++) { for (int j = i + 1; j < v.size(); j++) { if (v.at(i) > v.at(j)) P++; } } ll Q = 0; for (int i = 0; i < v.size(); i++) { for (int j = 0; j < v.size(); j++) { if (v.at(i) > v.at(j)) Q++; } } long long ans = (P * K) % MOD + (Q * ((K * (K - 1) / 2) % MOD) % MOD); ans %= MOD; cout << ans << endl; }
[ "assignment.change" ]
731,438
731,437
u598710706
cpp
p02928
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { int n, i; ll k, a[2005]; cin >> n >> k; for (i = 0; i < n; i++) cin >> a[i]; ll ans = 0, mod = 1e9 + 7; int c1 = 0, c2 = 0; for (i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { if (a[j] < a[i]) c1++; } } for (i = 1; i <= n; ++i) for (int j = 1; j <= n; ++j) c2 += a[i] > a[j]; ans = (k * (k - 1) / 2 % mod * c2 + k * c1) % mod; ans %= mod; cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { int n, i; ll k, a[2005]; cin >> n >> k; for (i = 0; i < n; i++) cin >> a[i]; ll ans = 0, mod = 1e9 + 7; int c1 = 0, c2 = 0; for (i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { if (a[j] < a[i]) c1++; } } for (i = 0; i < n; ++i) for (int j = 0; j < n; ++j) c2 += a[i] > a[j]; ans = (k * (k - 1) / 2 % mod * c2 + k * c1) % mod; ans %= mod; cout << ans << endl; return 0; }
[ "literal.number.change", "assignment.value.change", "control_flow.loop.for.initializer.change", "expression.off_by_one", "expression.operator.compare.change", "control_flow.loop.for.condition.change", "expression.operation.binary.change", "variable_declaration.value.change" ]
731,442
731,443
u057633934
cpp
p02928
/* Author: Dhruv Rastogi */ #include <bits/stdc++.h> using namespace std; #define ll long long #define int long long #define all(sdk) sdk.begin(), sdk.end() #define mll map<int, int> #define pb push_back #define rep(i, a, b) for (int i = a; i < b; ++i) #define repd(i, a, b) for (int i = a; i >= b; --i) #define mp make_pair #define hell 1000000007 #define endl '\n' #define vvll vector<vector<int>> #define vll vector<int> #define mint map<int, int> #define sz(x) (int)x.size() #define sll set<int> #define pll pair<int, int> #define F first #define S second const long double PI = acos(-1.0); int inv[2005], cnt[2005]; int a[2005]; void solve() { int n, k; cin >> n >> k; rep(i, 0, n) cin >> a[i]; rep(i, 0, n) { rep(j, 0, n) { if (a[j] < a[i]) { cnt[i]++; if (j > i) inv[i]++; } } } int ans = 0; rep(i, 0, n) { ans += inv[i] * k; ans %= hell; ans += (k * (k - 1) / 2) % hell * cnt[i] % hell; } cout << ans << endl; } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t = 1; // cin>>t; while (t--) { solve(); } return 0; }
/* Author: Dhruv Rastogi */ #include <bits/stdc++.h> using namespace std; #define ll long long #define int long long #define all(sdk) sdk.begin(), sdk.end() #define mll map<int, int> #define pb push_back #define rep(i, a, b) for (int i = a; i < b; ++i) #define repd(i, a, b) for (int i = a; i >= b; --i) #define mp make_pair #define hell 1000000007 #define endl '\n' #define vvll vector<vector<int>> #define vll vector<int> #define mint map<int, int> #define sz(x) (int)x.size() #define sll set<int> #define pll pair<int, int> #define F first #define S second const long double PI = acos(-1.0); int inv[2005], cnt[2005]; int a[2005]; void solve() { int n, k; cin >> n >> k; rep(i, 0, n) cin >> a[i]; rep(i, 0, n) { rep(j, 0, n) { if (a[j] < a[i]) { cnt[i]++; if (j > i) inv[i]++; } } } int ans = 0; rep(i, 0, n) { ans += inv[i] * k; ans %= hell; ans += (k * (k - 1) / 2) % hell * cnt[i] % hell; ans %= hell; } cout << ans << endl; } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t = 1; // cin>>t; while (t--) { solve(); } return 0; }
[ "assignment.add" ]
731,444
731,445
u651976779
cpp
p02928
#include <bits/stdc++.h> using namespace std; int main() { int N; int64_t K; cin >> N >> K; vector<int> A(N); for (int i = 0; i < N; i++) { cin >> A.at(i); } int64_t x = 0; bool flag; int64_t p = int64_t(pow(10, 9)); do { flag = false; for (int i = 0; i < N - 1; i++) { if (A.at(i) > A.at(i + 1)) { swap(A.at(i), A.at(i + 1)); x++; flag = true; } } } while (flag); int64_t ans = (x * K); ans %= (p + 7); int64_t y = 0; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { if (A.at(i) > A.at(j)) { y++; } } } int64_t c = (K * (K - 1)) % (p + 7); ans += (y * c) / 2; ans %= (p + 7); cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int N; int64_t K; cin >> N >> K; vector<int> A(N); for (int i = 0; i < N; i++) { cin >> A.at(i); } int64_t x = 0; bool flag; int64_t p = int64_t(pow(10, 9)); do { flag = false; for (int i = 0; i < N - 1; i++) { if (A.at(i) > A.at(i + 1)) { swap(A.at(i), A.at(i + 1)); x++; flag = true; } } } while (flag); int64_t ans = (x * K); ans %= (p + 7); int64_t y = 0; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { if (A.at(i) > A.at(j)) { y++; } } } int64_t c = ((K * (K - 1)) / 2) % (p + 7); ans += (y * c); ans %= (p + 7); cout << ans << endl; return 0; }
[ "expression.operation.binary.remove" ]
731,451
731,452
u030246664
cpp
p02928
#include <algorithm> #include <array> #include <cassert> #include <cmath> #include <cstdio> #include <deque> #include <iostream> #include <limits> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> #define for0(i, n) for (int i = 0; i < (n); ++i) #define for1n(i, n) for (int i = 1; i <= (n); ++i) #define for1(i, n) for (int i = 1; i < (n); ++i) #define forn(i, n) for (int i = 0; i <= (n); ++i) #define forx(i, n, x) for (int i = (x); i < (n); ++i) #define mod 1000000007LL using namespace std; class llm { long long l; explicit operator int() { return l; } explicit operator long() { return l; } public: llm(long long m = 0LL) : l((m % mod >= 0) ? (m % mod) : (m % mod + mod)){}; llm operator=(llm m) { l = m.l; return *this; } // llm operator=(int i) {l = i % mod; return *this;} // llm operator=(long i) {l = i % mod; return *this;} // llm operator=(long long i){l = i % mod; return *this;} llm operator+(llm m) { return llm(l + m.l); } llm operator+(int m) { return llm(l + (m % mod)); } llm operator+(long m) { return llm(l + (m % mod)); } llm operator+(long long m) { return llm(l + (m % mod)); } llm operator-(llm m) { return llm(l - m.l); } llm operator-(int m) { return llm(l - (m % mod)); } llm operator-(long m) { return llm(l - (m % mod)); } llm operator-(long long m) { return llm(l - (m % mod)); } // llm operator-(long long m){return llm(l - m);} // llm operator-(int m){return llm(l - m);} long long operator*(llm m) { return l * m.l; } llm operator*(int m) { return llm(l * (m % mod)); } llm operator*(long m) { return llm(l * (m % mod)); } llm operator*(long long m) { return llm(l * (m % mod)); } // llm operator/(llm m) {return llm(l / m.l);} llm operator/(int m) { assert(m < mod && mod % m != 0); return llm(l / m); } llm operator/(long m) { assert(m < mod && mod % m != 0); return llm(l / m); } llm operator/(long long m) { assert(m < mod && mod % m != 0); return llm(l / m); } // llm operator%(llm m) {return llm(l % m.l);} llm operator%(int m) { return llm(l % m); } llm operator%(long m) { return llm(l % m); } llm operator%(long long m) { return llm(l % m); } long long operator++(void) { return l = (l + 1) % mod; } long long operator++(int) { long long tmp = l; ++(*this); return tmp; } long long operator--(void) { return l = (l - 1) % mod; } long long operator--(int) { long long tmp = l; --(*this); return tmp; } llm operator-() { return llm(-l); } llm operator+() { return llm(l); } operator long long() { // cout << "l: " << l << "\n"; return l; } friend istream &operator>>(istream &stream, llm &m); // operator int(){return l;} }; istream &operator>>(istream &stream, llm &m) { long long tmp; stream >> tmp; m.l = tmp % mod; return stream; } typedef long long ll; typedef priority_queue<ll> pq; typedef priority_queue<ll, vector<ll>, greater<ll>> pql; typedef stack<ll> stk; typedef queue<ll> qu; int main(void) { int N; llm K; cin >> N >> K; int a[2000] = {}; for0(i, N) { cin >> a[i]; } pair<llm, llm> p[2000]; for0(i, N) { p[i].first = 0; // all p[i].second = 0; // after } for0(i, N) { for0(j, N) { if (a[i] > a[j]) { ++p[i].first; if (i < j) { ++p[i].second; } } } // p[i].first%=mod; // p[i].second%=mod; } llm result = 0; for0(i, N) { result = (result + (p[i].second * K)); result = ((p[i].first * (((long long)K * ((long long)K - 1)) % mod / 2)) + result); // result = (result + (p[i].second *K %mod)) %mod; // result = ((p[i].first * ((K-1) *K/2 % mod)) %mod + result) % mod; } cout << result; return 0; }
#include <algorithm> #include <array> #include <cassert> #include <cmath> #include <cstdio> #include <deque> #include <iostream> #include <limits> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> #define for0(i, n) for (int i = 0; i < (n); ++i) #define for1n(i, n) for (int i = 1; i <= (n); ++i) #define for1(i, n) for (int i = 1; i < (n); ++i) #define forn(i, n) for (int i = 0; i <= (n); ++i) #define forx(i, n, x) for (int i = (x); i < (n); ++i) #define mod 1000000007LL using namespace std; class llm { long long l; explicit operator int() { return l; } explicit operator long() { return l; } public: llm(long long m = 0LL) : l((m % mod >= 0) ? (m % mod) : (m % mod + mod)){}; llm operator=(llm m) { l = m.l; return *this; } // llm operator=(int i) {l = i % mod; return *this;} // llm operator=(long i) {l = i % mod; return *this;} // llm operator=(long long i){l = i % mod; return *this;} llm operator+(llm m) { return llm(l + m.l); } llm operator+(int m) { return llm(l + (m % mod)); } llm operator+(long m) { return llm(l + (m % mod)); } llm operator+(long long m) { return llm(l + (m % mod)); } llm operator-(llm m) { return llm(l - m.l); } llm operator-(int m) { return llm(l - (m % mod)); } llm operator-(long m) { return llm(l - (m % mod)); } llm operator-(long long m) { return llm(l - (m % mod)); } // llm operator-(long long m){return llm(l - m);} // llm operator-(int m){return llm(l - m);} long long operator*(llm m) { return l * m.l; } llm operator*(int m) { return llm(l * (m % mod)); } llm operator*(long m) { return llm(l * (m % mod)); } llm operator*(long long m) { return llm(l * (m % mod)); } // llm operator/(llm m) {return llm(l / m.l);} llm operator/(int m) { assert(m < mod && mod % m != 0); return llm(l / m); } llm operator/(long m) { assert(m < mod && mod % m != 0); return llm(l / m); } llm operator/(long long m) { assert(m < mod && mod % m != 0); return llm(l / m); } // llm operator%(llm m) {return llm(l % m.l);} llm operator%(int m) { return llm(l % m); } llm operator%(long m) { return llm(l % m); } llm operator%(long long m) { return llm(l % m); } long long operator++(void) { return l = (l + 1) % mod; } long long operator++(int) { long long tmp = l; ++(*this); return tmp; } long long operator--(void) { return l = (l - 1) % mod; } long long operator--(int) { long long tmp = l; --(*this); return tmp; } llm operator-() { return llm(-l); } llm operator+() { return llm(l); } operator long long() { // cout << "l: " << l << "\n"; return l; } friend istream &operator>>(istream &stream, llm &m); // operator int(){return l;} }; istream &operator>>(istream &stream, llm &m) { long long tmp; stream >> tmp; m.l = tmp % mod; return stream; } typedef long long ll; typedef priority_queue<ll> pq; typedef priority_queue<ll, vector<ll>, greater<ll>> pql; typedef stack<ll> stk; typedef queue<ll> qu; int main(void) { int N; llm K; cin >> N >> K; int a[2000] = {}; for0(i, N) { cin >> a[i]; } pair<llm, llm> p[2000]; for0(i, N) { p[i].first = 0; // all p[i].second = 0; // after } for0(i, N) { for0(j, N) { if (a[i] > a[j]) { ++p[i].first; if (i < j) { ++p[i].second; } } } // p[i].first%=mod; // p[i].second%=mod; } llm result = 0; for0(i, N) { result = (result + (p[i].second * K)); result = ((p[i].first * (((long long)K * ((long long)K - 1)) / 2)) + result); // result = (result + (p[i].second *K %mod)) %mod; // result = ((p[i].first * ((K-1) *K/2 % mod)) %mod + result) % mod; } cout << result; return 0; }
[ "expression.operation.binary.remove" ]
731,453
731,454
u643747754
cpp
p02928
#include <algorithm> #include <array> #include <cassert> #include <cmath> #include <cstdio> #include <deque> #include <iostream> #include <limits> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> #define for0(i, n) for (int i = 0; i < (n); ++i) #define for1n(i, n) for (int i = 1; i <= (n); ++i) #define for1(i, n) for (int i = 1; i < (n); ++i) #define forn(i, n) for (int i = 0; i <= (n); ++i) #define forx(i, n, x) for (int i = (x); i < (n); ++i) #define mod 1000000007LL using namespace std; class llm { long long l; public: llm(long long int l = 0) : l(l % mod) { assert(this->l < mod); }; llm &operator=(llm m) { l = m.l; return *this; } llm &operator=(int i) { l = i % mod; return *this; } llm &operator=(long i) { l = i % mod; return *this; } llm &operator=(long long i) { l = i % mod; return *this; } llm operator+(llm m) { return llm(l + m.l); } llm operator+(int m) { return llm(l + (m % mod)); } llm operator+(long m) { return llm(l + (m % mod)); } llm operator+(long long m) { return llm(l + (m % mod)); } llm operator-(llm m) { return llm(l - m.l); } llm operator-(int m) { return llm(l - (m % mod)); } llm operator-(long m) { return llm(l - (m % mod)); } llm operator-(long long m) { return llm(l - (m % mod)); } llm operator*(llm m) { return llm(l * m.l); } llm operator*(int m) { return llm(l * (m % mod)); } llm operator*(long m) { return llm(l * (m % mod)); } llm operator*(long long m) { return llm(l * (m % mod)); } // llm operator/(llm m) {return llm(l / m.l);} llm operator/(int m) { assert(mod % m != 0); return llm(l / m); } llm operator/(long m) { assert(mod % m != 0); return llm(l / m); } llm operator/(long long m) { assert(mod % m != 0); return llm(l / m); } // llm operator%(llm m) {return llm(l % m.l);} llm operator%(int m) { return llm(l % m); } llm operator%(long m) { return llm(l % m); } llm operator%(long long m) { return llm(l % m); } long long operator++(int) { l = (l + 1) % mod; return l; } long long operator++(void) { long long tmp = l; l = (l + 1) % mod; return tmp; } long long operator--(int) { l = (l - 1) % mod; return l; } long long operator--(void) { long long tmp = l; l = (l - 1) % mod; return tmp; } operator long long() { // cout << "l: " << l << "\n"; return l; } friend istream &operator>>(istream &stream, llm &m); // operator int(){return l;} }; istream &operator>>(istream &stream, llm &m) { long long tmp; stream >> tmp; m.l = tmp % mod; return stream; } typedef long long ll; typedef priority_queue<ll> pq; typedef priority_queue<ll, vector<ll>, greater<ll>> pql; typedef stack<ll> stk; typedef queue<ll> qu; int main(void) { int N; llm K; cin >> N >> K; int a[2000] = {}; for0(i, N) { cin >> a[i]; } pair<llm, llm> p[2000]; for0(i, N) { p[i].first = 0; // all p[i].second = 0; // after } for0(i, N) { for0(j, N) { if (a[i] > a[j]) { ++p[i].first; if (i < j) { ++p[i].second; } } } // p[i].first%=mod; // p[i].second%=mod; } llm result = 0; for0(i, N) { // result = (result + (p[i].second *K)); // result = ((p[i].first * ((K-1) *K/2)) + result); result = (result + (p[i].second * K % mod)) % mod; result = ((p[i].first * ((K - 1) * K / 2 % mod)) % mod + result) % mod; } cout << result; return 0; }
#include <algorithm> #include <array> #include <cassert> #include <cmath> #include <cstdio> #include <deque> #include <iostream> #include <limits> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> #define for0(i, n) for (int i = 0; i < (n); ++i) #define for1n(i, n) for (int i = 1; i <= (n); ++i) #define for1(i, n) for (int i = 1; i < (n); ++i) #define forn(i, n) for (int i = 0; i <= (n); ++i) #define forx(i, n, x) for (int i = (x); i < (n); ++i) #define mod 1000000007LL using namespace std; class llm { long long l; public: llm(long long int l = 0) : l(l % mod) { assert(this->l < mod); }; llm &operator=(llm m) { l = m.l; return *this; } llm &operator=(int i) { l = i % mod; return *this; } llm &operator=(long i) { l = i % mod; return *this; } llm &operator=(long long i) { l = i % mod; return *this; } llm operator+(llm m) { return llm(l + m.l); } llm operator+(int m) { return llm(l + (m % mod)); } llm operator+(long m) { return llm(l + (m % mod)); } llm operator+(long long m) { return llm(l + (m % mod)); } llm operator-(llm m) { return llm(l - m.l); } llm operator-(int m) { return llm(l - (m % mod)); } llm operator-(long m) { return llm(l - (m % mod)); } llm operator-(long long m) { return llm(l - (m % mod)); } llm operator*(llm m) { return llm(l * m.l); } llm operator*(int m) { return llm(l * (m % mod)); } llm operator*(long m) { return llm(l * (m % mod)); } llm operator*(long long m) { return llm(l * (m % mod)); } // llm operator/(llm m) {return llm(l / m.l);} llm operator/(int m) { assert(mod % m != 0); return llm(l / m); } llm operator/(long m) { assert(mod % m != 0); return llm(l / m); } llm operator/(long long m) { assert(mod % m != 0); return llm(l / m); } // llm operator%(llm m) {return llm(l % m.l);} llm operator%(int m) { return llm(l % m); } llm operator%(long m) { return llm(l % m); } llm operator%(long long m) { return llm(l % m); } long long operator++(int) { l = (l + 1) % mod; return l; } long long operator++(void) { long long tmp = l; l = (l + 1) % mod; return tmp; } long long operator--(int) { l = (l - 1) % mod; return l; } long long operator--(void) { long long tmp = l; l = (l - 1) % mod; return tmp; } operator long long() { // cout << "l: " << l << "\n"; return l; } friend istream &operator>>(istream &stream, llm &m); // operator int(){return l;} }; istream &operator>>(istream &stream, llm &m) { long long tmp; stream >> tmp; m.l = tmp % mod; return stream; } typedef long long ll; typedef priority_queue<ll> pq; typedef priority_queue<ll, vector<ll>, greater<ll>> pql; typedef stack<ll> stk; typedef queue<ll> qu; #define llm ll int main(void) { int N; llm K; cin >> N >> K; int a[2000] = {}; for0(i, N) { cin >> a[i]; } pair<llm, llm> p[2000]; for0(i, N) { p[i].first = 0; // all p[i].second = 0; // after } for0(i, N) { for0(j, N) { if (a[i] > a[j]) { ++p[i].first; if (i < j) { ++p[i].second; } } } // p[i].first%=mod; // p[i].second%=mod; } llm result = 0; for0(i, N) { // result = (result + (p[i].second *K)); // result = ((p[i].first * ((K-1) *K/2)) + result); result = (result + (p[i].second * K % mod)) % mod; result = ((p[i].first * ((K - 1) * K / 2 % mod)) % mod + result) % mod; } cout << result; return 0; }
[]
731,460
731,461
u643747754
cpp
p02928
#include <bits/stdc++.h> #include <stdio.h> using namespace std; typedef int64_t ll; typedef long double ld; void solve() { const ll M = 1000000007; ll n, k; cin >> n >> k; ll ans = 0, peeche[n] = {0}, aage[n] = {0}, a[n]; for (ll i = 0; i < n; i++) cin >> a[i]; for (ll i = 0; i < n; i++) { for (ll j = 0; j < n; j++) { if (j != i) { if (j < i && a[i] > a[j]) peeche[i]++; else if (j > i && a[i] > a[j]) aage[i]++; } } } ll kf = ((k * (k + 1)) / 2) % M, kb = ((k * (k - 1)) / 2) % M; for (ll i = 0; i < n; i++) { ans += (((peeche[i] * kb) % M) + ((aage[i] * kf) % M)) % M; } cout << ans; } int main() { ios_base ::sync_with_stdio(false); cin.tie(NULL); ll t = 1; // cin >> t; while (t--) { solve(); } return 0; }
#include <bits/stdc++.h> #include <stdio.h> using namespace std; typedef int64_t ll; typedef long double ld; void solve() { const ll M = 1000000007; ll n, k; cin >> n >> k; ll ans = 0, peeche[n] = {0}, aage[n] = {0}, a[n]; for (ll i = 0; i < n; i++) cin >> a[i]; for (ll i = 0; i < n; i++) { for (ll j = 0; j < n; j++) { if (j != i) { if (j < i && a[i] > a[j]) peeche[i]++; else if (j > i && a[i] > a[j]) aage[i]++; } } } ll kf = ((k * (k + 1)) / 2) % M, kb = ((k * (k - 1)) / 2) % M; for (ll i = 0; i < n; i++) { ans = (ans + ((peeche[i] * kb) % M) + ((aage[i] * kf) % M)) % M; } cout << ans; } int main() { ios_base ::sync_with_stdio(false); cin.tie(NULL); ll t = 1; // cin >> t; while (t--) { solve(); } return 0; }
[ "assignment.value.change", "assignment.change" ]
731,462
731,463
u488672860
cpp
p02928
#include <algorithm> #include <iostream> #include <map> #include <math.h> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <utility> #include <vector> typedef long long ll; const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1}; const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1}; const int dr[4] = {-1, 0, 1, 0}; const int dc[4] = {0, 1, 0, -1}; const int INF = 1e9; #define FOR(i, a, n) for (int i = (int)(a); i < (int)(n); ++i) #define REP(i, n) FOR(i, 0, n) #define SORT(a) sort(a.begin(), a.end()) #define REVERSE(a) reverse(a.begin(), a.end()) int guki(int a) { if (a % 2 == 0) return 0; else return 1; } int gcd(int a, int b) { if (a % b == 0) { return b; } else { return (gcd(b, a % b)); } } int lcm(int a, int b) { int x = gcd(a, b); return (a * b / x); } using namespace std; ll k(ll a) { a--; ll ans = 0; while (a != 0) { ans += a; a--; } return ans; } int main() { ll n, k, ans = 0, wa = 1000000007; cin >> n >> k; vector<ll> vec(n); vector<ll> cnt(n); REP(i, n) { cin >> vec[i]; cnt[i] = 0; } REP(i, n) { FOR(j, i + 1, n) { if (vec[i] > vec[j]) { cnt[i]++; } } } vector<ll> cnt2(n); REP(i, n) cnt2[i] = 0; REP(i, n) { for (int j = 0; j < i; j++) { if (vec[i] > vec[j]) cnt2[i]++; } } REP(i, n) { ans += cnt[i] * ((k + 1) * k / 2) % wa; ans += cnt2[i] * ((k) * (k - 1) / 2) % wa; } cout << ans % wa << endl; }
#include <algorithm> #include <iostream> #include <map> #include <math.h> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <utility> #include <vector> typedef long long ll; const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1}; const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1}; const int dr[4] = {-1, 0, 1, 0}; const int dc[4] = {0, 1, 0, -1}; const int INF = 1e9; #define FOR(i, a, n) for (int i = (int)(a); i < (int)(n); ++i) #define REP(i, n) FOR(i, 0, n) #define SORT(a) sort(a.begin(), a.end()) #define REVERSE(a) reverse(a.begin(), a.end()) int guki(int a) { if (a % 2 == 0) return 0; else return 1; } int gcd(int a, int b) { if (a % b == 0) { return b; } else { return (gcd(b, a % b)); } } int lcm(int a, int b) { int x = gcd(a, b); return (a * b / x); } using namespace std; ll k(ll a) { a--; ll ans = 0; while (a != 0) { ans += a; a--; } return ans; } int main() { ll n, k, ans = 0, wa = 1000000007; cin >> n >> k; vector<ll> vec(n); vector<ll> cnt(n); REP(i, n) { cin >> vec[i]; cnt[i] = 0; } REP(i, n) { FOR(j, i + 1, n) { if (vec[i] > vec[j]) { cnt[i]++; } } } vector<ll> cnt2(n); REP(i, n) cnt2[i] = 0; REP(i, n) { for (int j = 0; j < i; j++) { if (vec[i] > vec[j]) cnt2[i]++; } } REP(i, n) { ans += cnt[i] * (((k + 1) * k / 2) % wa); ans += cnt2[i] * (((k) * (k - 1) / 2) % wa); } cout << ans % wa << endl; }
[]
731,468
731,469
u339558464
cpp
p02928
#include <algorithm> #include <iostream> #include <map> #include <vector> // #include <numeric> // gcdとかlcmとか C++17から #include <time.h> // time_t timer; time(&timer); でtimerに現在時刻が代入される. #include <unistd.h> // sleep関数.引数は秒単位. using namespace std; typedef long long ll; ll my_gcd(ll a, ll b) { return (b == 0) ? a : my_gcd(b, a % b); } ll my_lcm(ll a, ll b) { return a * b / my_gcd(a, b); } ll factorial(ll a) { ll ans = 1; for (ll i = a; i > 0; i--) { ans *= i; } return ans; } ll pow(ll a, ll b) { ll a_powered = 1; for (int i = 0; i < b; i++) { a_powered *= a; } return a_powered; } int main(int argc, char *argv[]) { ll C = 1000000000 + 7; ll N, K; cin >> N >> K; ll A[N]; for (int i = 0; i < N; i++) { cin >> A[i]; } ll ans = 0; ll inversion_num_A = 0; for (int i = 0; i < N; i++) { ll x = 0; for (int j = 0; j < i; j++) { if (A[j] > A[i]) { x++; } } inversion_num_A += x; } ans += inversion_num_A * K; sort(A, A + N); ll count[2000] = {0}; for (int i = 0; i < N; i++) { if (A[i] == A[N - 1]) break; count[A[i]] = N - i - 1; } ll sum_count = 0; for (int i = 0; i < 2000; i++) { sum_count += count[i]; } ll K_seriesed = K * (K - 1) / 2; K_seriesed %= C; ans += sum_count * K_seriesed; ans %= C; cout << ans << endl; }
#include <algorithm> #include <iostream> #include <map> #include <vector> // #include <numeric> // gcdとかlcmとか C++17から #include <time.h> // time_t timer; time(&timer); でtimerに現在時刻が代入される. #include <unistd.h> // sleep関数.引数は秒単位. using namespace std; typedef long long ll; ll my_gcd(ll a, ll b) { return (b == 0) ? a : my_gcd(b, a % b); } ll my_lcm(ll a, ll b) { return a * b / my_gcd(a, b); } ll factorial(ll a) { ll ans = 1; for (ll i = a; i > 0; i--) { ans *= i; } return ans; } ll pow(ll a, ll b) { ll a_powered = 1; for (int i = 0; i < b; i++) { a_powered *= a; } return a_powered; } int main(int argc, char *argv[]) { ll C = 1000000000 + 7; ll N, K; cin >> N >> K; ll A[N]; for (int i = 0; i < N; i++) { cin >> A[i]; } ll ans = 0; ll inversion_num_A = 0; for (int i = 0; i < N; i++) { ll x = 0; for (int j = 0; j < i; j++) { if (A[j] > A[i]) { x++; } } inversion_num_A += x; } ans += inversion_num_A * K; sort(A, A + N); ll count[2001] = {0}; for (int i = 0; i < N; i++) { if (A[i] == A[N - 1]) break; count[A[i]] = N - i - 1; } ll sum_count = 0; for (int i = 0; i < N; i++) { sum_count += count[A[i]]; } ll K_seriesed = K * (K - 1) / 2; K_seriesed %= C; ans += sum_count * K_seriesed; ans %= C; cout << ans << endl; }
[ "literal.number.change", "variable_declaration.array_dimensions.change", "identifier.replace.add", "literal.replace.remove", "control_flow.loop.for.condition.change", "expression.operation.binary.change" ]
731,485
731,486
u867763103
cpp
p02928
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { int n; ll k, ans1 = 0, ans2 = 0, ans = 0; cin >> n >> k; int a[n], b[n * 2]; for (ll i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) { for (int j = i; j < n; j++) { if (a[i] > a[j]) ans1++; } } //1配列の転倒数 ans1 = ans1 * k % 1000000007; for (int i = 0; i < n * 2; i++) b[i] = a[i % n]; // 2配列間の転倒数 for (int i = 0; i < n; i++) { for (int j = n; j < n * 2; j++) { if (b[i] > b[j]) ans2++; } } ll mk = k * (k - 1) % 1000000007; ans2 = (ans2 * mk) / 2 % 1000000007; ans = (ans1 + ans2) % 1000000007; cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { int n; ll k, ans1 = 0, ans2 = 0, ans = 0; cin >> n >> k; int a[n], b[n * 2]; for (ll i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) { for (int j = i; j < n; j++) { if (a[i] > a[j]) ans1++; } } //1配列の転倒数 ans1 = ans1 * k % 1000000007; for (int i = 0; i < n * 2; i++) b[i] = a[i % n]; // 2配列間の転倒数 for (int i = 0; i < n; i++) { for (int j = n; j < n * 2; j++) { if (b[i] > b[j]) ans2++; } } ll mk = k * (k - 1) / 2 % 1000000007; ans2 = (ans2 * mk) % 1000000007; ans = (ans1 + ans2) % 1000000007; cout << ans << endl; return 0; }
[ "expression.operation.binary.remove" ]
731,487
731,488
u907518238
cpp
p02928
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { int n; ll k, ans1 = 0, ans2 = 0, ans = 0; cin >> n >> k; int a[n], b[n * 2]; for (ll i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) { for (int j = i; j < n; j++) { if (a[i] > a[j]) ans1++; } } //1配列の転倒数 ans1 = ans1 * k % 1000000007; for (int i = 0; i < n * 2; i++) b[i] = a[i % n]; // 2配列間の転倒数 for (int i = 0; i < n; i++) { for (int j = n; j < n * 2; j++) { if (b[i] > b[j]) ans2++; } } ll mk = k * (k - 1) % 1000000007; ans2 = (ans2 * mk / 2) % 1000000007; ans = (ans1 + ans2) % 1000000007; cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { int n; ll k, ans1 = 0, ans2 = 0, ans = 0; cin >> n >> k; int a[n], b[n * 2]; for (ll i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) { for (int j = i; j < n; j++) { if (a[i] > a[j]) ans1++; } } //1配列の転倒数 ans1 = ans1 * k % 1000000007; for (int i = 0; i < n * 2; i++) b[i] = a[i % n]; // 2配列間の転倒数 for (int i = 0; i < n; i++) { for (int j = n; j < n * 2; j++) { if (b[i] > b[j]) ans2++; } } ll mk = k * (k - 1) / 2 % 1000000007; ans2 = (ans2 * mk) % 1000000007; ans = (ans1 + ans2) % 1000000007; cout << ans << endl; return 0; }
[ "expression.operation.binary.remove" ]
731,489
731,488
u907518238
cpp
p02928
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); int64_t N, K; cin >> N >> K; vector<int> A(N); for (auto &v : A) { cin >> v; } int64_t x = 0; for (int i = 0; i < N - 1; ++i) { for (int j = i + 1; j < N; ++j) { if (A[i] > A[j]) { x += 1; } } } int64_t y = 0; for (int i = 0; i < N; ++i) { for (int j = 0; j < N; ++j) { if (A[i] < A[j]) { y += 1; } } } int64_t m = 1000000007; int64_t a = x * K % m; int64_t b = y * (K * (K - 1) % m / 2) % m; cout << (a + b) % m << endl; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); int64_t N, K; cin >> N >> K; vector<int> A(N); for (auto &v : A) { cin >> v; } int64_t x = 0; for (int i = 0; i < N - 1; ++i) { for (int j = i + 1; j < N; ++j) { if (A[i] > A[j]) { x += 1; } } } int64_t y = 0; for (int i = 0; i < N; ++i) { for (int j = 0; j < N; ++j) { if (A[i] < A[j]) { y += 1; } } } int64_t m = 1000000007; int64_t a = x * K % m; int64_t b = y * (K * (K - 1) / 2 % m) % m; cout << (a + b) % m << endl; }
[ "expression.operation.binary.remove" ]
731,494
731,495
u842596864
cpp
p02928
#include <iostream> long n, k, a = 0, i, j, m = 1e9 + 7, v[2 << 20]; main() { for (std::cin >> n >> k; i++ < n;) for (j = 0; j++ < n;) { std::cin >> v[i]; if (i == j) continue; if (v[i] > v[j]) (a += k * (k - 1) / 2 + (i < j ? k : 0)) %= m; } std::cout << a; }
#include <iostream> long n, k, a = 0, i, j, m = 1e9 + 7, v[2 << 20]; main() { for (std::cin >> n >> k; i++ < n;) for (j = 0; j++ < n;) { std::cin >> v[j]; if (i == j) continue; if (v[i] > v[j]) (a += k * (k - 1) / 2 + (i < j ? k : 0)) %= m; } std::cout << a; }
[ "identifier.change", "variable_access.subscript.index.change", "expression.operation.binary.change" ]
731,507
731,508
u317711717
cpp
p02928
#include <algorithm> #include <cmath> #include <complex> #include <cstdlib> #include <deque> #include <functional> #include <iostream> #include <map> #include <numeric> #include <set> #include <string> #include <vector> using namespace std; using Int = long long; Int INF = 1LL << 60; const Int MOD = 1000000000 + 7; template <int Modulo = MOD> struct Mint { Int val; constexpr Mint(Int v = 0) noexcept : val(v % Modulo) { if (val < 0) v += Modulo; } constexpr int getmod() { return Modulo; } constexpr Mint operator-() const noexcept { return val ? Modulo - val : 0; } constexpr Mint operator+(const Mint &r) const noexcept { return Mint(*this) += r; } constexpr Mint operator-(const Mint &r) const noexcept { return Mint(*this) -= r; } constexpr Mint operator*(const Mint &r) const noexcept { return Mint(*this) *= r; } constexpr Mint operator/(const Mint &r) const noexcept { return Mint(*this) /= r; } constexpr Mint &operator+=(const Mint &r) noexcept { val += r.val; if (val >= Modulo) val -= Modulo; return *this; } constexpr Mint &operator-=(const Mint &r) noexcept { val -= r.val; if (val < 0) val += Modulo; return *this; } constexpr Mint &operator*=(const Mint &r) noexcept { val = val * r.val % Modulo; return *this; } constexpr Mint &operator/=(const Mint &r) noexcept { Int a = r.val, b = Modulo, u = 1, v = 0; while (b) { Int t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } val = val * u % Modulo; if (val < 0) val += Modulo; return *this; } constexpr bool operator==(const Mint &r) const noexcept { return this->val == r.val; } constexpr bool operator!=(const Mint &r) const noexcept { return this->val != r.val; } friend ostream &operator<<(ostream &os, const Mint<Modulo> &x) noexcept { return os << x.val; } friend istream &operator>>(istream &is, Mint<Modulo> &x) noexcept { Int tmp; is >> tmp; x = Mint<Modulo>(tmp); return is; } friend constexpr Mint<Modulo> modpow(const Mint<Modulo> &a, Int n) noexcept { Mint res(1), tmp = a; while (n > 0) { if (n & 1) res *= tmp; tmp *= tmp; n >>= 1; } return res; } }; using mint = Mint<>; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); Int N, K; cin >> N >> K; vector<Int> a(N); for (Int i = 0; i < N; i++) { cin >> a[i]; } vector<pair<Int, Int>> count(N, pair<Int, Int>()); Int before; Int after; for (Int i = 0; i < N; i++) { before = 0; after = 0; for (Int j = 0; j < N; j++) { if (i == j) continue; if ((j < i) && (a[i] > a[j])) before += 1; if ((j > i) && (a[i] > a[j])) after += 1; } count[i].first = before; count[i].second = after; } mint ans = 0; for (Int i = 0; i < N; i++) { ans += count[i].second * K + (count[i].second + count[i].first) * K * (K - 1) / 2; } cout << ans << endl; }
#include <algorithm> #include <cmath> #include <complex> #include <cstdlib> #include <deque> #include <functional> #include <iostream> #include <map> #include <numeric> #include <set> #include <string> #include <vector> using namespace std; using Int = long long; Int INF = 1LL << 60; const Int MOD = 1000000000 + 7; template <int Modulo = MOD> struct Mint { Int val; constexpr Mint(Int v = 0) noexcept : val(v % Modulo) { if (val < 0) v += Modulo; } constexpr int getmod() { return Modulo; } constexpr Mint operator-() const noexcept { return val ? Modulo - val : 0; } constexpr Mint operator+(const Mint &r) const noexcept { return Mint(*this) += r; } constexpr Mint operator-(const Mint &r) const noexcept { return Mint(*this) -= r; } constexpr Mint operator*(const Mint &r) const noexcept { return Mint(*this) *= r; } constexpr Mint operator/(const Mint &r) const noexcept { return Mint(*this) /= r; } constexpr Mint &operator+=(const Mint &r) noexcept { val += r.val; if (val >= Modulo) val -= Modulo; return *this; } constexpr Mint &operator-=(const Mint &r) noexcept { val -= r.val; if (val < 0) val += Modulo; return *this; } constexpr Mint &operator*=(const Mint &r) noexcept { val = val * r.val % Modulo; return *this; } constexpr Mint &operator/=(const Mint &r) noexcept { Int a = r.val, b = Modulo, u = 1, v = 0; while (b) { Int t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } val = val * u % Modulo; if (val < 0) val += Modulo; return *this; } constexpr bool operator==(const Mint &r) const noexcept { return this->val == r.val; } constexpr bool operator!=(const Mint &r) const noexcept { return this->val != r.val; } friend ostream &operator<<(ostream &os, const Mint<Modulo> &x) noexcept { return os << x.val; } friend istream &operator>>(istream &is, Mint<Modulo> &x) noexcept { Int tmp; is >> tmp; x = Mint<Modulo>(tmp); return is; } friend constexpr Mint<Modulo> modpow(const Mint<Modulo> &a, Int n) noexcept { Mint res(1), tmp = a; while (n > 0) { if (n & 1) res *= tmp; tmp *= tmp; n >>= 1; } return res; } }; using mint = Mint<>; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); Int N, K; cin >> N >> K; vector<Int> a(N); for (Int i = 0; i < N; i++) { cin >> a[i]; } vector<pair<mint, mint>> count(N, pair<mint, mint>()); Int before; Int after; for (Int i = 0; i < N; i++) { before = 0; after = 0; for (Int j = 0; j < N; j++) { if (i == j) continue; if ((j < i) && (a[i] > a[j])) before += 1; if ((j > i) && (a[i] > a[j])) after += 1; } count[i].first = before; count[i].second = after; } mint ans = 0; for (Int i = 0; i < N; i++) { ans += count[i].second * K + (count[i].second + count[i].first) * K * (K - 1) / 2; } cout << ans << endl; }
[]
731,514
731,515
u612271542
cpp
p02928
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ll n; ll k; cin >> n >> k; ll a[2005]; for (int i = 0; i < n; i++) { cin >> a[i]; } ll c1 = 0; ll c2 = 0; for (int i = 0; i < n - 1; i++) { for (int j = i + 1; j < n; j++) { if (a[i] > a[j]) c1++; } } for (int i = 0; i < n; i++) { for (int g = 0; g < n; g++) { if (a[i] > a[g]) c2++; } } ll c = 1000000007; cout << ((c1 * k) + (((k * (k - 1) % c * c2)) / 2)) % c << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ll n; ll k; cin >> n >> k; ll a[2005]; for (int i = 0; i < n; i++) { cin >> a[i]; } ll c1 = 0; ll c2 = 0; for (int i = 0; i < n - 1; i++) { for (int j = i + 1; j < n; j++) { if (a[i] > a[j]) c1++; } } for (int i = 0; i < n; i++) { for (int g = 0; g < n; g++) { if (a[i] > a[g]) c2++; } } ll c = 1000000007; cout << ((c1 * k) + (((k * (k - 1) / 2 % c * c2)))) % c << endl; }
[ "expression.operation.binary.remove" ]
731,516
731,517
u892687772
cpp
p02928
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ll n; ll k; cin >> n >> k; ll a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } ll c1 = 0; ll c2 = 0; for (int i = 0; i < n - 1; i++) { for (int j = i + 1; j < n; j++) { if (a[i] > a[j]) c1++; } } for (int i = 0; i < n; i++) { for (int g = 0; g < n; g++) { if (a[i] > a[g]) c2++; } } ll c = 1000000007; cout << ((c1 * k) + (((k * (k - 1) % c * c2)) / 2)) % c << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ll n; ll k; cin >> n >> k; ll a[2005]; for (int i = 0; i < n; i++) { cin >> a[i]; } ll c1 = 0; ll c2 = 0; for (int i = 0; i < n - 1; i++) { for (int j = i + 1; j < n; j++) { if (a[i] > a[j]) c1++; } } for (int i = 0; i < n; i++) { for (int g = 0; g < n; g++) { if (a[i] > a[g]) c2++; } } ll c = 1000000007; cout << ((c1 * k) + (((k * (k - 1) / 2 % c * c2)))) % c << endl; }
[ "identifier.replace.remove", "literal.replace.add", "variable_declaration.array_dimensions.change", "expression.operation.binary.remove" ]
731,518
731,517
u892687772
cpp
p02928
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <stack> #include <string> #include <time.h> #include <vector> #define rep(i, n) for (ll i = 0; i < n; i++) #define ll long long #define ggr \ getchar(); \ getchar(); \ return 0; #define prique priority_queue #define inf 1000000007 #define double long double using namespace std; typedef pair<ll, ll> P; bool prime(int n) { int cnt = 0; for (int i = 1; i <= sqrt(n); i++) { if (n % i == 0) cnt++; } if (cnt != 1) return false; else return n != 1; } ll gcd(ll x, ll y) { if (y == 0) return x; return gcd(y, x % y); } ll lcm(ll x, ll y) { return x * y / gcd(x, y); } ll a[4444]; ll cnt[2222]; ll memo[2222]; signed main() { ll n, k, ans = 0; cin >> n >> k; rep(i, n) cin >> a[i]; rep(i, n) { for (int j = i + 1; j < n; j++) { if (a[i] > a[j]) memo[a[i]]++; } } rep(i, n) { rep(j, n) { if (a[i] > a[j]) cnt[a[i]]++; } } rep(i, 2002) { ans += (memo[i] * k % inf + cnt[i] * k * (k - 1) / 2 % inf); ans %= inf; } cout << ans << endl; ggr }
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <stack> #include <string> #include <time.h> #include <vector> #define rep(i, n) for (ll i = 0; i < n; i++) #define ll long long #define ggr \ getchar(); \ getchar(); \ return 0; #define prique priority_queue #define inf 1000000007 #define double long double using namespace std; typedef pair<ll, ll> P; bool prime(int n) { int cnt = 0; for (int i = 1; i <= sqrt(n); i++) { if (n % i == 0) cnt++; } if (cnt != 1) return false; else return n != 1; } ll gcd(ll x, ll y) { if (y == 0) return x; return gcd(y, x % y); } ll lcm(ll x, ll y) { return x * y / gcd(x, y); } ll a[4444]; ll cnt[2222]; ll memo[2222]; signed main() { ll n, k, ans = 0; cin >> n >> k; rep(i, n) cin >> a[i]; rep(i, n) { for (int j = i + 1; j < n; j++) { if (a[i] > a[j]) memo[a[i]]++; } } rep(i, n) { rep(j, n) { if (a[i] > a[j]) cnt[a[i]]++; } } rep(i, 2002) { ans += memo[i] * k % inf + cnt[i] * (k * (k - 1) / 2 % inf) % inf; ans %= inf; } cout << ans << endl; ggr }
[ "assignment.change" ]
731,526
731,527
u441250130
cpp
p02928
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <stack> #include <string> #include <time.h> #include <vector> #define rep(i, n) for (ll i = 0; i < n; i++) #define ll long long #define ggr \ getchar(); \ getchar(); \ return 0; #define prique priority_queue #define inf 1000000007 #define double long double using namespace std; typedef pair<ll, ll> P; bool prime(int n) { int cnt = 0; for (int i = 1; i <= sqrt(n); i++) { if (n % i == 0) cnt++; } if (cnt != 1) return false; else return n != 1; } ll gcd(ll x, ll y) { if (y == 0) return x; return gcd(y, x % y); } ll lcm(ll x, ll y) { return x * y / gcd(x, y); } ll a[4444]; ll cnt[2222]; ll memo[2222]; signed main() { ll n, k, ans = 0; cin >> n >> k; rep(i, n) cin >> a[i]; rep(i, n) { for (int j = i + 1; j < n; j++) { if (a[i] > a[j]) memo[a[i]]++; } } rep(i, n) { rep(j, n) { if (a[i] > a[j]) cnt[a[i]]++; } } rep(i, 2002) { ans += (memo[i] * k % inf + cnt[i] * k * (k - 1) / 2 % inf); ans %= inf; } cout << ans << endl; ggr }
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <stack> #include <string> #include <time.h> #include <vector> #define rep(i, n) for (ll i = 0; i < n; i++) #define ll long long #define ggr \ getchar(); \ getchar(); \ return 0; #define prique priority_queue #define inf 1000000007 #define double long double using namespace std; typedef pair<ll, ll> P; bool prime(int n) { int cnt = 0; for (int i = 1; i <= sqrt(n); i++) { if (n % i == 0) cnt++; } if (cnt != 1) return false; else return n != 1; } ll gcd(ll x, ll y) { if (y == 0) return x; return gcd(y, x % y); } ll lcm(ll x, ll y) { return x * y / gcd(x, y); } ll a[4444]; ll cnt[2222]; ll memo[2222]; signed main() { ll n, k, ans = 0; cin >> n >> k; rep(i, n) cin >> a[i]; rep(i, n) { for (int j = i + 1; j < n; j++) { if (a[i] > a[j]) memo[a[i]]++; } } rep(i, n) { rep(j, n) { if (a[i] > a[j]) cnt[a[i]]++; } } rep(i, 2002) { ans += (memo[i] * k % inf + cnt[i] * (k * (k - 1) / 2 % inf) % inf); ans %= inf; } cout << ans << endl; ggr }
[]
731,526
731,528
u441250130
cpp
p02928
#include <bits/stdc++.h> #define ll long long #define double long double #define rep(i, n) for (int i = 0; i < (n); i++) #define REP(i, n) for (int i = 1; i <= (n); i++) #define mod (ll)(1000000007) #define inf (ll)(3e18 + 7) #define P pair<int, int> #define PiP pair<int, pair<int, int>> #define all(x) x.begin(), x.end() using namespace std; int main() { ll n, k, ans = 0, nm; cin >> n >> k; vector<ll> a(n), c(n, 0), r(n, 0); rep(i, n) cin >> a.at(i); for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { if (a.at(i) > a.at(j)) c.at(i)++; } for (int j = 0; j < i; j++) { if (a.at(i) > a.at(j)) r.at(i)++; } } for (int i = 0; i < n; i++) { ans += (r.at(i) * ((k * (k - 1) / 2) % mod)) % mod; ans += (c.at(i) * ((k * (k + 1) / 2) % mod)) % mod; } cout << ans; }
#include <bits/stdc++.h> #define ll long long #define double long double #define rep(i, n) for (int i = 0; i < (n); i++) #define REP(i, n) for (int i = 1; i <= (n); i++) #define mod (ll)(1000000007) #define inf (ll)(3e18 + 7) #define P pair<int, int> #define PiP pair<int, pair<int, int>> #define all(x) x.begin(), x.end() using namespace std; int main() { ll n, k, ans = 0, nm; cin >> n >> k; vector<ll> a(n), c(n, 0), r(n, 0); rep(i, n) cin >> a.at(i); for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { if (a.at(i) > a.at(j)) c.at(i)++; } for (int j = 0; j < i; j++) { if (a.at(i) > a.at(j)) r.at(i)++; } } for (int i = 0; i < n; i++) { ans += (r.at(i) * ((k * (k - 1) / 2) % mod)) % mod; ans += (c.at(i) * ((k * (k + 1) / 2) % mod)) % mod; } cout << ans % mod; }
[ "expression.operation.binary.add" ]
731,529
731,530
u441250130
cpp
p02928
#include <bits/stdc++.h> using namespace std; using ll = long long int; const int MAX = (int)(1e5 + 5); const ll INF = (ll)(1e10 + 5); const int MAX_N = (int)(2e3 + 5); const ll MOD = (ll)(1e9 + 7); int n; ll k; int a[MAX_N]; ll base[MAX_N]; ll duplicate[MAX_N]; ll ans; int main(void) { // Here your code ! scanf("%d %lld", &n, &k); for (int i = 0; i < n; ++i) { scanf("%d", &(a[i])); } // vector<int> tmp; // for (int i = 0; i < k; ++i) { // for (int j = 0; j < n; ++j) { // tmp.push_back(a[j]); // } // } // ll cnt = 0LL; // for (int i = 0; i < tmp.size(); ++i) { // for (int j = i + 1; j < tmp.size(); ++j) { // if (tmp[i] > tmp[j]) cnt += 1LL; // } // } // printf("%lld\n", cnt); for (int i = 0; i < n; ++i) { for (int j = i + 1; j < n; ++j) { if (a[i] > a[j]) base[i] += 1LL; } } for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { if (i == j) continue; if (a[i] > a[j]) duplicate[i] += 1LL; } } ll coef = k * (k - 1LL) / 2LL; ans = 0LL; for (int i = 0; i < n; ++i) { ans += k * base[i]; ans %= MOD; ans += coef * duplicate[i]; ans %= MOD; } printf("%lld\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long int; const int MAX = (int)(1e5 + 5); const ll INF = (ll)(1e10 + 5); const int MAX_N = (int)(2e3 + 5); const ll MOD = (ll)(1e9 + 7); int n; ll k; int a[MAX_N]; ll base[MAX_N]; ll duplicate[MAX_N]; ll ans; int main(void) { // Here your code ! scanf("%d %lld", &n, &k); for (int i = 0; i < n; ++i) { scanf("%d", &(a[i])); } // vector<int> tmp; // for (int i = 0; i < k; ++i) { // for (int j = 0; j < n; ++j) { // tmp.push_back(a[j]); // } // } // ll cnt = 0LL; // for (int i = 0; i < tmp.size(); ++i) { // for (int j = i + 1; j < tmp.size(); ++j) { // if (tmp[i] > tmp[j]) cnt += 1LL; // } // } // printf("%lld\n", cnt); for (int i = 0; i < n; ++i) { for (int j = i + 1; j < n; ++j) { if (a[i] > a[j]) base[i] += 1LL; } } for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { if (i == j) continue; if (a[i] > a[j]) duplicate[i] += 1LL; } } ll coef = k * (k - 1LL) / 2LL; coef %= MOD; ans = 0LL; for (int i = 0; i < n; ++i) { ans += k * base[i]; ans %= MOD; ans += coef * duplicate[i]; ans %= MOD; } printf("%lld\n", ans); return 0; }
[ "assignment.add" ]
731,531
731,532
u497422208
cpp
p02928
#include <bits/stdc++.h> #define REP(i, n) for (int i = 0; i < n; ++i) #define REPP(i, n) for (int i = 1; i <= n; ++i) #define REPR(i, n) for (int i = n - 1; i >= 0; --i) #define FOR(i, m, n) for (int i = m; i < n; ++i) #define ALL(v) v.begin(), v.end() #define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()); using namespace std; typedef long long ll; typedef pair<ll, ll> P; const ll MOD = 1000000007; const ll INF = 1000000000; template <typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; } template <typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; } int main() { cin.tie(0); ios::sync_with_stdio(false); ll n, k; cin >> n >> k; vector<ll> a(n); REP(i, n) cin >> a[i]; ll ans = 0; REP(i, n) { ll b = 0, d = 0; REP(j, i) { b += (a[j] > a[i]); } REP(j, n) { d += (a[j] > a[i]); } ans += b * k + (k * (k - 1) / 2) * d; ans %= MOD; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define REP(i, n) for (int i = 0; i < n; ++i) #define REPP(i, n) for (int i = 1; i <= n; ++i) #define REPR(i, n) for (int i = n - 1; i >= 0; --i) #define FOR(i, m, n) for (int i = m; i < n; ++i) #define ALL(v) v.begin(), v.end() #define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()); using namespace std; typedef long long ll; typedef pair<ll, ll> P; const ll MOD = 1000000007; const ll INF = 1000000000; template <typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; } template <typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; } int main() { cin.tie(0); ios::sync_with_stdio(false); ll n, k; cin >> n >> k; vector<ll> a(n); REP(i, n) cin >> a[i]; ll ans = 0; REP(i, n) { ll b = 0, d = 0; REP(j, i) { b += (a[j] > a[i]); } REP(j, n) { d += (a[j] > a[i]); } ans += b * k + (k * (k - 1) / 2) % MOD * d % MOD; ans %= MOD; } cout << ans << endl; return 0; }
[ "assignment.change" ]
731,533
731,534
u881647420
cpp
p02928
#include <algorithm> #include <cmath> #include <cstdlib> #include <iostream> #include <map> #include <string> #include <vector> #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) FOR(i, 0, n) #define MOD 1000000007 using namespace std; typedef long long int ll; const ll INF = (ll)1e18; int main() { ll N, K; cin >> N >> K; int a[2001]; REP(i, N) cin >> a[i]; ll t = 0; REP(i, N) FOR(j, i + 1, N) { if (a[i] > a[j]) t += 1; } ll s = 0; REP(i, N) REP(j, N) { if (a[i] > a[j]) s += 1; } t %= MOD; s %= MOD; cout << ((t * K) % MOD + ((K * (K - 1) / 2) * s)) % MOD << endl; }
#include <algorithm> #include <cmath> #include <cstdlib> #include <iostream> #include <map> #include <string> #include <vector> #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) FOR(i, 0, n) #define MOD 1000000007 using namespace std; typedef long long int ll; const ll INF = (ll)1e18; int main() { ll N, K; cin >> N >> K; int a[2005]; REP(i, N) cin >> a[i]; ll t = 0; REP(i, N) FOR(j, i + 1, N) { if (a[i] > a[j]) t += 1; } ll s = 0; REP(i, N) REP(j, N) { if (a[i] > a[j]) s += 1; } t %= MOD; s %= MOD; cout << ((t * K) % MOD + (((K * (K - 1) / 2) % MOD) * s)) % MOD << endl; }
[ "literal.number.change", "variable_declaration.array_dimensions.change" ]
731,539
731,540
u868089307
cpp
p02928
#include <bits/stdc++.h> using namespace std; #define MOD 1000000007 int main() { int n, k; cin >> n >> k; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } int sum1, sum2, ans; sum1 = sum2 = ans = 0; for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { if (a[i] > a[j]) { sum1++; } } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (a[i] < a[j]) { sum2++; } } } ans += k * sum1 % MOD; ans += (k * (k - 1) / 2) % MOD * sum2; ans %= MOD; cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define MOD 1000000007 int main() { int n; long long k; cin >> n >> k; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } long long sum1, sum2, ans; sum1 = sum2 = ans = 0; for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { if (a[i] > a[j]) { sum1++; } } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (a[i] < a[j]) { sum2++; } } } ans += k * sum1 % MOD; ans += (k * (k - 1) / 2) % MOD * sum2; ans %= MOD; cout << ans << endl; }
[ "variable_declaration.type.primitive.change", "variable_declaration.type.widen.change" ]
731,548
731,549
u863841238
cpp
p02928
#include <bits/stdc++.h> using namespace std; #define MOD 1000000007 int main() { int n, k; cin >> n >> k; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } int sum1, sum2, ans; sum1 = sum2 = ans = 0; for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { if (a[i] < a[j]) { sum1++; } } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (a[i] < a[j]) { sum2++; } } } ans += k * sum1 % MOD; ans += (k * (k - 1) / 2) % MOD * sum2; ans %= MOD; cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define MOD 1000000007 int main() { int n; long long k; cin >> n >> k; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } long long sum1, sum2, ans; sum1 = sum2 = ans = 0; for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { if (a[i] > a[j]) { sum1++; } } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (a[i] < a[j]) { sum2++; } } } ans += k * sum1 % MOD; ans += (k * (k - 1) / 2) % MOD * sum2; ans %= MOD; cout << ans << endl; }
[ "variable_declaration.type.primitive.change", "variable_declaration.type.widen.change", "misc.opposites", "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
731,550
731,549
u863841238
cpp
p02928
#include <cstdio> #include <iostream> using namespace std; typedef long long LL; const LL mod = 1e9 + 7; const int N = 2000; int a[N + 5]; int n, k; int main() { scanf("%d %d", &n, &k); 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]) ans = (ans + k) % mod; for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) if (a[i] > a[j]) ans = (ans + (k - 1) * k / 2 % mod) % mod; printf("%lld\n", ans); return 0; }
#include <cstdio> #include <iostream> using namespace std; typedef long long LL; const LL mod = 1e9 + 7; const int N = 2000; int a[N + 5]; int n, k; int main() { scanf("%d %d", &n, &k); 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]) ans = (ans + k) % mod; for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) if (a[i] > a[j]) ans = (ans + 1ll * (k - 1) * k / 2 % mod) % mod; printf("%lld\n", ans); return 0; }
[ "assignment.change" ]
731,551
731,552
u239970578
cpp
p02928
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) int main() { long long n, k, b = 0, c = 0, ans = 0, mod = 1000000007; cin >> n >> k; vector<long long> a(n); rep(i, n) cin >> a.at(i); rep(i, n) { for (int j = i; j < n; j++) { if (a.at(i) > a.at(j)) b++; } rep(j, i) { if (a.at(i) > a.at(j)) c++; } ans += (k * (k + 1) / 2) % mod * (b + c); ans -= c * k; ans += mod; ans %= mod; b = 0; c = 0; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) int main() { long long n, k, b = 0, c = 0, ans = 0, mod = 1000000007; cin >> n >> k; vector<long long> a(n); rep(i, n) cin >> a.at(i); rep(i, n) { for (int j = i; j < n; j++) { if (a.at(i) > a.at(j)) b++; } rep(j, i) { if (a.at(i) > a.at(j)) c++; } ans += (k * (k + 1) / 2) % mod * (b + c); ans -= c * k; ans += mod * 2000; ans %= mod; b = 0; c = 0; } cout << ans << endl; }
[ "assignment.change" ]
731,558
731,559
u422633119
cpp
p02928
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) int main() { long long n, k, b = 0, c = 0, ans = 0, mod = 1000000007; cin >> n >> k; vector<long long> a(n); rep(i, n) cin >> a.at(i); rep(i, n) { for (int j = i; j < n; j++) { if (a.at(i) > a.at(j)) b++; } rep(j, i) { if (a.at(i) > a.at(j)) c++; } ans += (k * (k + 1) / 2) % mod * (b + c); ans -= c; ans += mod; ans %= mod; b = 0; c = 0; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) int main() { long long n, k, b = 0, c = 0, ans = 0, mod = 1000000007; cin >> n >> k; vector<long long> a(n); rep(i, n) cin >> a.at(i); rep(i, n) { for (int j = i; j < n; j++) { if (a.at(i) > a.at(j)) b++; } rep(j, i) { if (a.at(i) > a.at(j)) c++; } ans += (k * (k + 1) / 2) % mod * (b + c); ans -= c * k; ans += mod * 2000; ans %= mod; b = 0; c = 0; } cout << ans << endl; }
[ "assignment.change" ]
731,560
731,559
u422633119
cpp
p02928
#include <bits/stdc++.h> #define ll long long #define f first #define s second #define pb push_back using namespace std; ll n, k, ans, mod = 1000000007, a[20005]; ll m[20005], f[20005]; int main() { cin >> n >> k; for (int i = 1; i <= n; i++) { cin >> a[i]; for (int j = 1; j < i; j++) { if (a[i] < a[j]) m[i]++; if (a[i] > a[j]) f[j]++; } } for (int i = 1; i <= n; i++) { ans += m[i] * ((k * (k + 1)) / 2); ans %= mod; k--; ans += f[i] * ((k * (k + 1)) / 2); ans %= mod; k++; } cout << ans; return 0; }
#include <bits/stdc++.h> #define ll long long #define f first #define s second #define pb push_back using namespace std; ll n, k, ans, mod = 1000000007, a[20005]; ll m[20005], f[20005]; int main() { cin >> n >> k; for (int i = 1; i <= n; i++) { cin >> a[i]; for (int j = 1; j < i; j++) { if (a[i] < a[j]) m[i]++; if (a[i] > a[j]) f[j]++; } } for (int i = 1; i <= n; i++) { ans += m[i] * ((k * (k + 1)) / 2 % mod); ans %= mod; k--; ans += f[i] * ((k * (k + 1)) / 2 % mod); ans %= mod; k++; } cout << ans; return 0; }
[ "assignment.change" ]
731,568
731,569
u178725037
cpp
p02928
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int(i) = (0); (i) < (int)(n); ++(i)) using ll = long long; using P = pair<int, int>; using namespace std; ll mod = 1e9 + 7; int main() { ll N, K; cin >> N >> K; vector<ll> A(N); rep(i, N) cin >> A[i]; // 中 ll ans = 0; rep(i, N) rep(j, N) { if (i < j and A[i] > A[j]) ans++; } ans *= K; ans %= mod; // 外 ll k = K * (K - 1) / 2; rep(i, N) { ll tmp = 0; rep(j, N) { if (A[i] > A[j]) tmp++; } ans += (tmp * k) % mod; ans %= mod; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int(i) = (0); (i) < (int)(n); ++(i)) using ll = long long; using P = pair<int, int>; using namespace std; ll mod = 1e9 + 7; int main() { ll N, K; cin >> N >> K; vector<ll> A(N); rep(i, N) cin >> A[i]; // 中 ll ans = 0; rep(i, N) rep(j, N) { if (i < j and A[i] > A[j]) ans++; } ans *= K; ans %= mod; // 外 ll k = K * (K - 1) / 2; k %= mod; rep(i, N) { ll tmp = 0; rep(j, N) { if (A[i] > A[j]) tmp++; } ans += (tmp * k) % mod; ans %= mod; } cout << ans << endl; }
[ "assignment.add" ]
731,599
731,600
u482544950
cpp