Submission #678199

#TimeUsernameProblemLanguageResultExecution timeMemory
678199stanislavpolynDiversity (CEOI21_diversity)C++17
4 / 100
8 ms1744 KiB
#include <bits/stdc++.h> #define fr(i, a, b) for (int i = (a); i <= (b); ++i) #define rf(i, a, b) for (int i = (a); i >= (b); --i) #define fe(x, y) for (auto& x : y) #define fi first #define se second #define pb push_back #define mp make_pair #define mt make_tuple #define all(x) (x).begin(), (x).end() #define pw(x) (1LL << (x)) #define sz(x) (int)(x).size() using namespace std; mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count()); //mt19937_64 rng(228); #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; template <typename T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; #define fbo find_by_order #define ook order_of_key template <typename T> bool umn(T& a, T b) { return a > b ? a = b, 1 : 0; } template <typename T> bool umx(T& a, T b) { return a < b ? a = b, 1 : 0; } using ll = long long; using ld = long double; using pii = pair<int, int>; using pll = pair<ll, ll>; template <typename T> using ve = vector<T>; int calc(ve<int> a) { int ans = 0; fr (i, 0, sz(a) - 1) { set<int> s; fr (j, i, sz(a) - 1) { s.insert(a[j]); ans += sz(s); } } return ans; } ll calc2(ve<int> a) { int total = 0; fe (x, a) total += x; ll ans = 0; int toLeft = 0; fr (i, 0, sz(a) - 1) { int toRight = total - toLeft - a[i]; ans += 1LL * total * (total + 1) / 2; ans -= 1LL * toLeft * (toLeft + 1) / 2; ans -= 1LL * toRight * (toRight + 1) / 2; toLeft += a[i]; } return ans; } const int N = 3e5 + 5; int n, q; int a[N]; int cnt[N]; int rnd(int l, int r) { return rng() % (r - l + 1) + l; } int solve(ve<int> a) { fe (x, a) cnt[x] = 0; fe (x, a) cnt[x]++; ve<pii> order; fe (x, a) { if (cnt[x]) { order.pb({cnt[x], x}); cnt[x] = 0; } } sort(all(order)); reverse(all(order)); deque<int> d; bool who = 0; fe (cur, order) { if (who == 0) d.push_front(cur.fi); else d.pb(cur.fi); who ^= 1; } ve<int> v; int now = 1; fe (x, d) { v.pb(x); } return calc2(v); } int main() { #ifdef LOCAL freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #else ios::sync_with_stdio(0); cin.tie(0); #endif cin >> n >> q; ve<int> v; fr (i, 1, n) { cin >> a[i]; v.pb(a[i]); } sort(all(v)); cout << solve(v) << "\n"; // int mn = 1e9; // do { // umn(mn, calc(v)); // } while (next_permutation(all(v))); // // cout << solve(v) << " " << mn << "\n"; // // do { // if (calc(v) == mn) { // cout << "v: "; // fe (x, v) cout << x << " "; // cout << "\n"; // } // } while (next_permutation(all(v))); return 0; }

Compilation message (stderr)

diversity.cpp: In function 'int solve(ve<int>)':
diversity.cpp:108:9: warning: unused variable 'now' [-Wunused-variable]
  108 |     int now = 1;
      |         ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...