Submission #827326

# Submission time Handle Problem Language Result Execution time Memory
827326 2023-08-16T11:04:53 Z BERNARB01 Diversity (CEOI21_diversity) C++17
64 / 100
72 ms 8760 KB
/**
 *    author:  BERNARD B.01
**/
#include <bits/stdc++.h>

using namespace std;

#ifdef B01
#include "deb.h"
#else
#define deb(...)
#endif

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, q;
  cin >> n >> q;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  const int N = (int) 3e5 + 1;
  vector<int> cnt(N);
  for (int i = 0; i < n; i++) {
    cnt[a[i]]++;
  }
  vector<pair<int, int>> freqs;
  for (int i = 0; i < N; i++) {
    if (cnt[i] > 0) {
      freqs.emplace_back(cnt[i], i);
    }
  }
  sort(freqs.rbegin(), freqs.rend());
  deque<int> d;
  for (int i = 0; i < (int) freqs.size(); i++) {
    if (i & 1) {
      d.push_front(freqs[i].second);
    } else {
      d.push_back(freqs[i].second);
    }
  }
  vector<int> pos(n);
  for (int i = 0; i < (int) freqs.size(); i++) {
    pos[d[i]] = i;
  }
  sort(a.begin(), a.end(), [&](int i, int j) {
    return pos[i] < pos[j];
  });
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    if (i == 0 || a[i] != a[i - 1]) {
      ans += (long long) (i + 1) * (n - i);
    } else {
      ans += (n - i);
    }
  }
  while (q--) {
    int l, r;
    cin >> l >> r;
    --l; --r;
    cout << ans << '\n';
  }
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1492 KB Output is correct
2 Correct 1 ms 1492 KB Output is correct
3 Correct 1 ms 1492 KB Output is correct
4 Correct 1 ms 1492 KB Output is correct
5 Correct 1 ms 1492 KB Output is correct
6 Correct 1 ms 1492 KB Output is correct
7 Correct 1 ms 1492 KB Output is correct
8 Correct 1 ms 1468 KB Output is correct
9 Correct 2 ms 1492 KB Output is correct
10 Correct 1 ms 1472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1492 KB Output is correct
2 Correct 1 ms 1492 KB Output is correct
3 Correct 2 ms 1492 KB Output is correct
4 Correct 8 ms 2388 KB Output is correct
5 Correct 14 ms 3404 KB Output is correct
6 Correct 22 ms 4472 KB Output is correct
7 Correct 20 ms 4436 KB Output is correct
8 Correct 22 ms 4424 KB Output is correct
9 Correct 26 ms 4436 KB Output is correct
10 Correct 22 ms 4468 KB Output is correct
11 Correct 22 ms 4424 KB Output is correct
12 Correct 22 ms 4432 KB Output is correct
13 Correct 22 ms 4436 KB Output is correct
14 Correct 21 ms 4428 KB Output is correct
15 Correct 22 ms 4432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1492 KB Output is correct
2 Correct 1 ms 1492 KB Output is correct
3 Correct 2 ms 1492 KB Output is correct
4 Correct 8 ms 2388 KB Output is correct
5 Correct 14 ms 3404 KB Output is correct
6 Correct 22 ms 4472 KB Output is correct
7 Correct 20 ms 4436 KB Output is correct
8 Correct 22 ms 4424 KB Output is correct
9 Correct 26 ms 4436 KB Output is correct
10 Correct 22 ms 4468 KB Output is correct
11 Correct 22 ms 4424 KB Output is correct
12 Correct 22 ms 4432 KB Output is correct
13 Correct 22 ms 4436 KB Output is correct
14 Correct 21 ms 4428 KB Output is correct
15 Correct 22 ms 4432 KB Output is correct
16 Correct 1 ms 1492 KB Output is correct
17 Correct 1 ms 1492 KB Output is correct
18 Correct 2 ms 1492 KB Output is correct
19 Correct 9 ms 2508 KB Output is correct
20 Correct 16 ms 3540 KB Output is correct
21 Correct 24 ms 4564 KB Output is correct
22 Correct 24 ms 4556 KB Output is correct
23 Correct 26 ms 4688 KB Output is correct
24 Correct 24 ms 4548 KB Output is correct
25 Correct 24 ms 4564 KB Output is correct
26 Correct 25 ms 4564 KB Output is correct
27 Correct 26 ms 4560 KB Output is correct
28 Correct 23 ms 4560 KB Output is correct
29 Correct 23 ms 4556 KB Output is correct
30 Correct 24 ms 4564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1492 KB Output is correct
2 Correct 1 ms 1492 KB Output is correct
3 Correct 2 ms 1492 KB Output is correct
4 Correct 8 ms 2388 KB Output is correct
5 Correct 14 ms 3404 KB Output is correct
6 Correct 22 ms 4472 KB Output is correct
7 Correct 20 ms 4436 KB Output is correct
8 Correct 22 ms 4424 KB Output is correct
9 Correct 26 ms 4436 KB Output is correct
10 Correct 22 ms 4468 KB Output is correct
11 Correct 22 ms 4424 KB Output is correct
12 Correct 22 ms 4432 KB Output is correct
13 Correct 22 ms 4436 KB Output is correct
14 Correct 21 ms 4428 KB Output is correct
15 Correct 22 ms 4432 KB Output is correct
16 Correct 1 ms 1492 KB Output is correct
17 Correct 1 ms 1492 KB Output is correct
18 Correct 2 ms 1492 KB Output is correct
19 Correct 9 ms 2508 KB Output is correct
20 Correct 16 ms 3540 KB Output is correct
21 Correct 24 ms 4564 KB Output is correct
22 Correct 24 ms 4556 KB Output is correct
23 Correct 26 ms 4688 KB Output is correct
24 Correct 24 ms 4548 KB Output is correct
25 Correct 24 ms 4564 KB Output is correct
26 Correct 25 ms 4564 KB Output is correct
27 Correct 26 ms 4560 KB Output is correct
28 Correct 23 ms 4560 KB Output is correct
29 Correct 23 ms 4556 KB Output is correct
30 Correct 24 ms 4564 KB Output is correct
31 Correct 2 ms 1492 KB Output is correct
32 Correct 1 ms 1492 KB Output is correct
33 Correct 1 ms 1492 KB Output is correct
34 Correct 2 ms 1620 KB Output is correct
35 Correct 2 ms 1620 KB Output is correct
36 Correct 2 ms 1620 KB Output is correct
37 Correct 6 ms 2004 KB Output is correct
38 Correct 6 ms 1996 KB Output is correct
39 Correct 13 ms 2644 KB Output is correct
40 Correct 21 ms 3824 KB Output is correct
41 Correct 32 ms 4944 KB Output is correct
42 Correct 32 ms 4940 KB Output is correct
43 Correct 32 ms 4948 KB Output is correct
44 Correct 31 ms 4948 KB Output is correct
45 Correct 34 ms 5012 KB Output is correct
46 Correct 31 ms 4948 KB Output is correct
47 Correct 35 ms 4940 KB Output is correct
48 Correct 34 ms 4992 KB Output is correct
49 Correct 31 ms 4948 KB Output is correct
50 Correct 31 ms 4948 KB Output is correct
51 Correct 31 ms 4948 KB Output is correct
52 Correct 32 ms 4940 KB Output is correct
53 Correct 32 ms 4948 KB Output is correct
54 Correct 31 ms 4952 KB Output is correct
55 Correct 32 ms 5016 KB Output is correct
56 Correct 36 ms 4996 KB Output is correct
57 Correct 31 ms 4944 KB Output is correct
58 Correct 32 ms 4992 KB Output is correct
59 Correct 32 ms 4952 KB Output is correct
60 Correct 31 ms 4932 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1492 KB Output is correct
2 Correct 1 ms 1492 KB Output is correct
3 Correct 1 ms 1492 KB Output is correct
4 Correct 1 ms 1492 KB Output is correct
5 Correct 1 ms 1492 KB Output is correct
6 Correct 1 ms 1492 KB Output is correct
7 Correct 1 ms 1492 KB Output is correct
8 Correct 1 ms 1468 KB Output is correct
9 Correct 2 ms 1492 KB Output is correct
10 Correct 1 ms 1472 KB Output is correct
11 Correct 1 ms 1492 KB Output is correct
12 Correct 1 ms 1492 KB Output is correct
13 Correct 2 ms 1492 KB Output is correct
14 Correct 8 ms 2388 KB Output is correct
15 Correct 14 ms 3404 KB Output is correct
16 Correct 22 ms 4472 KB Output is correct
17 Correct 20 ms 4436 KB Output is correct
18 Correct 22 ms 4424 KB Output is correct
19 Correct 26 ms 4436 KB Output is correct
20 Correct 22 ms 4468 KB Output is correct
21 Correct 22 ms 4424 KB Output is correct
22 Correct 22 ms 4432 KB Output is correct
23 Correct 22 ms 4436 KB Output is correct
24 Correct 21 ms 4428 KB Output is correct
25 Correct 22 ms 4432 KB Output is correct
26 Correct 1 ms 1492 KB Output is correct
27 Correct 1 ms 1492 KB Output is correct
28 Correct 2 ms 1492 KB Output is correct
29 Correct 9 ms 2508 KB Output is correct
30 Correct 16 ms 3540 KB Output is correct
31 Correct 24 ms 4564 KB Output is correct
32 Correct 24 ms 4556 KB Output is correct
33 Correct 26 ms 4688 KB Output is correct
34 Correct 24 ms 4548 KB Output is correct
35 Correct 24 ms 4564 KB Output is correct
36 Correct 25 ms 4564 KB Output is correct
37 Correct 26 ms 4560 KB Output is correct
38 Correct 23 ms 4560 KB Output is correct
39 Correct 23 ms 4556 KB Output is correct
40 Correct 24 ms 4564 KB Output is correct
41 Correct 2 ms 1492 KB Output is correct
42 Correct 1 ms 1492 KB Output is correct
43 Correct 1 ms 1492 KB Output is correct
44 Correct 2 ms 1620 KB Output is correct
45 Correct 2 ms 1620 KB Output is correct
46 Correct 2 ms 1620 KB Output is correct
47 Correct 6 ms 2004 KB Output is correct
48 Correct 6 ms 1996 KB Output is correct
49 Correct 13 ms 2644 KB Output is correct
50 Correct 21 ms 3824 KB Output is correct
51 Correct 32 ms 4944 KB Output is correct
52 Correct 32 ms 4940 KB Output is correct
53 Correct 32 ms 4948 KB Output is correct
54 Correct 31 ms 4948 KB Output is correct
55 Correct 34 ms 5012 KB Output is correct
56 Correct 31 ms 4948 KB Output is correct
57 Correct 35 ms 4940 KB Output is correct
58 Correct 34 ms 4992 KB Output is correct
59 Correct 31 ms 4948 KB Output is correct
60 Correct 31 ms 4948 KB Output is correct
61 Correct 31 ms 4948 KB Output is correct
62 Correct 32 ms 4940 KB Output is correct
63 Correct 32 ms 4948 KB Output is correct
64 Correct 31 ms 4952 KB Output is correct
65 Correct 32 ms 5016 KB Output is correct
66 Correct 36 ms 4996 KB Output is correct
67 Correct 31 ms 4944 KB Output is correct
68 Correct 32 ms 4992 KB Output is correct
69 Correct 32 ms 4952 KB Output is correct
70 Correct 31 ms 4932 KB Output is correct
71 Correct 9 ms 2132 KB Output is correct
72 Correct 7 ms 2132 KB Output is correct
73 Correct 7 ms 2132 KB Output is correct
74 Correct 7 ms 2132 KB Output is correct
75 Correct 7 ms 2132 KB Output is correct
76 Correct 13 ms 2772 KB Output is correct
77 Correct 13 ms 2772 KB Output is correct
78 Correct 13 ms 2860 KB Output is correct
79 Correct 13 ms 2772 KB Output is correct
80 Correct 13 ms 2764 KB Output is correct
81 Correct 26 ms 4172 KB Output is correct
82 Correct 26 ms 4180 KB Output is correct
83 Correct 26 ms 4172 KB Output is correct
84 Correct 27 ms 4160 KB Output is correct
85 Correct 26 ms 4180 KB Output is correct
86 Correct 29 ms 4312 KB Output is correct
87 Correct 32 ms 4304 KB Output is correct
88 Correct 29 ms 4312 KB Output is correct
89 Correct 30 ms 4360 KB Output is correct
90 Correct 30 ms 4432 KB Output is correct
91 Correct 53 ms 6716 KB Output is correct
92 Correct 51 ms 6764 KB Output is correct
93 Correct 52 ms 6720 KB Output is correct
94 Correct 55 ms 6728 KB Output is correct
95 Correct 52 ms 6720 KB Output is correct
96 Correct 66 ms 8044 KB Output is correct
97 Correct 62 ms 8000 KB Output is correct
98 Correct 61 ms 7996 KB Output is correct
99 Correct 68 ms 8000 KB Output is correct
100 Correct 61 ms 8128 KB Output is correct
101 Correct 60 ms 8004 KB Output is correct
102 Correct 63 ms 8128 KB Output is correct
103 Correct 62 ms 8048 KB Output is correct
104 Correct 61 ms 8112 KB Output is correct
105 Correct 61 ms 8004 KB Output is correct
106 Correct 65 ms 8720 KB Output is correct
107 Correct 59 ms 8760 KB Output is correct
108 Correct 61 ms 8652 KB Output is correct
109 Correct 65 ms 8648 KB Output is correct
110 Correct 63 ms 8644 KB Output is correct
111 Correct 61 ms 8644 KB Output is correct
112 Correct 72 ms 8732 KB Output is correct
113 Correct 67 ms 8632 KB Output is correct
114 Correct 61 ms 8648 KB Output is correct
115 Correct 68 ms 8628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1492 KB Output is correct
2 Correct 1 ms 1492 KB Output is correct
3 Correct 1 ms 1492 KB Output is correct
4 Correct 1 ms 1492 KB Output is correct
5 Correct 1 ms 1492 KB Output is correct
6 Correct 1 ms 1492 KB Output is correct
7 Correct 1 ms 1492 KB Output is correct
8 Correct 1 ms 1468 KB Output is correct
9 Correct 2 ms 1492 KB Output is correct
10 Correct 1 ms 1472 KB Output is correct
11 Correct 1 ms 1492 KB Output is correct
12 Correct 1 ms 1492 KB Output is correct
13 Correct 2 ms 1492 KB Output is correct
14 Correct 8 ms 2388 KB Output is correct
15 Correct 14 ms 3404 KB Output is correct
16 Correct 22 ms 4472 KB Output is correct
17 Correct 20 ms 4436 KB Output is correct
18 Correct 22 ms 4424 KB Output is correct
19 Correct 26 ms 4436 KB Output is correct
20 Correct 22 ms 4468 KB Output is correct
21 Correct 22 ms 4424 KB Output is correct
22 Correct 22 ms 4432 KB Output is correct
23 Correct 22 ms 4436 KB Output is correct
24 Correct 21 ms 4428 KB Output is correct
25 Correct 22 ms 4432 KB Output is correct
26 Correct 1 ms 1492 KB Output is correct
27 Correct 1 ms 1492 KB Output is correct
28 Correct 2 ms 1492 KB Output is correct
29 Correct 9 ms 2508 KB Output is correct
30 Correct 16 ms 3540 KB Output is correct
31 Correct 24 ms 4564 KB Output is correct
32 Correct 24 ms 4556 KB Output is correct
33 Correct 26 ms 4688 KB Output is correct
34 Correct 24 ms 4548 KB Output is correct
35 Correct 24 ms 4564 KB Output is correct
36 Correct 25 ms 4564 KB Output is correct
37 Correct 26 ms 4560 KB Output is correct
38 Correct 23 ms 4560 KB Output is correct
39 Correct 23 ms 4556 KB Output is correct
40 Correct 24 ms 4564 KB Output is correct
41 Correct 2 ms 1492 KB Output is correct
42 Correct 1 ms 1492 KB Output is correct
43 Correct 1 ms 1492 KB Output is correct
44 Correct 2 ms 1620 KB Output is correct
45 Correct 2 ms 1620 KB Output is correct
46 Correct 2 ms 1620 KB Output is correct
47 Correct 6 ms 2004 KB Output is correct
48 Correct 6 ms 1996 KB Output is correct
49 Correct 13 ms 2644 KB Output is correct
50 Correct 21 ms 3824 KB Output is correct
51 Correct 32 ms 4944 KB Output is correct
52 Correct 32 ms 4940 KB Output is correct
53 Correct 32 ms 4948 KB Output is correct
54 Correct 31 ms 4948 KB Output is correct
55 Correct 34 ms 5012 KB Output is correct
56 Correct 31 ms 4948 KB Output is correct
57 Correct 35 ms 4940 KB Output is correct
58 Correct 34 ms 4992 KB Output is correct
59 Correct 31 ms 4948 KB Output is correct
60 Correct 31 ms 4948 KB Output is correct
61 Correct 31 ms 4948 KB Output is correct
62 Correct 32 ms 4940 KB Output is correct
63 Correct 32 ms 4948 KB Output is correct
64 Correct 31 ms 4952 KB Output is correct
65 Correct 32 ms 5016 KB Output is correct
66 Correct 36 ms 4996 KB Output is correct
67 Correct 31 ms 4944 KB Output is correct
68 Correct 32 ms 4992 KB Output is correct
69 Correct 32 ms 4952 KB Output is correct
70 Correct 31 ms 4932 KB Output is correct
71 Correct 9 ms 2132 KB Output is correct
72 Correct 7 ms 2132 KB Output is correct
73 Correct 7 ms 2132 KB Output is correct
74 Correct 7 ms 2132 KB Output is correct
75 Correct 7 ms 2132 KB Output is correct
76 Correct 13 ms 2772 KB Output is correct
77 Correct 13 ms 2772 KB Output is correct
78 Correct 13 ms 2860 KB Output is correct
79 Correct 13 ms 2772 KB Output is correct
80 Correct 13 ms 2764 KB Output is correct
81 Correct 26 ms 4172 KB Output is correct
82 Correct 26 ms 4180 KB Output is correct
83 Correct 26 ms 4172 KB Output is correct
84 Correct 27 ms 4160 KB Output is correct
85 Correct 26 ms 4180 KB Output is correct
86 Correct 29 ms 4312 KB Output is correct
87 Correct 32 ms 4304 KB Output is correct
88 Correct 29 ms 4312 KB Output is correct
89 Correct 30 ms 4360 KB Output is correct
90 Correct 30 ms 4432 KB Output is correct
91 Correct 53 ms 6716 KB Output is correct
92 Correct 51 ms 6764 KB Output is correct
93 Correct 52 ms 6720 KB Output is correct
94 Correct 55 ms 6728 KB Output is correct
95 Correct 52 ms 6720 KB Output is correct
96 Correct 66 ms 8044 KB Output is correct
97 Correct 62 ms 8000 KB Output is correct
98 Correct 61 ms 7996 KB Output is correct
99 Correct 68 ms 8000 KB Output is correct
100 Correct 61 ms 8128 KB Output is correct
101 Correct 60 ms 8004 KB Output is correct
102 Correct 63 ms 8128 KB Output is correct
103 Correct 62 ms 8048 KB Output is correct
104 Correct 61 ms 8112 KB Output is correct
105 Correct 61 ms 8004 KB Output is correct
106 Correct 65 ms 8720 KB Output is correct
107 Correct 59 ms 8760 KB Output is correct
108 Correct 61 ms 8652 KB Output is correct
109 Correct 65 ms 8648 KB Output is correct
110 Correct 63 ms 8644 KB Output is correct
111 Correct 61 ms 8644 KB Output is correct
112 Correct 72 ms 8732 KB Output is correct
113 Correct 67 ms 8632 KB Output is correct
114 Correct 61 ms 8648 KB Output is correct
115 Correct 68 ms 8628 KB Output is correct
116 Incorrect 11 ms 2548 KB Output isn't correct
117 Halted 0 ms 0 KB -