Submission #920311

# Submission time Handle Problem Language Result Execution time Memory
920311 2024-02-02T12:45:12 Z vjudge1 Diversity (CEOI21_diversity) C++17
64 / 100
7000 ms 8280 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <cassert>
#include <cstring>
#include <set>
#warning That's the baby, that's not my baby

typedef long long ll;

const int NMAX = 3e5;

int a[NMAX + 1];
int f[NMAX + 1];

int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0);

  int n, q;
  std::cin >> n >> q;

  std::vector<int> norm;
  for (int i = 1; i <= n; i++) {
    std::cin >> a[i];
    norm.push_back(a[i]);
  }

  std::sort(norm.begin(), norm.end());
  norm.erase(std::unique(norm.begin(), norm.end()), norm.end());

  for (int i = 1; i <= n; i++) {
    a[i] = std::lower_bound(norm.begin(), norm.end(), a[i]) - norm.begin();
  }

  /**

  1 * (f[1] + f[2] + ... + f[k]) +
  2 * (f[1] * f[2] + f[2] * f[3] + f[3] * f[4] + ... + f[k - 1] * f[k]) +
  3 * (f[1] * f[3] + f[2] * f[4] + ...) +
  ...

  **/

  while (q--) {
    int l, r;
    std::cin >> l >> r;
    std::vector<int> b;
    memset(f, 0, sizeof(f));
    for (int i = l; i <= r; i++) {
      f[a[i]]++;
    }
    std::vector<int> fr;
    for (int i = 0; i < NMAX; i++) {
      if (f[i] != 0) {
        fr.push_back(f[i]);
      }
    }

    std::sort(fr.begin(), fr.end());

    ll answer = 0;

    std::vector<int> frr;
    for (int i = 0; i < (int) fr.size(); i += 2) {
      frr.push_back(fr[i]);
    }
    int sz = (int) frr.size();
    for (int i = 1; i < (int) fr.size(); i += 2) {
      frr.push_back(fr[i]);
    }
    std::reverse(frr.begin() + sz, frr.end());
    fr = frr;
    int m = (int) fr.size();
    ll add = 0, sum = 0;
    for (int i = 0; i < m; i++) {
      ll cur = 0;
//      for (int j = 0; j < i; j++) {
//        cur += (ll) (i - j + 1) * fr[j];
//      }
      answer += (ll) fr[i] * add;
      sum += fr[i];
      add += sum + fr[i];
    }

    /**

    for i=0..m-1:
      for j=0..i-1:
        cur += (i - j) * fr[j]


    **/

    for (const auto &x : fr) {
      answer += (ll) x * (x + 1) / 2;
    }

    std::cout << answer << '\n';
  }

  return 0;
}

Compilation message

diversity.cpp:7:2: warning: #warning That's the baby, that's not my baby [-Wcpp]
    7 | #warning That's the baby, that's not my baby
      |  ^~~~~~~
diversity.cpp: In function 'int main()':
diversity.cpp:77:10: warning: unused variable 'cur' [-Wunused-variable]
   77 |       ll cur = 0;
      |          ^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 1 ms 2648 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 2648 KB Output is correct
