Submission #920258

# Submission time Handle Problem Language Result Execution time Memory
920258 2024-02-02T10:54:22 Z vjudge1 Diversity (CEOI21_diversity) C++17
38 / 100
7000 ms 8384 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());
//    for (const auto &x : frr) {
//      std::cout << x << ' ';
//    }
//    std::cout << '\n';
    fr = frr;
    int m = (int) fr.size();
    for (int k = 2; k <= m; k++) {
      for (int i = k - 1; i < m; i++) {
        answer += (ll) k * ((ll) fr[i - k + 1] * fr[i]);
      }
    }

    /**

    for i=1..N:
      for j=1..i-1:
        cur += j * f[i - j + 1]


    **/

//    do {
//      int m = (int) fr.size();
//      int cur = 0;
//      for (int k = 2; k <= m; k++) {
//        for (int i = k - 1; i < m; i++) {
//          cur += k * (fr[i - k + 1] * fr[i]);
//        }
//      }
//      answer = std::min(answer, cur);
//    } while(std::next_permutation(fr.begin(), fr.end()));
//
//    std::sort(fr.begin(), fr.end());
//    do {
//      int m = (int) fr.size();
//      int cur = 0;
//      for (int k = 2; k <= m; k++) {
//        for (int i = k - 1; i < m; i++) {
//          cur += k * (fr[i - k + 1] * fr[i]);
//        }
//      }
//      if (cur == answer) {
//        for (const auto &x : fr) {
//          std::cout << x << ' ';
//        }
//        std::cout << '\n';
//      }
//    } while(std::next_permutation(fr.begin(), fr.end()));

    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
      |  ^~~~~~~
