Submission #696508

# Submission time Handle Problem Language Result Execution time Memory
696508 2023-02-06T16:11:35 Z cig32 Diversity (CEOI21_diversity) C++17
64 / 100
49 ms 6756 KB
#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

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 time Memory Grader output
1 Correct 8 ms 2644 KB Output is correct
2 Correct 6 ms 2644 KB Output is correct
3 Correct 5 ms 2644 KB Output is correct
4 Correct 5 ms 2644 KB Output is correct
5 Correct 6 ms 2632 KB Output is correct
6 Correct 6 ms 2624 KB Output is correct
7 Correct 6 ms 2628 KB Output is correct
8 Correct 5 ms 2644 KB Output is correct
9 Correct 5 ms 2644 KB Output is correct
10 Correct 5 ms 2644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 2644 KB Output is correct
2 Correct 5 ms 2632 KB Output is correct
3 Correct 6 ms 2644 KB Output is correct
4 Correct 14 ms 2772 KB Output is correct
5 Correct 15 ms 3060 KB Output is correct
6 Correct 20 ms 3296 KB Output is correct
7 Correct 18 ms 3276 KB Output is correct
8 Correct 19 ms 3284 KB Output is correct
9 Correct 19 ms 3292 KB Output is correct
10 Correct 20 ms 3320 KB Output is correct
11 Correct 23 ms 3288 KB Output is correct
12 Correct 20 ms 3324 KB Output is correct
13 Correct 20 ms 3284 KB Output is correct
14 Correct 22 ms 3268 KB Output is correct
15 Correct 22 ms 3288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 2644 KB Output is correct
2 Correct 5 ms 2632 KB Output is correct
3 Correct 6 ms 2644 KB Output is correct
4 Correct 14 ms 2772 KB Output is correct
5 Correct 15 ms 3060 KB Output is correct
6 Correct 20 ms 3296 KB Output is correct
7 Correct 18 ms 3276 KB Output is correct
8 Correct 19 ms 3284 KB Output is correct
9 Correct 19 ms 3292 KB Output is correct
10 Correct 20 ms 3320 KB Output is correct
11 Correct 23 ms 3288 KB Output is correct
12 Correct 20 ms 3324 KB Output is correct
13 Correct 20 ms 3284 KB Output is correct
14 Correct 22 ms 3268 KB Output is correct
15 Correct 22 ms 3288 KB Output is correct
16 Correct 6 ms 2560 KB Output is correct
17 Correct 5 ms 2644 KB Output is correct
18 Correct 6 ms 2644 KB Output is correct
19 Correct 11 ms 2940 KB Output is correct
20 Correct 15 ms 3156 KB Output is correct
21 Correct 26 ms 3412 KB Output is correct
22 Correct 30 ms 3444 KB Output is correct
23 Correct 20 ms 3420 KB Output is correct
24 Correct 21 ms 3408 KB Output is correct
25 Correct 21 ms 3424 KB Output is correct
26 Correct 21 ms 3424 KB Output is correct
27 Correct 22 ms 3420 KB Output is correct
28 Correct 20 ms 3296 KB Output is correct
29 Correct 21 ms 3292 KB Output is correct
30 Correct 23 ms 3400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 2644 KB Output is correct
2 Correct 5 ms 2632 KB Output is correct
3 Correct 6 ms 2644 KB Output is correct
4 Correct 14 ms 2772 KB Output is correct
5 Correct 15 ms 3060 KB Output is correct
6 Correct 20 ms 3296 KB Output is correct
7 Correct 18 ms 3276 KB Output is correct
8 Correct 19 ms 3284 KB Output is correct
9 Correct 19 ms 3292 KB Output is correct
10 Correct 20 ms 3320 KB Output is correct
11 Correct 23 ms 3288 KB Output is correct
12 Correct 20 ms 3324 KB Output is correct
13 Correct 20 ms 3284 KB Output is correct
14 Correct 22 ms 3268 KB Output is correct
15 Correct 22 ms 3288 KB Output is correct
16 Correct 6 ms 2560 KB Output is correct
17 Correct 5 ms 2644 KB Output is correct
18 Correct 6 ms 2644 KB Output is correct
19 Correct 11 ms 2940 KB Output is correct
20 Correct 15 ms 3156 KB Output is correct
21 Correct 26 ms 3412 KB Output is correct
22 Correct 30 ms 3444 KB Output is correct
23 Correct 20 ms 3420 KB Output is correct
24 Correct 21 ms 3408 KB Output is correct
25 Correct 21 ms 3424 KB Output is correct
26 Correct 21 ms 3424 KB Output is correct
27 Correct 22 ms 3420 KB Output is correct
28 Correct 20 ms 3296 KB Output is correct
29 Correct 21 ms 3292 KB Output is correct
30 Correct 23 ms 3400 KB Output is correct
31 Correct 5 ms 2644 KB Output is correct
32 Correct 6 ms 2644 KB Output is correct
33 Correct 6 ms 2644 KB Output is correct
34 Correct 6 ms 2644 KB Output is correct
35 Correct 6 ms 2636 KB Output is correct
36 Correct 6 ms 2644 KB Output is correct
37 Correct 8 ms 2852 KB Output is correct
38 Correct 8 ms 2772 KB Output is correct
39 Correct 12 ms 3036 KB Output is correct
40 Correct 17 ms 3428 KB Output is correct
41 Correct 22 ms 3792 KB Output is correct
42 Correct 23 ms 3808 KB Output is correct
43 Correct 25 ms 3780 KB Output is correct
44 Correct 23 ms 3796 KB Output is correct
45 Correct 24 ms 3804 KB Output is correct
46 Correct 23 ms 3800 KB Output is correct
47 Correct 22 ms 3804 KB Output is correct
48 Correct 22 ms 3796 KB Output is correct
49 Correct 22 ms 3804 KB Output is correct
50 Correct 31 ms 3784 KB Output is correct
51 Correct 23 ms 3792 KB Output is correct
52 Correct 23 ms 3792 KB Output is correct
53 Correct 24 ms 3804 KB Output is correct
54 Correct 24 ms 3792 KB Output is correct
55 Correct 22 ms 3808 KB Output is correct
56 Correct 29 ms 3740 KB Output is correct
57 Correct 25 ms 3788 KB Output is correct
58 Correct 22 ms 3800 KB Output is correct
59 Correct 30 ms 3784 KB Output is correct
60 Correct 22 ms 3800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 2644 KB Output is correct
2 Correct 6 ms 2644 KB Output is correct
3 Correct 5 ms 2644 KB Output is correct
4 Correct 5 ms 2644 KB Output is correct
5 Correct 6 ms 2632 KB Output is correct
6 Correct 6 ms 2624 KB Output is correct
7 Correct 6 ms 2628 KB Output is correct
8 Correct 5 ms 2644 KB Output is correct
9 Correct 5 ms 2644 KB Output is correct
10 Correct 5 ms 2644 KB Output is correct
11 Correct 8 ms 2644 KB Output is correct
12 Correct 5 ms 2632 KB Output is correct
13 Correct 6 ms 2644 KB Output is correct
14 Correct 14 ms 2772 KB Output is correct
15 Correct 15 ms 3060 KB Output is correct
16 Correct 20 ms 3296 KB Output is correct
17 Correct 18 ms 3276 KB Output is correct
18 Correct 19 ms 3284 KB Output is correct
19 Correct 19 ms 3292 KB Output is correct
20 Correct 20 ms 3320 KB Output is correct
21 Correct 23 ms 3288 KB Output is correct
22 Correct 20 ms 3324 KB Output is correct
23 Correct 20 ms 3284 KB Output is correct
24 Correct 22 ms 3268 KB Output is correct
25 Correct 22 ms 3288 KB Output is correct
26 Correct 6 ms 2560 KB Output is correct
27 Correct 5 ms 2644 KB Output is correct
28 Correct 6 ms 2644 KB Output is correct
29 Correct 11 ms 2940 KB Output is correct
30 Correct 15 ms 3156 KB Output is correct
31 Correct 26 ms 3412 KB Output is correct
32 Correct 30 ms 3444 KB Output is correct
33 Correct 20 ms 3420 KB Output is correct
34 Correct 21 ms 3408 KB Output is correct
35 Correct 21 ms 3424 KB Output is correct
36 Correct 21 ms 3424 KB Output is correct
37 Correct 22 ms 3420 KB Output is correct
38 Correct 20 ms 3296 KB Output is correct
39 Correct 21 ms 3292 KB Output is correct
40 Correct 23 ms 3400 KB Output is correct
41 Correct 5 ms 2644 KB Output is correct
42 Correct 6 ms 2644 KB Output is correct
43 Correct 6 ms 2644 KB Output is correct
44 Correct 6 ms 2644 KB Output is correct
45 Correct 6 ms 2636 KB Output is correct
46 Correct 6 ms 2644 KB Output is correct
47 Correct 8 ms 2852 KB Output is correct
48 Correct 8 ms 2772 KB Output is correct
49 Correct 12 ms 3036 KB Output is correct
50 Correct 17 ms 3428 KB Output is correct
51 Correct 22 ms 3792 KB Output is correct
52 Correct 23 ms 3808 KB Output is correct
53 Correct 25 ms 3780 KB Output is correct
54 Correct 23 ms 3796 KB Output is correct
55 Correct 24 ms 3804 KB Output is correct
56 Correct 23 ms 3800 KB Output is correct
57 Correct 22 ms 3804 KB Output is correct
58 Correct 22 ms 3796 KB Output is correct
59 Correct 22 ms 3804 KB Output is correct
60 Correct 31 ms 3784 KB Output is correct
61 Correct 23 ms 3792 KB Output is correct
62 Correct 23 ms 3792 KB Output is correct
63 Correct 24 ms 3804 KB Output is correct
64 Correct 24 ms 3792 KB Output is correct
65 Correct 22 ms 3808 KB Output is correct
66 Correct 29 ms 3740 KB Output is correct
67 Correct 25 ms 3788 KB Output is correct
68 Correct 22 ms 3800 KB Output is correct
69 Correct 30 ms 3784 KB Output is correct
70 Correct 22 ms 3800 KB Output is correct
71 Correct 12 ms 2908 KB Output is correct
72 Correct 9 ms 2900 KB Output is correct
73 Correct 9 ms 2900 KB Output is correct
74 Correct 9 ms 2900 KB Output is correct
75 Correct 10 ms 2884 KB Output is correct
76 Correct 13 ms 3148 KB Output is correct
77 Correct 12 ms 3160 KB Output is correct
78 Correct 12 ms 3140 KB Output is correct
79 Correct 13 ms 3136 KB Output is correct
80 Correct 13 ms 3156 KB Output is correct
81 Correct 22 ms 3672 KB Output is correct
82 Correct 19 ms 3616 KB Output is correct
83 Correct 18 ms 3664 KB Output is correct
84 Correct 18 ms 3620 KB Output is correct
85 Correct 19 ms 3660 KB Output is correct
86 Correct 20 ms 3788 KB Output is correct
87 Correct 20 ms 3808 KB Output is correct
88 Correct 21 ms 3804 KB Output is correct
89 Correct 20 ms 3784 KB Output is correct
90 Correct 21 ms 3796 KB Output is correct
91 Correct 30 ms 4812 KB Output is correct
92 Correct 30 ms 5212 KB Output is correct
93 Correct 29 ms 5192 KB Output is correct
94 Correct 30 ms 5152 KB Output is correct
95 Correct 35 ms 5236 KB Output is correct
96 Correct 34 ms 6224 KB Output is correct
97 Correct 34 ms 6220 KB Output is correct
98 Correct 38 ms 6220 KB Output is correct
99 Correct 40 ms 6228 KB Output is correct
100 Correct 35 ms 6232 KB Output is correct
101 Correct 49 ms 6220 KB Output is correct
102 Correct 41 ms 6220 KB Output is correct
103 Correct 37 ms 6220 KB Output is correct
104 Correct 36 ms 6220 KB Output is correct
105 Correct 39 ms 6228 KB Output is correct
106 Correct 39 ms 6756 KB Output is correct
107 Correct 39 ms 6732 KB Output is correct
108 Correct 35 ms 6740 KB Output is correct
109 Correct 38 ms 6740 KB Output is correct
110 Correct 39 ms 6732 KB Output is correct
111 Correct 41 ms 6744 KB Output is correct
112 Correct 37 ms 6732 KB Output is correct
113 Correct 38 ms 6740 KB Output is correct
114 Correct 36 ms 6748 KB Output is correct
115 Correct 35 ms 6740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 2644 KB Output is correct
2 Correct 6 ms 2644 KB Output is correct
3 Correct 5 ms 2644 KB Output is correct
4 Correct 5 ms 2644 KB Output is correct
5 Correct 6 ms 2632 KB Output is correct
6 Correct 6 ms 2624 KB Output is correct
7 Correct 6 ms 2628 KB Output is correct
8 Correct 5 ms 2644 KB Output is correct
9 Correct 5 ms 2644 KB Output is correct
10 Correct 5 ms 2644 KB Output is correct
11 Correct 8 ms 2644 KB Output is correct
12 Correct 5 ms 2632 KB Output is correct
13 Correct 6 ms 2644 KB Output is correct
14 Correct 14 ms 2772 KB Output is correct
15 Correct 15 ms 3060 KB Output is correct
16 Correct 20 ms 3296 KB Output is correct
17 Correct 18 ms 3276 KB Output is correct
18 Correct 19 ms 3284 KB Output is correct
19 Correct 19 ms 3292 KB Output is correct
20 Correct 20 ms 3320 KB Output is correct
21 Correct 23 ms 3288 KB Output is correct
22 Correct 20 ms 3324 KB Output is correct
23 Correct 20 ms 3284 KB Output is correct
24 Correct 22 ms 3268 KB Output is correct
25 Correct 22 ms 3288 KB Output is correct
26 Correct 6 ms 2560 KB Output is correct
27 Correct 5 ms 2644 KB Output is correct
28 Correct 6 ms 2644 KB Output is correct
29 Correct 11 ms 2940 KB Output is correct
30 Correct 15 ms 3156 KB Output is correct
31 Correct 26 ms 3412 KB Output is correct
32 Correct 30 ms 3444 KB Output is correct
33 Correct 20 ms 3420 KB Output is correct
34 Correct 21 ms 3408 KB Output is correct
35 Correct 21 ms 3424 KB Output is correct
36 Correct 21 ms 3424 KB Output is correct
37 Correct 22 ms 3420 KB Output is correct
38 Correct 20 ms 3296 KB Output is correct
39 Correct 21 ms 3292 KB Output is correct
40 Correct 23 ms 3400 KB Output is correct
41 Correct 5 ms 2644 KB Output is correct
42 Correct 6 ms 2644 KB Output is correct
43 Correct 6 ms 2644 KB Output is correct
44 Correct 6 ms 2644 KB Output is correct
45 Correct 6 ms 2636 KB Output is correct
46 Correct 6 ms 2644 KB Output is correct
47 Correct 8 ms 2852 KB Output is correct
48 Correct 8 ms 2772 KB Output is correct
49 Correct 12 ms 3036 KB Output is correct
50 Correct 17 ms 3428 KB Output is correct
51 Correct 22 ms 3792 KB Output is correct
52 Correct 23 ms 3808 KB Output is correct
53 Correct 25 ms 3780 KB Output is correct
54 Correct 23 ms 3796 KB Output is correct
55 Correct 24 ms 3804 KB Output is correct
56 Correct 23 ms 3800 KB Output is correct
57 Correct 22 ms 3804 KB Output is correct
58 Correct 22 ms 3796 KB Output is correct
59 Correct 22 ms 3804 KB Output is correct
60 Correct 31 ms 3784 KB Output is correct
61 Correct 23 ms 3792 KB Output is correct
62 Correct 23 ms 3792 KB Output is correct
63 Correct 24 ms 3804 KB Output is correct
64 Correct 24 ms 3792 KB Output is correct
65 Correct 22 ms 3808 KB Output is correct
66 Correct 29 ms 3740 KB Output is correct
67 Correct 25 ms 3788 KB Output is correct
68 Correct 22 ms 3800 KB Output is correct
69 Correct 30 ms 3784 KB Output is correct
70 Correct 22 ms 3800 KB Output is correct
71 Correct 12 ms 2908 KB Output is correct
72 Correct 9 ms 2900 KB Output is correct
73 Correct 9 ms 2900 KB Output is correct
74 Correct 9 ms 2900 KB Output is correct
75 Correct 10 ms 2884 KB Output is correct
76 Correct 13 ms 3148 KB Output is correct
77 Correct 12 ms 3160 KB Output is correct
78 Correct 12 ms 3140 KB Output is correct
79 Correct 13 ms 3136 KB Output is correct
80 Correct 13 ms 3156 KB Output is correct
81 Correct 22 ms 3672 KB Output is correct
82 Correct 19 ms 3616 KB Output is correct
83 Correct 18 ms 3664 KB Output is correct
84 Correct 18 ms 3620 KB Output is correct
85 Correct 19 ms 3660 KB Output is correct
86 Correct 20 ms 3788 KB Output is correct
87 Correct 20 ms 3808 KB Output is correct
88 Correct 21 ms 3804 KB Output is correct
89 Correct 20 ms 3784 KB Output is correct
90 Correct 21 ms 3796 KB Output is correct
91 Correct 30 ms 4812 KB Output is correct
92 Correct 30 ms 5212 KB Output is correct
93 Correct 29 ms 5192 KB Output is correct
94 Correct 30 ms 5152 KB Output is correct
95 Correct 35 ms 5236 KB Output is correct
96 Correct 34 ms 6224 KB Output is correct
97 Correct 34 ms 6220 KB Output is correct
98 Correct 38 ms 6220 KB Output is correct
99 Correct 40 ms 6228 KB Output is correct
100 Correct 35 ms 6232 KB Output is correct
101 Correct 49 ms 6220 KB Output is correct
102 Correct 41 ms 6220 KB Output is correct
103 Correct 37 ms 6220 KB Output is correct
104 Correct 36 ms 6220 KB Output is correct
105 Correct 39 ms 6228 KB Output is correct
106 Correct 39 ms 6756 KB Output is correct
107 Correct 39 ms 6732 KB Output is correct
108 Correct 35 ms 6740 KB Output is correct
109 Correct 38 ms 6740 KB Output is correct
110 Correct 39 ms 6732 KB Output is correct
111 Correct 41 ms 6744 KB Output is correct
112 Correct 37 ms 6732 KB Output is correct
113 Correct 38 ms 6740 KB Output is correct
114 Correct 36 ms 6748 KB Output is correct
115 Correct 35 ms 6740 KB Output is correct
116 Incorrect 9 ms 2764 KB Output isn't correct
117 Halted 0 ms 0 KB -