Submission #1089878

# Submission time Handle Problem Language Result Execution time Memory
1089878 2024-09-17T10:58:23 Z juicy Diversity (CEOI21_diversity) C++17
64 / 100
7000 ms 5892 KB
#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif

int main() {
  ios::sync_with_stdio(false); cin.tie(nullptr);

  int n, q; cin >> n >> q;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  while (q--) {
    int l, r; cin >> l >> r;
    auto b = vector(a.begin() + l - 1, a.begin() + r);
    sort(b.begin(), b.end());
    vector<int> cnd;
    int m = b.size();
    for (int i = 0; i < m; ) {
      int j = i;
      while (j < m && b[j] == b[i]) {
        ++j;
      }
      cnd.push_back(j - i);
      i = j;
    }
    sort(cnd.begin(), cnd.end());
    int i = 0, j = m;
    long long res = (long long) m * (m + 1) / 2;
    for (int k = 0; k < cnd.size(); ++k) {
      if (k & 1) {
        j -= cnd[k];
        res += (long long) j * (m - j);
      } else {
        res += (long long) i * (m - i);
        i += cnd[k];
      }
    }
    cout << res << "\n";
  }
  return 0;
}

Compilation message

diversity.cpp: In function 'int main()':
diversity.cpp:36:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |     for (int k = 0; k < cnd.size(); ++k) {
      |                     ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 388 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 6 ms 1388 KB Output is correct
5 Correct 12 ms 2396 KB Output is correct
6 Correct 18 ms 3292 KB Output is correct
7 Correct 18 ms 3416 KB Output is correct
8 Correct 24 ms 3420 KB Output is correct
9 Correct 18 ms 3420 KB Output is correct
10 Correct 18 ms 3420 KB Output is correct
11 Correct 18 ms 3420 KB Output is correct
12 Correct 19 ms 3420 KB Output is correct
13 Correct 19 ms 3420 KB Output is correct
14 Correct 18 ms 3416 KB Output is correct
15 Correct 18 ms 3416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 6 ms 1388 KB Output is correct
5 Correct 12 ms 2396 KB Output is correct
6 Correct 18 ms 3292 KB Output is correct
7 Correct 18 ms 3416 KB Output is correct
8 Correct 24 ms 3420 KB Output is correct
9 Correct 18 ms 3420 KB Output is correct
10 Correct 18 ms 3420 KB Output is correct
11 Correct 18 ms 3420 KB Output is correct
12 Correct 19 ms 3420 KB Output is correct
13 Correct 19 ms 3420 KB Output is correct
14 Correct 18 ms 3416 KB Output is correct
15 Correct 18 ms 3416 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 524 KB Output is correct
19 Correct 7 ms 1372 KB Output is correct
20 Correct 14 ms 2520 KB Output is correct
21 Correct 20 ms 3544 KB Output is correct
22 Correct 22 ms 3452 KB Output is correct
23 Correct 20 ms 3416 KB Output is correct
24 Correct 20 ms 3416 KB Output is correct
25 Correct 20 ms 3548 KB Output is correct
26 Correct 20 ms 3548 KB Output is correct
27 Correct 20 ms 3420 KB Output is correct
28 Correct 22 ms 3420 KB Output is correct
29 Correct 22 ms 3420 KB Output is correct
30 Correct 20 ms 3468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 6 ms 1388 KB Output is correct
5 Correct 12 ms 2396 KB Output is correct
6 Correct 18 ms 3292 KB Output is correct
7 Correct 18 ms 3416 KB Output is correct
8 Correct 24 ms 3420 KB Output is correct
9 Correct 18 ms 3420 KB Output is correct
10 Correct 18 ms 3420 KB Output is correct
11 Correct 18 ms 3420 KB Output is correct
12 Correct 19 ms 3420 KB Output is correct
13 Correct 19 ms 3420 KB Output is correct
14 Correct 18 ms 3416 KB Output is correct
15 Correct 18 ms 3416 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 524 KB Output is correct
19 Correct 7 ms 1372 KB Output is correct
20 Correct 14 ms 2520 KB Output is correct
21 Correct 20 ms 3544 KB Output is correct
22 Correct 22 ms 3452 KB Output is correct
23 Correct 20 ms 3416 KB Output is correct
24 Correct 20 ms 3416 KB Output is correct
25 Correct 20 ms 3548 KB Output is correct
26 Correct 20 ms 3548 KB Output is correct
27 Correct 20 ms 3420 KB Output is correct
28 Correct 22 ms 3420 KB Output is correct
29 Correct 22 ms 3420 KB Output is correct
30 Correct 20 ms 3468 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 1 ms 580 KB Output is correct
37 Correct 4 ms 848 KB Output is correct
38 Correct 5 ms 860 KB Output is correct
39 Correct 9 ms 1628 KB Output is correct
40 Correct 19 ms 2652 KB Output is correct
41 Correct 26 ms 3928 KB Output is correct
42 Correct 26 ms 3800 KB Output is correct
43 Correct 26 ms 3928 KB Output is correct
44 Correct 26 ms 3932 KB Output is correct
45 Correct 27 ms 3812 KB Output is correct
46 Correct 27 ms 3932 KB Output is correct
47 Correct 27 ms 3800 KB Output is correct
48 Correct 26 ms 3928 KB Output is correct
49 Correct 26 ms 3928 KB Output is correct
50 Correct 26 ms 3940 KB Output is correct
51 Correct 25 ms 3932 KB Output is correct
52 Correct 26 ms 3932 KB Output is correct
53 Correct 26 ms 3928 KB Output is correct
54 Correct 27 ms 3928 KB Output is correct
55 Correct 27 ms 3932 KB Output is correct
56 Correct 29 ms 3932 KB Output is correct
57 Correct 29 ms 3928 KB Output is correct
58 Correct 26 ms 3932 KB Output is correct
59 Correct 26 ms 3932 KB Output is correct
60 Correct 27 ms 3932 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 388 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 6 ms 1388 KB Output is correct
15 Correct 12 ms 2396 KB Output is correct
16 Correct 18 ms 3292 KB Output is correct
17 Correct 18 ms 3416 KB Output is correct
18 Correct 24 ms 3420 KB Output is correct
19 Correct 18 ms 3420 KB Output is correct
20 Correct 18 ms 3420 KB Output is correct
21 Correct 18 ms 3420 KB Output is correct
22 Correct 19 ms 3420 KB Output is correct
23 Correct 19 ms 3420 KB Output is correct
24 Correct 18 ms 3416 KB Output is correct
25 Correct 18 ms 3416 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 1 ms 524 KB Output is correct
29 Correct 7 ms 1372 KB Output is correct
30 Correct 14 ms 2520 KB Output is correct
31 Correct 20 ms 3544 KB Output is correct
32 Correct 22 ms 3452 KB Output is correct
33 Correct 20 ms 3416 KB Output is correct
34 Correct 20 ms 3416 KB Output is correct
35 Correct 20 ms 3548 KB Output is correct
36 Correct 20 ms 3548 KB Output is correct
37 Correct 20 ms 3420 KB Output is correct
38 Correct 22 ms 3420 KB Output is correct
39 Correct 22 ms 3420 KB Output is correct
40 Correct 20 ms 3468 KB Output is correct
41 Correct 0 ms 344 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 1 ms 348 KB Output is correct
45 Correct 1 ms 348 KB Output is correct
46 Correct 1 ms 580 KB Output is correct
47 Correct 4 ms 848 KB Output is correct
48 Correct 5 ms 860 KB Output is correct
49 Correct 9 ms 1628 KB Output is correct
50 Correct 19 ms 2652 KB Output is correct
51 Correct 26 ms 3928 KB Output is correct
52 Correct 26 ms 3800 KB Output is correct
53 Correct 26 ms 3928 KB Output is correct
54 Correct 26 ms 3932 KB Output is correct
55 Correct 27 ms 3812 KB Output is correct
56 Correct 27 ms 3932 KB Output is correct
57 Correct 27 ms 3800 KB Output is correct
58 Correct 26 ms 3928 KB Output is correct
59 Correct 26 ms 3928 KB Output is correct
60 Correct 26 ms 3940 KB Output is correct
61 Correct 25 ms 3932 KB Output is correct
62 Correct 26 ms 3932 KB Output is correct
63 Correct 26 ms 3928 KB Output is correct
64 Correct 27 ms 3928 KB Output is correct
65 Correct 27 ms 3932 KB Output is correct
66 Correct 29 ms 3932 KB Output is correct
67 Correct 29 ms 3928 KB Output is correct
68 Correct 26 ms 3932 KB Output is correct
69 Correct 26 ms 3932 KB Output is correct
70 Correct 27 ms 3932 KB Output is correct
71 Correct 6 ms 856 KB Output is correct
72 Correct 5 ms 860 KB Output is correct
73 Correct 5 ms 860 KB Output is correct
74 Correct 5 ms 860 KB Output is correct
75 Correct 5 ms 980 KB Output is correct
76 Correct 11 ms 1720 KB Output is correct
77 Correct 11 ms 1628 KB Output is correct
78 Correct 11 ms 1720 KB Output is correct
79 Correct 11 ms 1628 KB Output is correct
80 Correct 11 ms 1728 KB Output is correct
81 Correct 21 ms 3028 KB Output is correct
82 Correct 22 ms 2904 KB Output is correct
83 Correct 22 ms 3016 KB Output is correct
84 Correct 21 ms 2904 KB Output is correct
85 Correct 22 ms 2904 KB Output is correct
86 Correct 24 ms 3156 KB Output is correct
87 Correct 23 ms 3152 KB Output is correct
88 Correct 23 ms 3164 KB Output is correct
89 Correct 23 ms 3156 KB Output is correct
90 Correct 24 ms 3088 KB Output is correct
91 Correct 43 ms 4928 KB Output is correct
92 Correct 40 ms 5076 KB Output is correct
93 Correct 40 ms 5084 KB Output is correct
94 Correct 39 ms 4936 KB Output is correct
95 Correct 39 ms 5076 KB Output is correct
96 Correct 43 ms 5840 KB Output is correct
97 Correct 41 ms 5836 KB Output is correct
98 Correct 43 ms 5852 KB Output is correct
99 Correct 43 ms 5844 KB Output is correct
100 Correct 42 ms 5708 KB Output is correct
101 Correct 45 ms 5844 KB Output is correct
102 Correct 48 ms 5852 KB Output is correct
103 Correct 43 ms 5716 KB Output is correct
104 Correct 42 ms 5836 KB Output is correct
105 Correct 42 ms 5840 KB Output is correct
106 Correct 44 ms 5736 KB Output is correct
107 Correct 43 ms 5868 KB Output is correct
108 Correct 43 ms 5840 KB Output is correct
109 Correct 42 ms 5840 KB Output is correct
110 Correct 42 ms 5892 KB Output is correct
111 Correct 43 ms 5844 KB Output is correct
112 Correct 42 ms 5840 KB Output is correct
113 Correct 43 ms 5844 KB Output is correct
114 Correct 42 ms 5844 KB Output is correct
115 Correct 50 ms 5736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 388 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 6 ms 1388 KB Output is correct
15 Correct 12 ms 2396 KB Output is correct
16 Correct 18 ms 3292 KB Output is correct
17 Correct 18 ms 3416 KB Output is correct
18 Correct 24 ms 3420 KB Output is correct
19 Correct 18 ms 3420 KB Output is correct
20 Correct 18 ms 3420 KB Output is correct
21 Correct 18 ms 3420 KB Output is correct
22 Correct 19 ms 3420 KB Output is correct
23 Correct 19 ms 3420 KB Output is correct
24 Correct 18 ms 3416 KB Output is correct
25 Correct 18 ms 3416 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 1 ms 524 KB Output is correct
29 Correct 7 ms 1372 KB Output is correct
30 Correct 14 ms 2520 KB Output is correct
31 Correct 20 ms 3544 KB Output is correct
32 Correct 22 ms 3452 KB Output is correct
33 Correct 20 ms 3416 KB Output is correct
34 Correct 20 ms 3416 KB Output is correct
35 Correct 20 ms 3548 KB Output is correct
36 Correct 20 ms 3548 KB Output is correct
37 Correct 20 ms 3420 KB Output is correct
38 Correct 22 ms 3420 KB Output is correct
39 Correct 22 ms 3420 KB Output is correct
40 Correct 20 ms 3468 KB Output is correct
41 Correct 0 ms 344 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 1 ms 348 KB Output is correct
45 Correct 1 ms 348 KB Output is correct
46 Correct 1 ms 580 KB Output is correct
47 Correct 4 ms 848 KB Output is correct
48 Correct 5 ms 860 KB Output is correct
49 Correct 9 ms 1628 KB Output is correct
50 Correct 19 ms 2652 KB Output is correct
51 Correct 26 ms 3928 KB Output is correct
52 Correct 26 ms 3800 KB Output is correct
53 Correct 26 ms 3928 KB Output is correct
54 Correct 26 ms 3932 KB Output is correct
55 Correct 27 ms 3812 KB Output is correct
56 Correct 27 ms 3932 KB Output is correct
57 Correct 27 ms 3800 KB Output is correct
58 Correct 26 ms 3928 KB Output is correct
59 Correct 26 ms 3928 KB Output is correct
60 Correct 26 ms 3940 KB Output is correct
61 Correct 25 ms 3932 KB Output is correct
62 Correct 26 ms 3932 KB Output is correct
63 Correct 26 ms 3928 KB Output is correct
64 Correct 27 ms 3928 KB Output is correct
65 Correct 27 ms 3932 KB Output is correct
66 Correct 29 ms 3932 KB Output is correct
67 Correct 29 ms 3928 KB Output is correct
68 Correct 26 ms 3932 KB Output is correct
69 Correct 26 ms 3932 KB Output is correct
70 Correct 27 ms 3932 KB Output is correct
71 Correct 6 ms 856 KB Output is correct
72 Correct 5 ms 860 KB Output is correct
73 Correct 5 ms 860 KB Output is correct
74 Correct 5 ms 860 KB Output is correct
75 Correct 5 ms 980 KB Output is correct
76 Correct 11 ms 1720 KB Output is correct
77 Correct 11 ms 1628 KB Output is correct
78 Correct 11 ms 1720 KB Output is correct
79 Correct 11 ms 1628 KB Output is correct
80 Correct 11 ms 1728 KB Output is correct
81 Correct 21 ms 3028 KB Output is correct
82 Correct 22 ms 2904 KB Output is correct
83 Correct 22 ms 3016 KB Output is correct
84 Correct 21 ms 2904 KB Output is correct
85 Correct 22 ms 2904 KB Output is correct
86 Correct 24 ms 3156 KB Output is correct
87 Correct 23 ms 3152 KB Output is correct
88 Correct 23 ms 3164 KB Output is correct
89 Correct 23 ms 3156 KB Output is correct
90 Correct 24 ms 3088 KB Output is correct
91 Correct 43 ms 4928 KB Output is correct
92 Correct 40 ms 5076 KB Output is correct
93 Correct 40 ms 5084 KB Output is correct
94 Correct 39 ms 4936 KB Output is correct
95 Correct 39 ms 5076 KB Output is correct
96 Correct 43 ms 5840 KB Output is correct
97 Correct 41 ms 5836 KB Output is correct
98 Correct 43 ms 5852 KB Output is correct
99 Correct 43 ms 5844 KB Output is correct
100 Correct 42 ms 5708 KB Output is correct
101 Correct 45 ms 5844 KB Output is correct
102 Correct 48 ms 5852 KB Output is correct
103 Correct 43 ms 5716 KB Output is correct
104 Correct 42 ms 5836 KB Output is correct
105 Correct 42 ms 5840 KB Output is correct
106 Correct 44 ms 5736 KB Output is correct
107 Correct 43 ms 5868 KB Output is correct
108 Correct 43 ms 5840 KB Output is correct
109 Correct 42 ms 5840 KB Output is correct
110 Correct 42 ms 5892 KB Output is correct
111 Correct 43 ms 5844 KB Output is correct
112 Correct 42 ms 5840 KB Output is correct
113 Correct 43 ms 5844 KB Output is correct
114 Correct 42 ms 5844 KB Output is correct
115 Correct 50 ms 5736 KB Output is correct
116 Correct 4544 ms 1420 KB Output is correct
117 Correct 5176 ms 1364 KB Output is correct
118 Execution timed out 7070 ms 1496 KB Time limit exceeded
119 Halted 0 ms 0 KB -