Submission #1034013

# Submission time Handle Problem Language Result Execution time Memory
1034013 2024-07-25T08:44:51 Z vjudge1 Diversity (CEOI21_diversity) C++17
64 / 100
7000 ms 11028 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define all(x) x.begin(), x.end()

const int N = 3e5+5;

int n, q, a[N];

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

  cin >> n >> q;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  while (q--) {
    int l, r;
    cin >> l >> r;
    l--; r--;

    int sz = r-l+1;
    vector<int> vt(sz);
    for (int i = l; i <= r; i++) {
      vt[i-l] = a[i];
    }
    sort(all(vt));

    //for (int& x : vt) cerr << x << " ";
    //cerr << endl;

    vector<int> s;
    int cnt = 0;
    for (int i = 0; i < sz; i++) {
      if (i && vt[i] != vt[i-1]) {
        s.push_back(cnt);
        cnt = 1;
      }
      else cnt++;
    }
    s.push_back(cnt);

    sort(all(s));
  
    //for (int& x : s) cerr << x << " ";
    //cerr << endl;

    deque<int> dq;
    int szS = s.size();
    for (int i = 0; i < szS; i+=2) {
      dq.push_back(s[i]);
    }
    for (int i = szS - (szS % 2 ? 2 : 1); i >= 0; i-=2) {
      dq.push_back(s[i]);
    }

    //for (int& x : dq) cerr << x << " ";
    //cerr << endl;

    int ans = 0;
    int L = 1;
    while (!dq.empty()) {
      int x = dq.front() - 1; dq.pop_front();

      while (x--) {
        ans += L;
        L++;
      }

      ans += L * (sz-L+1);
      L++;
    }

    cout << ans << "\n";
  }
}
# 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 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 432 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 600 KB Output is correct
3 Correct 1 ms 600 KB Output is correct
4 Correct 6 ms 2140 KB Output is correct
5 Correct 12 ms 3932 KB Output is correct
6 Correct 24 ms 5772 KB Output is correct
7 Correct 19 ms 5724 KB Output is correct
8 Correct 19 ms 5724 KB Output is correct
9 Correct 18 ms 5752 KB Output is correct
10 Correct 24 ms 5744 KB Output is correct
11 Correct 19 ms 5768 KB Output is correct
12 Correct 19 ms 5724 KB Output is correct
13 Correct 23 ms 5720 KB Output is correct
14 Correct 19 ms 5724 KB Output is correct
15 Correct 19 ms 5724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 600 KB Output is correct
3 Correct 1 ms 600 KB Output is correct
4 Correct 6 ms 2140 KB Output is correct
5 Correct 12 ms 3932 KB Output is correct
6 Correct 24 ms 5772 KB Output is correct
7 Correct 19 ms 5724 KB Output is correct
8 Correct 19 ms 5724 KB Output is correct
9 Correct 18 ms 5752 KB Output is correct
10 Correct 24 ms 5744 KB Output is correct
11 Correct 19 ms 5768 KB Output is correct
12 Correct 19 ms 5724 KB Output is correct
13 Correct 23 ms 5720 KB Output is correct
14 Correct 19 ms 5724 KB Output is correct
15 Correct 19 ms 5724 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 604 KB Output is correct
19 Correct 7 ms 2140 KB Output is correct
20 Correct 14 ms 3932 KB Output is correct
21 Correct 20 ms 5988 KB Output is correct
22 Correct 23 ms 5756 KB Output is correct
23 Correct 21 ms 5720 KB Output is correct
24 Correct 21 ms 5724 KB Output is correct
25 Correct 21 ms 5784 KB Output is correct
26 Correct 23 ms 5720 KB Output is correct
27 Correct 21 ms 5724 KB Output is correct
28 Correct 20 ms 5740 KB Output is correct
29 Correct 21 ms 5848 KB Output is correct
30 Correct 21 ms 5724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 600 KB Output is correct
3 Correct 1 ms 600 KB Output is correct
4 Correct 6 ms 2140 KB Output is correct
5 Correct 12 ms 3932 KB Output is correct
6 Correct 24 ms 5772 KB Output is correct
7 Correct 19 ms 5724 KB Output is correct
8 Correct 19 ms 5724 KB Output is correct
9 Correct 18 ms 5752 KB Output is correct
10 Correct 24 ms 5744 KB Output is correct
11 Correct 19 ms 5768 KB Output is correct
12 Correct 19 ms 5724 KB Output is correct
13 Correct 23 ms 5720 KB Output is correct
14 Correct 19 ms 5724 KB Output is correct
15 Correct 19 ms 5724 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 604 KB Output is correct
19 Correct 7 ms 2140 KB Output is correct
20 Correct 14 ms 3932 KB Output is correct
21 Correct 20 ms 5988 KB Output is correct
22 Correct 23 ms 5756 KB Output is correct
23 Correct 21 ms 5720 KB Output is correct
24 Correct 21 ms 5724 KB Output is correct
25 Correct 21 ms 5784 KB Output is correct
26 Correct 23 ms 5720 KB Output is correct
27 Correct 21 ms 5724 KB Output is correct
28 Correct 20 ms 5740 KB Output is correct
29 Correct 21 ms 5848 KB Output is correct
30 Correct 21 ms 5724 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 0 ms 360 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 1 ms 604 KB Output is correct
35 Correct 1 ms 604 KB Output is correct
36 Correct 1 ms 604 KB Output is correct
37 Correct 5 ms 1420 KB Output is correct
38 Correct 5 ms 1372 KB Output is correct
39 Correct 10 ms 2396 KB Output is correct
40 Correct 18 ms 4188 KB Output is correct
41 Correct 27 ms 6232 KB Output is correct
42 Correct 32 ms 6296 KB Output is correct
43 Correct 26 ms 6300 KB Output is correct
44 Correct 27 ms 6232 KB Output is correct
45 Correct 26 ms 6236 KB Output is correct
46 Correct 26 ms 6236 KB Output is correct
47 Correct 26 ms 6308 KB Output is correct
48 Correct 25 ms 6304 KB Output is correct
49 Correct 26 ms 6232 KB Output is correct
50 Correct 26 ms 6236 KB Output is correct
51 Correct 29 ms 6484 KB Output is correct
52 Correct 26 ms 6236 KB Output is correct
53 Correct 26 ms 6324 KB Output is correct
54 Correct 26 ms 6236 KB Output is correct
55 Correct 26 ms 6236 KB Output is correct
56 Correct 28 ms 6308 KB Output is correct
57 Correct 26 ms 6236 KB Output is correct
58 Correct 26 ms 6248 KB Output is correct
59 Correct 26 ms 6232 KB Output is correct
60 Correct 29 ms 6744 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 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 432 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 1 ms 600 KB Output is correct
13 Correct 1 ms 600 KB Output is correct
14 Correct 6 ms 2140 KB Output is correct
15 Correct 12 ms 3932 KB Output is correct
16 Correct 24 ms 5772 KB Output is correct
17 Correct 19 ms 5724 KB Output is correct
18 Correct 19 ms 5724 KB Output is correct
19 Correct 18 ms 5752 KB Output is correct
20 Correct 24 ms 5744 KB Output is correct
21 Correct 19 ms 5768 KB Output is correct
22 Correct 19 ms 5724 KB Output is correct
23 Correct 23 ms 5720 KB Output is correct
24 Correct 19 ms 5724 KB Output is correct
25 Correct 19 ms 5724 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 604 KB Output is correct
29 Correct 7 ms 2140 KB Output is correct
30 Correct 14 ms 3932 KB Output is correct
31 Correct 20 ms 5988 KB Output is correct
32 Correct 23 ms 5756 KB Output is correct
33 Correct 21 ms 5720 KB Output is correct
34 Correct 21 ms 5724 KB Output is correct
35 Correct 21 ms 5784 KB Output is correct
36 Correct 23 ms 5720 KB Output is correct
37 Correct 21 ms 5724 KB Output is correct
38 Correct 20 ms 5740 KB Output is correct
39 Correct 21 ms 5848 KB Output is correct
40 Correct 21 ms 5724 KB Output is correct
41 Correct 0 ms 344 KB Output is correct
42 Correct 0 ms 360 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 1 ms 604 KB Output is correct
45 Correct 1 ms 604 KB Output is correct
46 Correct 1 ms 604 KB Output is correct
47 Correct 5 ms 1420 KB Output is correct
48 Correct 5 ms 1372 KB Output is correct
49 Correct 10 ms 2396 KB Output is correct
50 Correct 18 ms 4188 KB Output is correct
51 Correct 27 ms 6232 KB Output is correct
52 Correct 32 ms 6296 KB Output is correct
53 Correct 26 ms 6300 KB Output is correct
54 Correct 27 ms 6232 KB Output is correct
55 Correct 26 ms 6236 KB Output is correct
56 Correct 26 ms 6236 KB Output is correct
57 Correct 26 ms 6308 KB Output is correct
58 Correct 25 ms 6304 KB Output is correct
59 Correct 26 ms 6232 KB Output is correct
60 Correct 26 ms 6236 KB Output is correct
61 Correct 29 ms 6484 KB Output is correct
62 Correct 26 ms 6236 KB Output is correct
63 Correct 26 ms 6324 KB Output is correct
64 Correct 26 ms 6236 KB Output is correct
65 Correct 26 ms 6236 KB Output is correct
66 Correct 28 ms 6308 KB Output is correct
67 Correct 26 ms 6236 KB Output is correct
68 Correct 26 ms 6248 KB Output is correct
69 Correct 26 ms 6232 KB Output is correct
70 Correct 29 ms 6744 KB Output is correct
71 Correct 5 ms 1368 KB Output is correct
72 Correct 5 ms 1400 KB Output is correct
73 Correct 6 ms 1372 KB Output is correct
74 Correct 5 ms 1372 KB Output is correct
75 Correct 5 ms 1372 KB Output is correct
76 Correct 11 ms 2392 KB Output is correct
77 Correct 11 ms 2396 KB Output is correct
78 Correct 10 ms 2512 KB Output is correct
79 Correct 11 ms 2396 KB Output is correct
80 Correct 11 ms 2512 KB Output is correct
81 Correct 24 ms 4688 KB Output is correct
82 Correct 22 ms 4692 KB Output is correct
83 Correct 21 ms 4556 KB Output is correct
84 Correct 22 ms 4692 KB Output is correct
85 Correct 23 ms 4552 KB Output is correct
86 Correct 25 ms 5200 KB Output is correct
87 Correct 24 ms 4944 KB Output is correct
88 Correct 28 ms 4948 KB Output is correct
89 Correct 24 ms 4920 KB Output is correct
90 Correct 23 ms 4956 KB Output is correct
91 Correct 40 ms 8396 KB Output is correct
92 Correct 43 ms 8408 KB Output is correct
93 Correct 40 ms 8396 KB Output is correct
94 Correct 39 ms 8396 KB Output is correct
95 Correct 39 ms 8296 KB Output is correct
96 Correct 47 ms 10104 KB Output is correct
97 Correct 43 ms 10184 KB Output is correct
98 Correct 43 ms 10196 KB Output is correct
99 Correct 44 ms 10188 KB Output is correct
100 Correct 44 ms 10176 KB Output is correct
101 Correct 48 ms 10188 KB Output is correct
102 Correct 44 ms 10188 KB Output is correct
103 Correct 44 ms 10188 KB Output is correct
104 Correct 43 ms 10164 KB Output is correct
105 Correct 42 ms 10184 KB Output is correct
106 Correct 43 ms 10956 KB Output is correct
107 Correct 43 ms 10952 KB Output is correct
108 Correct 44 ms 10952 KB Output is correct
109 Correct 51 ms 10956 KB Output is correct
110 Correct 47 ms 10956 KB Output is correct
111 Correct 44 ms 10908 KB Output is correct
112 Correct 41 ms 10952 KB Output is correct
113 Correct 48 ms 10956 KB Output is correct
114 Correct 44 ms 11028 KB Output is correct
115 Correct 43 ms 10956 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 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 432 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 1 ms 600 KB Output is correct
13 Correct 1 ms 600 KB Output is correct
14 Correct 6 ms 2140 KB Output is correct
15 Correct 12 ms 3932 KB Output is correct
16 Correct 24 ms 5772 KB Output is correct
17 Correct 19 ms 5724 KB Output is correct
18 Correct 19 ms 5724 KB Output is correct
19 Correct 18 ms 5752 KB Output is correct
20 Correct 24 ms 5744 KB Output is correct
21 Correct 19 ms 5768 KB Output is correct
22 Correct 19 ms 5724 KB Output is correct
23 Correct 23 ms 5720 KB Output is correct
24 Correct 19 ms 5724 KB Output is correct
25 Correct 19 ms 5724 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 604 KB Output is correct
29 Correct 7 ms 2140 KB Output is correct
30 Correct 14 ms 3932 KB Output is correct
31 Correct 20 ms 5988 KB Output is correct
32 Correct 23 ms 5756 KB Output is correct
33 Correct 21 ms 5720 KB Output is correct
34 Correct 21 ms 5724 KB Output is correct
35 Correct 21 ms 5784 KB Output is correct
36 Correct 23 ms 5720 KB Output is correct
37 Correct 21 ms 5724 KB Output is correct
38 Correct 20 ms 5740 KB Output is correct
39 Correct 21 ms 5848 KB Output is correct
40 Correct 21 ms 5724 KB Output is correct
41 Correct 0 ms 344 KB Output is correct
42 Correct 0 ms 360 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 1 ms 604 KB Output is correct
45 Correct 1 ms 604 KB Output is correct
46 Correct 1 ms 604 KB Output is correct
47 Correct 5 ms 1420 KB Output is correct
48 Correct 5 ms 1372 KB Output is correct
49 Correct 10 ms 2396 KB Output is correct
50 Correct 18 ms 4188 KB Output is correct
51 Correct 27 ms 6232 KB Output is correct
52 Correct 32 ms 6296 KB Output is correct
53 Correct 26 ms 6300 KB Output is correct
54 Correct 27 ms 6232 KB Output is correct
55 Correct 26 ms 6236 KB Output is correct
56 Correct 26 ms 6236 KB Output is correct
57 Correct 26 ms 6308 KB Output is correct
58 Correct 25 ms 6304 KB Output is correct
59 Correct 26 ms 6232 KB Output is correct
60 Correct 26 ms 6236 KB Output is correct
61 Correct 29 ms 6484 KB Output is correct
62 Correct 26 ms 6236 KB Output is correct
63 Correct 26 ms 6324 KB Output is correct
64 Correct 26 ms 6236 KB Output is correct
65 Correct 26 ms 6236 KB Output is correct
66 Correct 28 ms 6308 KB Output is correct
67 Correct 26 ms 6236 KB Output is correct
68 Correct 26 ms 6248 KB Output is correct
69 Correct 26 ms 6232 KB Output is correct
70 Correct 29 ms 6744 KB Output is correct
71 Correct 5 ms 1368 KB Output is correct
72 Correct 5 ms 1400 KB Output is correct
73 Correct 6 ms 1372 KB Output is correct
74 Correct 5 ms 1372 KB Output is correct
75 Correct 5 ms 1372 KB Output is correct
76 Correct 11 ms 2392 KB Output is correct
77 Correct 11 ms 2396 KB Output is correct
78 Correct 10 ms 2512 KB Output is correct
79 Correct 11 ms 2396 KB Output is correct
80 Correct 11 ms 2512 KB Output is correct
81 Correct 24 ms 4688 KB Output is correct
82 Correct 22 ms 4692 KB Output is correct
83 Correct 21 ms 4556 KB Output is correct
84 Correct 22 ms 4692 KB Output is correct
85 Correct 23 ms 4552 KB Output is correct
86 Correct 25 ms 5200 KB Output is correct
87 Correct 24 ms 4944 KB Output is correct
88 Correct 28 ms 4948 KB Output is correct
89 Correct 24 ms 4920 KB Output is correct
90 Correct 23 ms 4956 KB Output is correct
91 Correct 40 ms 8396 KB Output is correct
92 Correct 43 ms 8408 KB Output is correct
93 Correct 40 ms 8396 KB Output is correct
94 Correct 39 ms 8396 KB Output is correct
95 Correct 39 ms 8296 KB Output is correct
96 Correct 47 ms 10104 KB Output is correct
97 Correct 43 ms 10184 KB Output is correct
98 Correct 43 ms 10196 KB Output is correct
99 Correct 44 ms 10188 KB Output is correct
100 Correct 44 ms 10176 KB Output is correct
101 Correct 48 ms 10188 KB Output is correct
102 Correct 44 ms 10188 KB Output is correct
103 Correct 44 ms 10188 KB Output is correct
104 Correct 43 ms 10164 KB Output is correct
105 Correct 42 ms 10184 KB Output is correct
106 Correct 43 ms 10956 KB Output is correct
107 Correct 43 ms 10952 KB Output is correct
108 Correct 44 ms 10952 KB Output is correct
109 Correct 51 ms 10956 KB Output is correct
110 Correct 47 ms 10956 KB Output is correct
111 Correct 44 ms 10908 KB Output is correct
112 Correct 41 ms 10952 KB Output is correct
113 Correct 48 ms 10956 KB Output is correct
114 Correct 44 ms 11028 KB Output is correct
115 Correct 43 ms 10956 KB Output is correct
116 Correct 4354 ms 1444 KB Output is correct
117 Correct 5083 ms 1432 KB Output is correct
118 Execution timed out 7059 ms 1884 KB Time limit exceeded
119 Halted 0 ms 0 KB -