# 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 2648 KB Output is correct
4 Correct 1 ms 2648 KB Output is correct
5 Correct 1 ms 2648 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2648 KB Output is correct
8 Correct 1 ms 2648 KB Output is correct
9 Correct 1 ms 2648 KB Output is correct
10 Correct 1 ms 2648 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 2 ms 2652 KB Output is correct
4 Correct 8 ms 3036 KB Output is correct
5 Correct 16 ms 3544 KB Output is correct
6 Correct 25 ms 4564 KB Output is correct
7 Correct 23 ms 5076 KB Output is correct
8 Correct 25 ms 5336 KB Output is correct
9 Correct 25 ms 5332 KB Output is correct
10 Correct 26 ms 5332 KB Output is correct
11 Correct 25 ms 5332 KB Output is correct
12 Correct 27 ms 5588 KB Output is correct
13 Correct 25 ms 5332 KB Output is correct
14 Correct 26 ms 5332 KB Output is correct
15 Correct 28 ms 5336 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 2 ms 2652 KB Output is correct
4 Correct 8 ms 3036 KB Output is correct
5 Correct 16 ms 3544 KB Output is correct
6 Correct 25 ms 4564 KB Output is correct
7 Correct 23 ms 5076 KB Output is correct
8 Correct 25 ms 5336 KB Output is correct
9 Correct 25 ms 5332 KB Output is correct
10 Correct 26 ms 5332 KB Output is correct
11 Correct 25 ms 5332 KB Output is correct
12 Correct 27 ms 5588 KB Output is correct
13 Correct 25 ms 5332 KB Output is correct
14 Correct 26 ms 5332 KB Output is correct
15 Correct 28 ms 5336 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 3296 KB Output is correct
20 Correct 20 ms 4056 KB Output is correct
21 Correct 28 ms 5332 KB Output is correct
22 Correct 29 ms 5332 KB Output is correct
23 Correct 28 ms 5332 KB Output is correct
24 Correct 30 ms 5332 KB Output is correct
25 Correct 29 ms 5332 KB Output is correct
26 Correct 29 ms 5332 KB Output is correct
27 Correct 28 ms 5332 KB Output is correct
28 Correct 27 ms 5332 KB Output is correct
29 Correct 29 ms 5332 KB Output is correct
30 Correct 29 ms 5500 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 2 ms 2652 KB Output is correct
4 Correct 8 ms 3036 KB Output is correct
5 Correct 16 ms 3544 KB Output is correct
6 Correct 25 ms 4564 KB Output is correct
7 Correct 23 ms 5076 KB Output is correct
8 Correct 25 ms 5336 KB Output is correct
9 Correct 25 ms 5332 KB Output is correct
10 Correct 26 ms 5332 KB Output is correct
11 Correct 25 ms 5332 KB Output is correct
12 Correct 27 ms 5588 KB Output is correct
13 Correct 25 ms 5332 KB Output is correct
14 Correct 26 ms 5332 KB Output is correct
15 Correct 28 ms 5336 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 3296 KB Output is correct
20 Correct 20 ms 4056 KB Output is correct
21 Correct 28 ms 5332 KB Output is correct
22 Correct 29 ms 5332 KB Output is correct
23 Correct 28 ms 5332 KB Output is correct
24 Correct 30 ms 5332 KB Output is correct
25 Correct 29 ms 5332 KB Output is correct
26 Correct 29 ms 5332 KB Output is correct
27 Correct 28 ms 5332 KB Output is correct
28 Correct 27 ms 5332 KB Output is correct
29 Correct 29 ms 5332 KB Output is correct
30 Correct 29 ms 5500 KB Output is correct
31 Correct 1 ms 2660 KB Output is correct
32 Correct 1 ms 2652 KB Output is correct
33 Correct 2 ms 2512 KB Output is correct
34 Correct 2 ms 2652 KB Output is correct
35 Correct 2 ms 2652 KB Output is correct
36 Correct 3 ms 2648 KB Output is correct
37 Correct 8 ms 3040 KB Output is correct
38 Correct 9 ms 3036 KB Output is correct
39 Correct 16 ms 3548 KB Output is correct
40 Correct 30 ms 4312 KB Output is correct
41 Correct 45 ms 5836 KB Output is correct
42 Correct 45 ms 5836 KB Output is correct
43 Correct 45 ms 5844 KB Output is correct
44 Correct 44 ms 5848 KB Output is correct
45 Correct 45 ms 5848 KB Output is correct
46 Correct 45 ms 5844 KB Output is correct
47 Correct 47 ms 5844 KB Output is correct
48 Correct 45 ms 5844 KB Output is correct
49 Correct 44 ms 5844 KB Output is correct
50 Correct 44 ms 5844 KB Output is correct
51 Correct 47 ms 5856 KB Output is correct
52 Correct 45 ms 5844 KB Output is correct
53 Correct 44 ms 5844 KB Output is correct
54 Correct 46 ms 5844 KB Output is correct
55 Correct 46 ms 5580 KB Output is correct
56 Correct 45 ms 5820 KB Output is correct
57 Correct 44 ms 5844 KB Output is correct
58 Correct 45 ms 5844 KB Output is correct
59 Correct 44 ms 5848 KB Output is correct
60 Correct 45 ms 5836 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 2648 KB Output is correct
4 Correct 1 ms 2648 KB Output is correct
5 Correct 1 ms 2648 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2648 KB Output is correct
8 Correct 1 ms 2648 KB Output is correct
9 Correct 1 ms 2648 KB Output is correct
10 Correct 1 ms 2648 KB Output is correct
11 Correct 1 ms 2648 KB Output is correct
12 Correct 1 ms 2648 KB Output is correct
13 Correct 2 ms 2652 KB Output is correct
14 Correct 8 ms 3036 KB Output is correct
15 Correct 16 ms 3544 KB Output is correct
16 Correct 25 ms 4564 KB Output is correct
17 Correct 23 ms 5076 KB Output is correct
18 Correct 25 ms 5336 KB Output is correct
19 Correct 25 ms 5332 KB Output is correct
20 Correct 26 ms 5332 KB Output is correct
21 Correct 25 ms 5332 KB Output is correct
22 Correct 27 ms 5588 KB Output is correct
23 Correct 25 ms 5332 KB Output is correct
24 Correct 26 ms 5332 KB Output is correct
25 Correct 28 ms 5336 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 3296 KB Output is correct
30 Correct 20 ms 4056 KB Output is correct
31 Correct 28 ms 5332 KB Output is correct
32 Correct 29 ms 5332 KB Output is correct
33 Correct 28 ms 5332 KB Output is correct
34 Correct 30 ms 5332 KB Output is correct
35 Correct 29 ms 5332 KB Output is correct
36 Correct 29 ms 5332 KB Output is correct
37 Correct 28 ms 5332 KB Output is correct
38 Correct 27 ms 5332 KB Output is correct
39 Correct 29 ms 5332 KB Output is correct
40 Correct 29 ms 5500 KB Output is correct
41 Correct 1 ms 2660 KB Output is correct
42 Correct 1 ms 2652 KB Output is correct
43 Correct 2 ms 2512 KB Output is correct
44 Correct 2 ms 2652 KB Output is correct
45 Correct 2 ms 2652 KB Output is correct
46 Correct 3 ms 2648 KB Output is correct
47 Correct 8 ms 3040 KB Output is correct
48 Correct 9 ms 3036 KB Output is correct
49 Correct 16 ms 3548 KB Output is correct
50 Correct 30 ms 4312 KB Output is correct
51 Correct 45 ms 5836 KB Output is correct
52 Correct 45 ms 5836 KB Output is correct
53 Correct 45 ms 5844 KB Output is correct
54 Correct 44 ms 5848 KB Output is correct
55 Correct 45 ms 5848 KB Output is correct
56 Correct 45 ms 5844 KB Output is correct
57 Correct 47 ms 5844 KB Output is correct
58 Correct 45 ms 5844 KB Output is correct
59 Correct 44 ms 5844 KB Output is correct
60 Correct 44 ms 5844 KB Output is correct
61 Correct 47 ms 5856 KB Output is correct
62 Correct 45 ms 5844 KB Output is correct
63 Correct 44 ms 5844 KB Output is correct
64 Correct 46 ms 5844 KB Output is correct
65 Correct 46 ms 5580 KB Output is correct
66 Correct 45 ms 5820 KB Output is correct
67 Correct 44 ms 5844 KB Output is correct
68 Correct 45 ms 5844 KB Output is correct
69 Correct 44 ms 5848 KB Output is correct
70 Correct 45 ms 5836 KB Output is correct
71 Correct 12 ms 3292 KB Output is correct
72 Correct 11 ms 3040 KB Output is correct
73 Correct 11 ms 3040 KB Output is correct
74 Correct 10 ms 3036 KB Output is correct
75 Correct 11 ms 3036 KB Output is correct
76 Correct 28 ms 3552 KB Output is correct
77 Correct 29 ms 3548 KB Output is correct
78 Correct 28 ms 3552 KB Output is correct
79 Correct 27 ms 3552 KB Output is correct
80 Correct 29 ms 3548 KB Output is correct
81 Correct 74 ms 4568 KB Output is correct
82 Correct 74 ms 4568 KB Output is correct
83 Correct 75 ms 4568 KB Output is correct
84 Correct 75 ms 4380 KB Output is correct
85 Correct 73 ms 4572 KB Output is correct
86 Correct 185 ms 4808 KB Output is correct
87 Correct 185 ms 4680 KB Output is correct
88 Correct 186 ms 4824 KB Output is correct
89 Correct 186 ms 4808 KB Output is correct
90 Correct 187 ms 4812 KB Output is correct
91 Correct 3718 ms 6856 KB Output is correct
92 Correct 3724 ms 6852 KB Output is correct
93 Correct 3688 ms 7108 KB Output is correct
94 Correct 3705 ms 6940 KB Output is correct
95 Correct 3725 ms 6948 KB Output is correct
96 Execution timed out 7012 ms 8384 KB Time limit exceeded
97 Halted 0 ms 0 KB -
# 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 2648 KB Output is correct
4 Correct 1 ms 2648 KB Output is correct
5 Correct 1 ms 2648 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2648 KB Output is correct
8 Correct 1 ms 2648 KB Output is correct
9 Correct 1 ms 2648 KB Output is correct
10 Correct 1 ms 2648 KB Output is correct
11 Correct 1 ms 2648 KB Output is correct
12 Correct 1 ms 2648 KB Output is correct
13 Correct 2 ms 2652 KB Output is correct
14 Correct 8 ms 3036 KB Output is correct
15 Correct 16 ms 3544 KB Output is correct
16 Correct 25 ms 4564 KB Output is correct
17 Correct 23 ms 5076 KB Output is correct
18 Correct 25 ms 5336 KB Output is correct
19 Correct 25 ms 5332 KB Output is correct
20 Correct 26 ms 5332 KB Output is correct
21 Correct 25 ms 5332 KB Output is correct
22 Correct 27 ms 5588 KB Output is correct
23 Correct 25 ms 5332 KB Output is correct
24 Correct 26 ms 5332 KB Output is correct
25 Correct 28 ms 5336 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 3296 KB Output is correct
30 Correct 20 ms 4056 KB Output is correct
31 Correct 28 ms 5332 KB Output is correct
32 Correct 29 ms 5332 KB Output is correct
33 Correct 28 ms 5332 KB Output is correct
34 Correct 30 ms 5332 KB Output is correct
35 Correct 29 ms 5332 KB Output is correct
36 Correct 29 ms 5332 KB Output is correct
37 Correct 28 ms 5332 KB Output is correct
38 Correct 27 ms 5332 KB Output is correct
39 Correct 29 ms 5332 KB Output is correct
40 Correct 29 ms 5500 KB Output is correct
41 Correct 1 ms 2660 KB Output is correct
42 Correct 1 ms 2652 KB Output is correct
43 Correct 2 ms 2512 KB Output is correct
44 Correct 2 ms 2652 KB Output is correct
45 Correct 2 ms 2652 KB Output is correct
46 Correct 3 ms 2648 KB Output is correct
47 Correct 8 ms 3040 KB Output is correct
48 Correct 9 ms 3036 KB Output is correct
49 Correct 16 ms 3548 KB Output is correct
50 Correct 30 ms 4312 KB Output is correct
51 Correct 45 ms 5836 KB Output is correct
52 Correct 45 ms 5836 KB Output is correct
53 Correct 45 ms 5844 KB Output is correct
54 Correct 44 ms 5848 KB Output is correct
55 Correct 45 ms 5848 KB Output is correct
56 Correct 45 ms 5844 KB Output is correct
57 Correct 47 ms 5844 KB Output is correct
58 Correct 45 ms 5844 KB Output is correct
59 Correct 44 ms 5844 KB Output is correct
60 Correct 44 ms 5844 KB Output is correct
61 Correct 47 ms 5856 KB Output is correct
62 Correct 45 ms 5844 KB Output is correct
63 Correct 44 ms 5844 KB Output is correct
64 Correct 46 ms 5844 KB Output is correct
65 Correct 46 ms 5580 KB Output is correct
66 Correct 45 ms 5820 KB Output is correct
67 Correct 44 ms 5844 KB Output is correct
68 Correct 45 ms 5844 KB Output is correct
69 Correct 44 ms 5848 KB Output is correct
70 Correct 45 ms 5836 KB Output is correct
71 Correct 12 ms 3292 KB Output is correct
72 Correct 11 ms 3040 KB Output is correct
73 Correct 11 ms 3040 KB Output is correct
74 Correct 10 ms 3036 KB Output is correct
75 Correct 11 ms 3036 KB Output is correct
76 Correct 28 ms 3552 KB Output is correct
77 Correct 29 ms 3548 KB Output is correct
78 Correct 28 ms 3552 KB Output is correct
79 Correct 27 ms 3552 KB Output is correct
80 Correct 29 ms 3548 KB Output is correct
81 Correct 74 ms 4568 KB Output is correct
82 Correct 74 ms 4568 KB Output is correct
83 Correct 75 ms 4568 KB Output is correct
84 Correct 75 ms 4380 KB Output is correct
85 Correct 73 ms 4572 KB Output is correct
86 Correct 185 ms 4808 KB Output is correct
87 Correct 185 ms 4680 KB Output is correct
88 Correct 186 ms 4824 KB Output is correct
89 Correct 186 ms 4808 KB Output is correct
90 Correct 187 ms 4812 KB Output is correct
91 Correct 3718 ms 6856 KB Output is correct
92 Correct 3724 ms 6852 KB Output is correct
93 Correct 3688 ms 7108 KB Output is correct
94 Correct 3705 ms 6940 KB Output is correct
95 Correct 3725 ms 6948 KB Output is correct
96 Execution timed out 7012 ms 8384 KB Time limit exceeded
97 Halted 0 ms 0 KB -