Submission #718155

# Submission time Handle Problem Language Result Execution time Memory
718155 2023-04-03T13:04:46 Z mychecksedad Diversity (CEOI21_diversity) C++17
64 / 100
55 ms 8672 KB
/* Author : Mychecksdead */
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define MOD (1000000000+7)
#define MOD1 (998244353)
#define PI 3.1415926535
#define pb push_back
#define all(x) x.begin(), x.end()
const int N = 1e6+100, M = 1e5+10, K = 20;


int n, q, a[N];
vector<int> c(300005);
ll pref[N];
void solve(){
  cin >> n >> q;
  for(int i = 0; i < n; ++i){
    cin >> a[i];
    c[a[i]]++;
  }

  int l, r;
  cin >> l >> r;

  sort(all(c));

  deque<ll> Q; 

  bool b = 1;

  for(int i = 300004; i >= 1; --i){
    if(c[i] > 0){
      if(b)
        Q.push_front(c[i]);
      else
        Q.push_back(c[i]);
      b ^= 1;
    }
  }


  ll ans = 0;
  pref[0] = 0;
  ll m = Q.size();
  for(int i = 0; i < m; ++i) pref[i + 1] = pref[i] + Q[i];
  for(int i = 0; i < m; ++i){
    ans += (pref[m] - pref[i + 1]) * (pref[i]) + (pref[i]) * (Q[i]) + (Q[i]) * (pref[m] - pref[i + 1]) + (Q[i] + 1) * Q[i] / 2;
  }
  cout << ans;
}


int main(){
  cin.tie(0); ios::sync_with_stdio(0);
  int T = 1, aa;
  // cin >> T;aa=T;
  while(T--){
    // cout << "Case #" << aa-T << ": ";
    solve();
    cout << '\n';
  }
  return 0;
 
}

Compilation message

diversity.cpp: In function 'int main()':
diversity.cpp:56:14: warning: unused variable 'aa' [-Wunused-variable]
   56 |   int T = 1, aa;
      |              ^~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1492 KB Output is correct