6 Correct 1 ms 2648 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2648 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 1 ms 2904 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2648 KB Output is correct
3 Correct 2 ms 2648 KB Output is correct
4 Correct 8 ms 3036 KB Output is correct
5 Correct 15 ms 3544 KB Output is correct
6 Correct 26 ms 4564 KB Output is correct
7 Correct 23 ms 4568 KB Output is correct
8 Correct 25 ms 4568 KB Output is correct
9 Correct 25 ms 4564 KB Output is correct
10 Correct 25 ms 4564 KB Output is correct
11 Correct 25 ms 4568 KB Output is correct
12 Correct 26 ms 4564 KB Output is correct
13 Correct 26 ms 4564 KB Output is correct
14 Correct 26 ms 4564 KB Output is correct
15 Correct 26 ms 4568 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2648 KB Output is correct
3 Correct 2 ms 2648 KB Output is correct
4 Correct 8 ms 3036 KB Output is correct
5 Correct 15 ms 3544 KB Output is correct
6 Correct 26 ms 4564 KB Output is correct
7 Correct 23 ms 4568 KB Output is correct
8 Correct 25 ms 4568 KB Output is correct
9 Correct 25 ms 4564 KB Output is correct
10 Correct 25 ms 4564 KB Output is correct
11 Correct 25 ms 4568 KB Output is correct
12 Correct 26 ms 4564 KB Output is correct
13 Correct 26 ms 4564 KB Output is correct
14 Correct 26 ms 4564 KB Output is correct
15 Correct 26 ms 4568 KB Output is correct
16 Correct 1 ms 2648 KB Output is correct
17 Correct 1 ms 2648 KB Output is correct
18 Correct 2 ms 2648 KB Output is correct
19 Correct 10 ms 3036 KB Output is correct
20 Correct 19 ms 3544 KB Output is correct
21 Correct 28 ms 4564 KB Output is correct
22 Correct 29 ms 4568 KB Output is correct
23 Correct 28 ms 4568 KB Output is correct
24 Correct 29 ms 4564 KB Output is correct
25 Correct 29 ms 4564 KB Output is correct
26 Correct 31 ms 4564 KB Output is correct
27 Correct 28 ms 4664 KB Output is correct
28 Correct 27 ms 4564 KB Output is correct
29 Correct 29 ms 4564 KB Output is correct
30 Correct 30 ms 4564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2648 KB Output is correct
3 Correct 2 ms 2648 KB Output is correct
4 Correct 8 ms 3036 KB Output is correct
5 Correct 15 ms 3544 KB Output is correct
6 Correct 26 ms 4564 KB Output is correct
7 Correct 23 ms 4568 KB Output is correct
8 Correct 25 ms 4568 KB Output is correct
9 Correct 25 ms 4564 KB Output is correct
10 Correct 25 ms 4564 KB Output is correct
11 Correct 25 ms 4568 KB Output is correct
12 Correct 26 ms 4564 KB Output is correct
13 Correct 26 ms 4564 KB Output is correct
14 Correct 26 ms 4564 KB Output is correct
15 Correct 26 ms 4568 KB Output is correct
16 Correct 1 ms 2648 KB Output is correct
17 Correct 1 ms 2648 KB Output is correct
18 Correct 2 ms 2648 KB Output is correct
19 Correct 10 ms 3036 KB Output is correct
20 Correct 19 ms 3544 KB Output is correct
21 Correct 28 ms 4564 KB Output is correct
22 Correct 29 ms 4568 KB Output is correct
23 Correct 28 ms 4568 KB Output is correct
24 Correct 29 ms 4564 KB Output is correct
25 Correct 29 ms 4564 KB Output is correct
26 Correct 31 ms 4564 KB Output is correct
27 Correct 28 ms 4664 KB Output is correct
28 Correct 27 ms 4564 KB Output is correct
29 Correct 29 ms 4564 KB Output is correct
30 Correct 30 ms 4564 KB Output is correct
31 Correct 1 ms 2652 KB Output is correct
32 Correct 1 ms 2648 KB Output is correct
33 Correct 1 ms 2648 KB Output is correct
34 Correct 2 ms 2652 KB Output is correct
35 Correct 2 ms 2648 KB Output is correct
36 Correct 2 ms 2648 KB Output is correct
37 Correct 7 ms 2908 KB Output is correct
38 Correct 8 ms 2908 KB Output is correct
39 Correct 15 ms 3036 KB Output is correct
40 Correct 29 ms 3548 KB Output is correct
41 Correct 44 ms 4564 KB Output is correct
42 Correct 43 ms 4564 KB Output is correct
43 Correct 43 ms 4564 KB Output is correct
44 Correct 44 ms 4564 KB Output is correct
45 Correct 45 ms 4564 KB Output is correct
46 Correct 44 ms 4568 KB Output is correct
47 Correct 44 ms 4564 KB Output is correct
48 Correct 44 ms 4564 KB Output is correct
49 Correct 43 ms 4564 KB Output is correct
50 Correct 43 ms 4564 KB Output is correct
51 Correct 44 ms 4564 KB Output is correct
52 Correct 43 ms 4652 KB Output is correct
53 Correct 45 ms 4568 KB Output is correct
54 Correct 43 ms 4564 KB Output is correct
55 Correct 43 ms 4540 KB Output is correct
56 Correct 44 ms 4564 KB Output is correct
57 Correct 43 ms 4564 KB Output is correct
58 Correct 44 ms 4568 KB Output is correct
59 Correct 44 ms 4564 KB Output is correct
60 Correct 44 ms 4564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 1 ms 2648 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 2648 KB Output is correct
6 Correct 1 ms 2648 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2648 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 1 ms 2904 KB Output is correct
11 Correct 1 ms 2652 KB Output is correct
12 Correct 1 ms 2648 KB Output is correct
13 Correct 2 ms 2648 KB Output is correct
14 Correct 8 ms 3036 KB Output is correct
15 Correct 15 ms 3544 KB Output is correct
16 Correct 26 ms 4564 KB Output is correct
17 Correct 23 ms 4568 KB Output is correct
18 Correct 25 ms 4568 KB Output is correct
19 Correct 25 ms 4564 KB Output is correct
20 Correct 25 ms 4564 KB Output is correct
21 Correct 25 ms 4568 KB Output is correct
22 Correct 26 ms 4564 KB Output is correct
23 Correct 26 ms 4564 KB Output is correct
24 Correct 26 ms 4564 KB Output is correct
25 Correct 26 ms 4568 KB Output is correct
26 Correct 1 ms 2648 KB Output is correct
27 Correct 1 ms 2648 KB Output is correct
28 Correct 2 ms 2648 KB Output is correct
29 Correct 10 ms 3036 KB Output is correct
30 Correct 19 ms 3544 KB Output is correct
31 Correct 28 ms 4564 KB Output is correct
32 Correct 29 ms 4568 KB Output is correct
33 Correct 28 ms 4568 KB Output is correct
34 Correct 29 ms 4564 KB Output is correct
35 Correct 29 ms 4564 KB Output is correct
36 Correct 31 ms 4564 KB Output is correct
37 Correct 28 ms 4664 KB Output is correct
38 Correct 27 ms 4564 KB Output is correct
39 Correct 29 ms 4564 KB Output is correct
40 Correct 30 ms 4564 KB Output is correct
41 Correct 1 ms 2652 KB Output is correct
42 Correct 1 ms 2648 KB Output is correct
43 Correct 1 ms 2648 KB Output is correct
44 Correct 2 ms 2652 KB Output is correct
45 Correct 2 ms 2648 KB Output is correct
46 Correct 2 ms 2648 KB Output is correct
47 Correct 7 ms 2908 KB Output is correct
48 Correct 8 ms 2908 KB Output is correct
49 Correct 15 ms 3036 KB Output is correct
50 Correct 29 ms 3548 KB Output is correct
51 Correct 44 ms 4564 KB Output is correct
52 Correct 43 ms 4564 KB Output is correct
53 Correct 43 ms 4564 KB Output is correct
54 Correct 44 ms 4564 KB Output is correct
55 Correct 45 ms 4564 KB Output is correct
56 Correct 44 ms 4568 KB Output is correct
57 Correct 44 ms 4564 KB Output is correct
58 Correct 44 ms 4564 KB Output is correct
59 Correct 43 ms 4564 KB Output is correct
60 Correct 43 ms 4564 KB Output is correct
61 Correct 44 ms 4564 KB Output is correct
62 Correct 43 ms 4652 KB Output is correct
63 Correct 45 ms 4568 KB Output is correct
64 Correct 43 ms 4564 KB Output is correct
65 Correct 43 ms 4540 KB Output is correct
66 Correct 44 ms 4564 KB Output is correct
67 Correct 43 ms 4564 KB Output is correct
68 Correct 44 ms 4568 KB Output is correct
69 Correct 44 ms 4564 KB Output is correct
70 Correct 44 ms 4564 KB Output is correct
71 Correct 9 ms 2908 KB Output is correct
72 Correct 9 ms 3036 KB Output is correct
73 Correct 11 ms 2908 KB Output is correct
74 Correct 9 ms 2904 KB Output is correct
75 Correct 10 ms 2904 KB Output is correct
76 Correct 18 ms 3036 KB Output is correct
77 Correct 18 ms 3036 KB Output is correct
78 Correct 18 ms 3036 KB Output is correct
79 Correct 18 ms 3036 KB Output is correct
80 Correct 18 ms 3036 KB Output is correct
81 Correct 37 ms 3544 KB Output is correct
82 Correct 38 ms 3544 KB Output is correct
83 Correct 37 ms 3544 KB Output is correct
84 Correct 39 ms 3544 KB Output is correct
85 Correct 37 ms 3544 KB Output is correct
86 Correct 42 ms 3544 KB Output is correct
87 Correct 41 ms 3548 KB Output is correct
88 Correct 41 ms 3544 KB Output is correct
89 Correct 41 ms 3544 KB Output is correct
90 Correct 52 ms 3548 KB Output is correct
91 Correct 70 ms 5060 KB Output is correct
92 Correct 72 ms 5060 KB Output is correct
93 Correct 74 ms 5220 KB Output is correct
94 Correct 71 ms 5060 KB Output is correct
95 Correct 77 ms 5040 KB Output is correct
96 Correct 79 ms 6508 KB Output is correct
97 Correct 84 ms 8280 KB Output is correct
98 Correct 86 ms 7620 KB Output is correct
99 Correct 84 ms 7620 KB Output is correct
100 Correct 83 ms 7784 KB Output is correct
101 Correct 80 ms 7624 KB Output is correct
102 Correct 82 ms 7624 KB Output is correct
103 Correct 83 ms 7620 KB Output is correct
104 Correct 82 ms 7620 KB Output is correct
105 Correct 80 ms 7624 KB Output is correct
106 Correct 86 ms 8036 KB Output is correct
107 Correct 82 ms 8024 KB Output is correct
108 Correct 82 ms 8024 KB Output is correct
109 Correct 82 ms 8024 KB Output is correct
110 Correct 83 ms 8244 KB Output is correct
111 Correct 84 ms 8132 KB Output is correct
112 Correct 82 ms 8028 KB Output is correct
113 Correct 97 ms 8020 KB Output is correct
114 Correct 83 ms 8136 KB Output is correct
115 Correct 89 ms 8020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 1 ms 2648 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 2648 KB Output is correct
6 Correct 1 ms 2648 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2648 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 1 ms 2904 KB Output is correct
11 Correct 1 ms 2652 KB Output is correct
12 Correct 1 ms 2648 KB Output is correct
13 Correct 2 ms 2648 KB Output is correct
14 Correct 8 ms 3036 KB Output is correct
15 Correct 15 ms 3544 KB Output is correct
16 Correct 26 ms 4564 KB Output is correct
17 Correct 23 ms 4568 KB Output is correct
18 Correct 25 ms 4568 KB Output is correct
19 Correct 25 ms 4564 KB Output is correct
20 Correct 25 ms 4564 KB Output is correct
21 Correct 25 ms 4568 KB Output is correct
22 Correct 26 ms 4564 KB Output is correct
23 Correct 26 ms 4564 KB Output is correct
24 Correct 26 ms 4564 KB Output is correct
25 Correct 26 ms 4568 KB Output is correct
26 Correct 1 ms 2648 KB Output is correct
27 Correct 1 ms 2648 KB Output is correct
28 Correct 2 ms 2648 KB Output is correct
29 Correct 10 ms 3036 KB Output is correct
30 Correct 19 ms 3544 KB Output is correct
31 Correct 28 ms 4564 KB Output is correct
32 Correct 29 ms 4568 KB Output is correct
33 Correct 28 ms 4568 KB Output is correct
34 Correct 29 ms 4564 KB Output is correct
35 Correct 29 ms 4564 KB Output is correct
36 Correct 31 ms 4564 KB Output is correct
37 Correct 28 ms 4664 KB Output is correct
38 Correct 27 ms 4564 KB Output is correct
39 Correct 29 ms 4564 KB Output is correct
40 Correct 30 ms 4564 KB Output is correct
41 Correct 1 ms 2652 KB Output is correct
42 Correct 1 ms 2648 KB Output is correct
43 Correct 1 ms 2648 KB Output is correct
44 Correct 2 ms 2652 KB Output is correct
45 Correct 2 ms 2648 KB Output is correct
46 Correct 2 ms 2648 KB Output is correct
47 Correct 7 ms 2908 KB Output is correct
48 Correct 8 ms 2908 KB Output is correct
49 Correct 15 ms 3036 KB Output is correct
50 Correct 29 ms 3548 KB Output is correct
51 Correct 44 ms 4564 KB Output is correct
52 Correct 43 ms 4564 KB Output is correct
53 Correct 43 ms 4564 KB Output is correct
54 Correct 44 ms 4564 KB Output is correct
55 Correct 45 ms 4564 KB Output is correct
56 Correct 44 ms 4568 KB Output is correct
57 Correct 44 ms 4564 KB Output is correct
58 Correct 44 ms 4564 KB Output is correct
59 Correct 43 ms 4564 KB Output is correct
60 Correct 43 ms 4564 KB Output is correct
61 Correct 44 ms 4564 KB Output is correct
62 Correct 43 ms 4652 KB Output is correct
63 Correct 45 ms 4568 KB Output is correct
64 Correct 43 ms 4564 KB Output is correct
65 Correct 43 ms 4540 KB Output is correct
66 Correct 44 ms 4564 KB Output is correct
67 Correct 43 ms 4564 KB Output is correct
68 Correct 44 ms 4568 KB Output is correct
69 Correct 44 ms 4564 KB Output is correct
70 Correct 44 ms 4564 KB Output is correct
71 Correct 9 ms 2908 KB Output is correct
72 Correct 9 ms 3036 KB Output is correct
73 Correct 11 ms 2908 KB Output is correct
74 Correct 9 ms 2904 KB Output is correct
75 Correct 10 ms 2904 KB Output is correct
76 Correct 18 ms 3036 KB Output is correct
77 Correct 18 ms 3036 KB Output is correct
78 Correct 18 ms 3036 KB Output is correct
79 Correct 18 ms 3036 KB Output is correct
80 Correct 18 ms 3036 KB Output is correct
81 Correct 37 ms 3544 KB Output is correct
82 Correct 38 ms 3544 KB Output is correct
83 Correct 37 ms 3544 KB Output is correct
84 Correct 39 ms 3544 KB Output is correct
85 Correct 37 ms 3544 KB Output is correct
86 Correct 42 ms 3544 KB Output is correct
87 Correct 41 ms 3548 KB Output is correct
88 Correct 41 ms 3544 KB Output is correct
89 Correct 41 ms 3544 KB Output is correct
90 Correct 52 ms 3548 KB Output is correct
91 Correct 70 ms 5060 KB Output is correct
92 Correct 72 ms 5060 KB Output is correct
93 Correct 74 ms 5220 KB Output is correct
94 Correct 71 ms 5060 KB Output is correct
95 Correct 77 ms 5040 KB Output is correct
96 Correct 79 ms 6508 KB Output is correct
97 Correct 84 ms 8280 KB Output is correct
98 Correct 86 ms 7620 KB Output is correct
99 Correct 84 ms 7620 KB Output is correct
100 Correct 83 ms 7784 KB Output is correct
101 Correct 80 ms 7624 KB Output is correct
102 Correct 82 ms 7624 KB Output is correct
103 Correct 83 ms 7620 KB Output is correct
104 Correct 82 ms 7620 KB Output is correct
105 Correct 80 ms 7624 KB Output is correct
106 Correct 86 ms 8036 KB Output is correct
107 Correct 82 ms 8024 KB Output is correct
108 Correct 82 ms 8024 KB Output is correct
109 Correct 82 ms 8024 KB Output is correct
110 Correct 83 ms 8244 KB Output is correct
111 Correct 84 ms 8132 KB Output is correct
112 Correct 82 ms 8028 KB Output is correct
113 Correct 97 ms 8020 KB Output is correct
114 Correct 83 ms 8136 KB Output is correct
115 Correct 89 ms 8020 KB Output is correct
116 Correct 5787 ms 3728 KB Output is correct
117 Correct 5819 ms 3596 KB Output is correct
118 Correct 6314 ms 3980 KB Output is correct
119 Execution timed out 7021 ms 4064 KB Time limit exceeded
120 Halted 0 ms 0 KB -