Submission #696508

#TimeUsernameProblemLanguageResultExecution timeMemory
696508cig32Diversity (CEOI21_diversity)C++17
64 / 100
49 ms6756 KiB
#include "bits/stdc++.h" using namespace std; #define int long long const int MAXN = 2e5 + 10; const int MOD = 1e9 + 7; mt19937_64 rng((int)std::chrono::steady_clock::now().time_since_epoch().count()); int rnd(int x, int y) { int u = uniform_int_distribution<int>(x, y)(rng); return u; } int bm(int b, int p) { if(p==0) return 1 % MOD; int r = bm(b, p >> 1); if(p&1) return (((r*r) % MOD) * b) % MOD; return (r*r) % MOD; } int inv(int b) { return bm(b, MOD-2); } int fastlog(int x) { return (x == 0 ? -1 : 64 - __builtin_clzll(x) - 1); } void printcase(int i) { cout << "Case #" << i << ": "; } void solve(int tc) { int n, q; cin >> n >> q; int c = 300000; int freq[c+1]; for(int i=1; i<=c; i++) freq[i] = 0; for(int i=1; i<=n; i++) { int x;cin >> x;freq[x]++; } sort(freq+1, freq+c+1); int a[n+1]; int l=1,r=n,ct=0; deque<int> dq; stack<int> y; queue<int> x; for(int i=1;i<=c; i++) { if(freq[i]>0) { if(ct&1) { y.push(freq[i]); } else { x.push(freq[i]); } ct^=1; } } while(x.size()) { dq.push_back(x.front()); x.pop(); } while(y.size()) { dq.push_back(y.top()); y.pop(); } int m=dq.size(); int ans=0; int ws=0,rs=0; for(int i=m-1; i>=0; i--) { ans += dq[i] * ws - dq[i] * (i-1) * rs; ws += dq[i] * i, rs += dq[i]; } for(int i=0; i<m; i++) ans += dq[i] * (dq[i] + 1) / 2; cout << ans << "\n"; } int32_t main() { ios::sync_with_stdio(0); cin.tie(0); int t = 1; //cin >> t; for(int i=1; i<=t; i++) solve(i); }

Compilation message (stderr)

diversity.cpp: In function 'void solve(long long int)':
diversity.cpp:33:7: warning: unused variable 'a' [-Wunused-variable]
   33 |   int a[n+1];
      |       ^
diversity.cpp:34:7: warning: unused variable 'l' [-Wunused-variable]
   34 |   int l=1,r=n,ct=0;
      |       ^
diversity.cpp:34:11: warning: unused variable 'r' [-Wunused-variable]
   34 |   int l=1,r=n,ct=0;
      |           ^
#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...