2 Correct 5 ms 1492 KB Output is correct
3 Correct 5 ms 1492 KB Output is correct
4 Correct 5 ms 1492 KB Output is correct
5 Correct 6 ms 1492 KB Output is correct
6 Correct 5 ms 1492 KB Output is correct
7 Correct 5 ms 1492 KB Output is correct
8 Correct 5 ms 1492 KB Output is correct
9 Correct 7 ms 1492 KB Output is correct
10 Correct 6 ms 1492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1492 KB Output is correct
2 Correct 5 ms 1492 KB Output is correct
3 Correct 8 ms 1536 KB Output is correct
4 Correct 11 ms 2048 KB Output is correct
5 Correct 15 ms 2680 KB Output is correct
6 Correct 21 ms 3276 KB Output is correct
7 Correct 21 ms 3172 KB Output is correct
8 Correct 20 ms 3292 KB Output is correct
9 Correct 22 ms 3272 KB Output is correct
10 Correct 31 ms 3328 KB Output is correct
11 Correct 27 ms 3312 KB Output is correct
12 Correct 21 ms 3236 KB Output is correct
13 Correct 21 ms 3280 KB Output is correct
14 Correct 20 ms 3284 KB Output is correct
15 Correct 20 ms 3220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1492 KB Output is correct
2 Correct 5 ms 1492 KB Output is correct
3 Correct 8 ms 1536 KB Output is correct
4 Correct 11 ms 2048 KB Output is correct
5 Correct 15 ms 2680 KB Output is correct
6 Correct 21 ms 3276 KB Output is correct
7 Correct 21 ms 3172 KB Output is correct
8 Correct 20 ms 3292 KB Output is correct
9 Correct 22 ms 3272 KB Output is correct
10 Correct 31 ms 3328 KB Output is correct
11 Correct 27 ms 3312 KB Output is correct
12 Correct 21 ms 3236 KB Output is correct
13 Correct 21 ms 3280 KB Output is correct
14 Correct 20 ms 3284 KB Output is correct
15 Correct 20 ms 3220 KB Output is correct
16 Correct 6 ms 1492 KB Output is correct
17 Correct 5 ms 1492 KB Output is correct
18 Correct 8 ms 1552 KB Output is correct
19 Correct 10 ms 2156 KB Output is correct
20 Correct 18 ms 2804 KB Output is correct
21 Correct 32 ms 3444 KB Output is correct
22 Correct 22 ms 3460 KB Output is correct
23 Correct 24 ms 3468 KB Output is correct
24 Correct 24 ms 3412 KB Output is correct
25 Correct 22 ms 3400 KB Output is correct
26 Correct 22 ms 3456 KB Output is correct
27 Correct 23 ms 3464 KB Output is correct
28 Correct 21 ms 3400 KB Output is correct
29 Correct 23 ms 3364 KB Output is correct
30 Correct 22 ms 3412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1492 KB Output is correct
2 Correct 5 ms 1492 KB Output is correct
3 Correct 8 ms 1536 KB Output is correct
4 Correct 11 ms 2048 KB Output is correct
5 Correct 15 ms 2680 KB Output is correct
6 Correct 21 ms 3276 KB Output is correct
7 Correct 21 ms 3172 KB Output is correct
8 Correct 20 ms 3292 KB Output is correct
9 Correct 22 ms 3272 KB Output is correct
10 Correct 31 ms 3328 KB Output is correct
11 Correct 27 ms 3312 KB Output is correct
12 Correct 21 ms 3236 KB Output is correct
13 Correct 21 ms 3280 KB Output is correct
14 Correct 20 ms 3284 KB Output is correct
15 Correct 20 ms 3220 KB Output is correct
16 Correct 6 ms 1492 KB Output is correct
17 Correct 5 ms 1492 KB Output is correct
18 Correct 8 ms 1552 KB Output is correct
19 Correct 10 ms 2156 KB Output is correct
20 Correct 18 ms 2804 KB Output is correct
21 Correct 32 ms 3444 KB Output is correct
22 Correct 22 ms 3460 KB Output is correct
23 Correct 24 ms 3468 KB Output is correct
24 Correct 24 ms 3412 KB Output is correct
25 Correct 22 ms 3400 KB Output is correct
26 Correct 22 ms 3456 KB Output is correct
27 Correct 23 ms 3464 KB Output is correct
28 Correct 21 ms 3400 KB Output is correct
29 Correct 23 ms 3364 KB Output is correct
30 Correct 22 ms 3412 KB Output is correct
31 Correct 7 ms 1492 KB Output is correct
32 Correct 5 ms 1492 KB Output is correct
33 Correct 5 ms 1492 KB Output is correct
34 Correct 6 ms 1492 KB Output is correct
35 Correct 6 ms 1492 KB Output is correct
36 Correct 7 ms 1600 KB Output is correct
37 Correct 9 ms 1824 KB Output is correct
38 Correct 8 ms 1876 KB Output is correct
39 Correct 12 ms 2260 KB Output is correct
40 Correct 18 ms 3068 KB Output is correct
41 Correct 29 ms 3816 KB Output is correct
42 Correct 25 ms 3832 KB Output is correct
43 Correct 24 ms 3832 KB Output is correct
44 Correct 25 ms 3728 KB Output is correct
45 Correct 23 ms 3748 KB Output is correct
46 Correct 24 ms 3824 KB Output is correct
47 Correct 22 ms 3804 KB Output is correct
48 Correct 24 ms 3784 KB Output is correct
49 Correct 24 ms 3796 KB Output is correct
50 Correct 27 ms 3824 KB Output is correct
51 Correct 23 ms 3812 KB Output is correct
52 Correct 24 ms 3796 KB Output is correct
53 Correct 24 ms 3736 KB Output is correct
54 Correct 23 ms 3844 KB Output is correct
55 Correct 24 ms 3800 KB Output is correct
56 Correct 23 ms 3788 KB Output is correct
57 Correct 23 ms 3708 KB Output is correct
58 Correct 25 ms 3804 KB Output is correct
59 Correct 26 ms 3888 KB Output is correct
60 Correct 28 ms 3792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1492 KB Output is correct
2 Correct 5 ms 1492 KB Output is correct
3 Correct 5 ms 1492 KB Output is correct
4 Correct 5 ms 1492 KB Output is correct
5 Correct 6 ms 1492 KB Output is correct
6 Correct 5 ms 1492 KB Output is correct
7 Correct 5 ms 1492 KB Output is correct
8 Correct 5 ms 1492 KB Output is correct
9 Correct 7 ms 1492 KB Output is correct
10 Correct 6 ms 1492 KB Output is correct
11 Correct 6 ms 1492 KB Output is correct
12 Correct 5 ms 1492 KB Output is correct
13 Correct 8 ms 1536 KB Output is correct
14 Correct 11 ms 2048 KB Output is correct
15 Correct 15 ms 2680 KB Output is correct
16 Correct 21 ms 3276 KB Output is correct
17 Correct 21 ms 3172 KB Output is correct
18 Correct 20 ms 3292 KB Output is correct
19 Correct 22 ms 3272 KB Output is correct
20 Correct 31 ms 3328 KB Output is correct
21 Correct 27 ms 3312 KB Output is correct
22 Correct 21 ms 3236 KB Output is correct
23 Correct 21 ms 3280 KB Output is correct
24 Correct 20 ms 3284 KB Output is correct
25 Correct 20 ms 3220 KB Output is correct
26 Correct 6 ms 1492 KB Output is correct
27 Correct 5 ms 1492 KB Output is correct
28 Correct 8 ms 1552 KB Output is correct
29 Correct 10 ms 2156 KB Output is correct
30 Correct 18 ms 2804 KB Output is correct
31 Correct 32 ms 3444 KB Output is correct
32 Correct 22 ms 3460 KB Output is correct
33 Correct 24 ms 3468 KB Output is correct
34 Correct 24 ms 3412 KB Output is correct
35 Correct 22 ms 3400 KB Output is correct
36 Correct 22 ms 3456 KB Output is correct
37 Correct 23 ms 3464 KB Output is correct
38 Correct 21 ms 3400 KB Output is correct
39 Correct 23 ms 3364 KB Output is correct
40 Correct 22 ms 3412 KB Output is correct
41 Correct 7 ms 1492 KB Output is correct
42 Correct 5 ms 1492 KB Output is correct
43 Correct 5 ms 1492 KB Output is correct
44 Correct 6 ms 1492 KB Output is correct
45 Correct 6 ms 1492 KB Output is correct
46 Correct 7 ms 1600 KB Output is correct
47 Correct 9 ms 1824 KB Output is correct
48 Correct 8 ms 1876 KB Output is correct
49 Correct 12 ms 2260 KB Output is correct
50 Correct 18 ms 3068 KB Output is correct
51 Correct 29 ms 3816 KB Output is correct
52 Correct 25 ms 3832 KB Output is correct
53 Correct 24 ms 3832 KB Output is correct
54 Correct 25 ms 3728 KB Output is correct
55 Correct 23 ms 3748 KB Output is correct
56 Correct 24 ms 3824 KB Output is correct
57 Correct 22 ms 3804 KB Output is correct
58 Correct 24 ms 3784 KB Output is correct
59 Correct 24 ms 3796 KB Output is correct
60 Correct 27 ms 3824 KB Output is correct
61 Correct 23 ms 3812 KB Output is correct
62 Correct 24 ms 3796 KB Output is correct
63 Correct 24 ms 3736 KB Output is correct
64 Correct 23 ms 3844 KB Output is correct
65 Correct 24 ms 3800 KB Output is correct
66 Correct 23 ms 3788 KB Output is correct
67 Correct 23 ms 3708 KB Output is correct
68 Correct 25 ms 3804 KB Output is correct
69 Correct 26 ms 3888 KB Output is correct
70 Correct 28 ms 3792 KB Output is correct
71 Correct 11 ms 1936 KB Output is correct
72 Correct 9 ms 1968 KB Output is correct
73 Correct 9 ms 1876 KB Output is correct
74 Correct 8 ms 1912 KB Output is correct
75 Correct 9 ms 1944 KB Output is correct
76 Correct 12 ms 2388 KB Output is correct
77 Correct 13 ms 2384 KB Output is correct
78 Correct 13 ms 2448 KB Output is correct
79 Correct 12 ms 2368 KB Output is correct
80 Correct 14 ms 2408 KB Output is correct
81 Correct 20 ms 3288 KB Output is correct
82 Correct 19 ms 3276 KB Output is correct
83 Correct 22 ms 3328 KB Output is correct
84 Correct 19 ms 3376 KB Output is correct
85 Correct 19 ms 3392 KB Output is correct
86 Correct 22 ms 3556 KB Output is correct
87 Correct 20 ms 3660 KB Output is correct
88 Correct 21 ms 3620 KB Output is correct
89 Correct 26 ms 3616 KB Output is correct
90 Correct 22 ms 3556 KB Output is correct
91 Correct 42 ms 6004 KB Output is correct
92 Correct 29 ms 5932 KB Output is correct
93 Correct 33 ms 5988 KB Output is correct
94 Correct 34 ms 5964 KB Output is correct
95 Correct 30 ms 5920 KB Output is correct
96 Correct 49 ms 7748 KB Output is correct
97 Correct 55 ms 7756 KB Output is correct
98 Correct 35 ms 7756 KB Output is correct
99 Correct 38 ms 7776 KB Output is correct
100 Correct 36 ms 7780 KB Output is correct
101 Correct 35 ms 7740 KB Output is correct
102 Correct 36 ms 7760 KB Output is correct
103 Correct 33 ms 7744 KB Output is correct
104 Correct 33 ms 7696 KB Output is correct
105 Correct 36 ms 7772 KB Output is correct
106 Correct 38 ms 8508 KB Output is correct
107 Correct 37 ms 8584 KB Output is correct
108 Correct 37 ms 8600 KB Output is correct
109 Correct 36 ms 8524 KB Output is correct
110 Correct 35 ms 8612 KB Output is correct
111 Correct 37 ms 8520 KB Output is correct
112 Correct 47 ms 8536 KB Output is correct
113 Correct 45 ms 8672 KB Output is correct
114 Correct 34 ms 8584 KB Output is correct
115 Correct 36 ms 8564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1492 KB Output is correct
2 Correct 5 ms 1492 KB Output is correct
3 Correct 5 ms 1492 KB Output is correct
4 Correct 5 ms 1492 KB Output is correct
5 Correct 6 ms 1492 KB Output is correct
6 Correct 5 ms 1492 KB Output is correct
7 Correct 5 ms 1492 KB Output is correct
8 Correct 5 ms 1492 KB Output is correct
9 Correct 7 ms 1492 KB Output is correct
10 Correct 6 ms 1492 KB Output is correct
11 Correct 6 ms 1492 KB Output is correct
12 Correct 5 ms 1492 KB Output is correct
13 Correct 8 ms 1536 KB Output is correct
14 Correct 11 ms 2048 KB Output is correct
15 Correct 15 ms 2680 KB Output is correct
16 Correct 21 ms 3276 KB Output is correct
17 Correct 21 ms 3172 KB Output is correct
18 Correct 20 ms 3292 KB Output is correct
19 Correct 22 ms 3272 KB Output is correct
20 Correct 31 ms 3328 KB Output is correct
21 Correct 27 ms 3312 KB Output is correct
22 Correct 21 ms 3236 KB Output is correct
23 Correct 21 ms 3280 KB Output is correct
24 Correct 20 ms 3284 KB Output is correct
25 Correct 20 ms 3220 KB Output is correct
26 Correct 6 ms 1492 KB Output is correct
27 Correct 5 ms 1492 KB Output is correct
28 Correct 8 ms 1552 KB Output is correct
29 Correct 10 ms 2156 KB Output is correct
30 Correct 18 ms 2804 KB Output is correct
31 Correct 32 ms 3444 KB Output is correct
32 Correct 22 ms 3460 KB Output is correct
33 Correct 24 ms 3468 KB Output is correct
34 Correct 24 ms 3412 KB Output is correct
35 Correct 22 ms 3400 KB Output is correct
36 Correct 22 ms 3456 KB Output is correct
37 Correct 23 ms 3464 KB Output is correct
38 Correct 21 ms 3400 KB Output is correct
39 Correct 23 ms 3364 KB Output is correct
40 Correct 22 ms 3412 KB Output is correct
41 Correct 7 ms 1492 KB Output is correct
42 Correct 5 ms 1492 KB Output is correct
43 Correct 5 ms 1492 KB Output is correct
44 Correct 6 ms 1492 KB Output is correct
45 Correct 6 ms 1492 KB Output is correct
46 Correct 7 ms 1600 KB Output is correct
47 Correct 9 ms 1824 KB Output is correct
48 Correct 8 ms 1876 KB Output is correct
49 Correct 12 ms 2260 KB Output is correct
50 Correct 18 ms 3068 KB Output is correct
51 Correct 29 ms 3816 KB Output is correct
52 Correct 25 ms 3832 KB Output is correct
53 Correct 24 ms 3832 KB Output is correct
54 Correct 25 ms 3728 KB Output is correct
55 Correct 23 ms 3748 KB Output is correct
56 Correct 24 ms 3824 KB Output is correct
57 Correct 22 ms 3804 KB Output is correct
58 Correct 24 ms 3784 KB Output is correct
59 Correct 24 ms 3796 KB Output is correct
60 Correct 27 ms 3824 KB Output is correct
61 Correct 23 ms 3812 KB Output is correct
62 Correct 24 ms 3796 KB Output is correct
63 Correct 24 ms 3736 KB Output is correct
64 Correct 23 ms 3844 KB Output is correct
65 Correct 24 ms 3800 KB Output is correct
66 Correct 23 ms 3788 KB Output is correct
67 Correct 23 ms 3708 KB Output is correct
68 Correct 25 ms 3804 KB Output is correct
69 Correct 26 ms 3888 KB Output is correct
70 Correct 28 ms 3792 KB Output is correct
71 Correct 11 ms 1936 KB Output is correct
72 Correct 9 ms 1968 KB Output is correct
73 Correct 9 ms 1876 KB Output is correct
74 Correct 8 ms 1912 KB Output is correct
75 Correct 9 ms 1944 KB Output is correct
76 Correct 12 ms 2388 KB Output is correct
77 Correct 13 ms 2384 KB Output is correct
78 Correct 13 ms 2448 KB Output is correct
79 Correct 12 ms 2368 KB Output is correct
80 Correct 14 ms 2408 KB Output is correct
81 Correct 20 ms 3288 KB Output is correct
82 Correct 19 ms 3276 KB Output is correct
83 Correct 22 ms 3328 KB Output is correct
84 Correct 19 ms 3376 KB Output is correct
85 Correct 19 ms 3392 KB Output is correct
86 Correct 22 ms 3556 KB Output is correct
87 Correct 20 ms 3660 KB Output is correct
88 Correct 21 ms 3620 KB Output is correct
89 Correct 26 ms 3616 KB Output is correct
90 Correct 22 ms 3556 KB Output is correct
91 Correct 42 ms 6004 KB Output is correct
92 Correct 29 ms 5932 KB Output is correct
93 Correct 33 ms 5988 KB Output is correct
94 Correct 34 ms 5964 KB Output is correct
95 Correct 30 ms 5920 KB Output is correct
96 Correct 49 ms 7748 KB Output is correct
97 Correct 55 ms 7756 KB Output is correct
98 Correct 35 ms 7756 KB Output is correct
99 Correct 38 ms 7776 KB Output is correct
100 Correct 36 ms 7780 KB Output is correct
101 Correct 35 ms 7740 KB Output is correct
102 Correct 36 ms 7760 KB Output is correct
103 Correct 33 ms 7744 KB Output is correct
104 Correct 33 ms 7696 KB Output is correct
105 Correct 36 ms 7772 KB Output is correct
106 Correct 38 ms 8508 KB Output is correct
107 Correct 37 ms 8584 KB Output is correct
108 Correct 37 ms 8600 KB Output is correct
109 Correct 36 ms 8524 KB Output is correct
110 Correct 35 ms 8612 KB Output is correct
111 Correct 37 ms 8520 KB Output is correct
112 Correct 47 ms 8536 KB Output is correct
113 Correct 45 ms 8672 KB Output is correct
114 Correct 34 ms 8584 KB Output is correct
115 Correct 36 ms 8564 KB Output is correct
116 Incorrect 6 ms 1620 KB Output isn't correct
117 Halted 0 ms 0 KB -