Submission #1125320

#TimeUsernameProblemLanguageResultExecution timeMemory
1125320Peter2017Diversity (CEOI21_diversity)C++20
64 / 100
32 ms4604 KiB
#include <bits/stdc++.h> #define fi first #define se second #define ll long long #define pii pair<int,int> #define MASK(i) (1LL << (i)) #define BIT(x, i) (((x) >> (i)) & 1) #define mem(a, b) memset(a, b, sizeof(a)) #define name "test" using namespace std; const int N = 3e5 + 5; const int mod = 1e9 + 7; template <typename T1, typename T2> bool maxi(T1 &a, T2 b){if (a < b){a = b; return 1;} return 0;} template <typename T1, typename T2> bool mini(T1 &a, T2 b){if (a > b){a = b; return 1;} return 0;} int n; int q; int a[N]; int L[N]; int R[N]; int cnt[N]; deque<int> dq; vector<int> value; void load(){ cin.tie(0)->sync_with_stdio(0); if (fopen(name".inp", "r")){ freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); } } void input(){ cin >> n >> q; for (int i = 1; i <= n; i++){ cin >> a[i]; cnt[a[i]]++; } for (int i = 1; i <= q; i++) cin >> L[i] >> R[i]; } ll cal(ll n){ return n * (n + 1) / 2; } void solve(){ int MAX = 3e5; for (int i = MAX; i >= 1; i--) if (cnt[i]) value.push_back(cnt[i]); sort(value.begin(), value.end(), greater<int>()); bool type = 0; for (int x : value){ if (type == 0) dq.push_front(x); else dq.push_back(x); type ^= 1; } value.clear(); while (dq.size()){ value.push_back(dq.front()); dq.pop_front(); } ll ans = 0; int sum = n; for (int x : value){ for (int j = 1; j <= x; j++){ if (j == 1) ans += 1LL * (n - sum + 1) * sum; else ans += sum; sum--; } } cout << ans; } int main(){ load(); input(); solve(); }

Compilation message (stderr)

diversity.cpp: In function 'void load()':
diversity.cpp:31:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |         freopen(name".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
diversity.cpp:32:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |         freopen(name".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#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...