Submission #1034285

# Submission time Handle Problem Language Result Execution time Memory
1034285 2024-07-25T11:46:35 Z vjudge1 Diversity (CEOI21_diversity) C++17
64 / 100
7000 ms 25568 KB
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
#define all(x) x.begin(), x.end()
 
const int N = 3e5;
 
int n, q, a[N];
unordered_map<int, int> mp[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--;
 
    auto it = mp[l].find(r);
    if (it != mp[l].end()) {
      cout << it->second << "\n";
      continue;
    }
 
    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();
 
      // sumar [L, L+x-1]
      ans += (L+x-1)*(L+x)/2 - (L-1)*(L)/2;
      L += x;
 
      ans += L * (sz-L+1);
      L++;
    }
 
    mp[l][r] = ans;
    cout <<  ans << "\n";
  }
}
# Verdict Execution time Memory Grader output
1 Correct 8 ms 16728 KB Output is correct
2 Correct 7 ms 16732 KB Output is correct
3 Correct 7 ms 16732 KB Output is correct
4 Correct 8 ms 16796 KB Output is correct
5 Correct 7 ms 16732 KB Output is correct
6 Correct 7 ms 16732 KB Output is correct
7 Correct 8 ms 16732 KB Output is correct
8 Correct 8 ms 16732 KB Output is correct
9 Correct 8 ms 16732 KB Output is correct
10 Correct 8 ms 16648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 16728 KB Output is correct
2 Correct 8 ms 16732 KB Output is correct
3 Correct 8 ms 16852 KB Output is correct
4 Correct 13 ms 18268 KB Output is correct
5 Correct 24 ms 19804 KB Output is correct
6 Correct 26 ms 21436 KB Output is correct
7 Correct 23 ms 21492 KB Output is correct
8 Correct 24 ms 21596 KB Output is correct
9 Correct 34 ms 21572 KB Output is correct
10 Correct 26 ms 21592 KB Output is correct
11 Correct 25 ms 21596 KB Output is correct
12 Correct 32 ms 21596 KB Output is correct
13 Correct 26 ms 21596 KB Output is correct
14 Correct 26 ms 21592 KB Output is correct
15 Correct 31 ms 21592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 16728 KB Output is correct
2 Correct 8 ms 16732 KB Output is correct
3 Correct 8 ms 16852 KB Output is correct
4 Correct 13 ms 18268 KB Output is correct
5 Correct 24 ms 19804 KB Output is correct
6 Correct 26 ms 21436 KB Output is correct
7 Correct 23 ms 21492 KB Output is correct
8 Correct 24 ms 21596 KB Output is correct
9 Correct 34 ms 21572 KB Output is correct
10 Correct 26 ms 21592 KB Output is correct
11 Correct 25 ms 21596 KB Output is correct
12 Correct 32 ms 21596 KB Output is correct
13 Correct 26 ms 21596 KB Output is correct
14 Correct 26 ms 21592 KB Output is correct
15 Correct 31 ms 21592 KB Output is correct
16 Correct 8 ms 16984 KB Output is correct
17 Correct 7 ms 16732 KB Output is correct
18 Correct 8 ms 16988 KB Output is correct
19 Correct 13 ms 18364 KB Output is correct
20 Correct 21 ms 19804 KB Output is correct
21 Correct 27 ms 21592 KB Output is correct
22 Correct 27 ms 21332 KB Output is correct
23 Correct 30 ms 21592 KB Output is correct
24 Correct 28 ms 21328 KB Output is correct
25 Correct 27 ms 21476 KB Output is correct
26 Correct 29 ms 21596 KB Output is correct
27 Correct 28 ms 21592 KB Output is correct
28 Correct 26 ms 21596 KB Output is correct
29 Correct 29 ms 21588 KB Output is correct
30 Correct 27 ms 21596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 16728 KB Output is correct
2 Correct 8 ms 16732 KB Output is correct
3 Correct 8 ms 16852 KB Output is correct
4 Correct 13 ms 18268 KB Output is correct
5 Correct 24 ms 19804 KB Output is correct
6 Correct 26 ms 21436 KB Output is correct
7 Correct 23 ms 21492 KB Output is correct
8 Correct 24 ms 21596 KB Output is correct
9 Correct 34 ms 21572 KB Output is correct
10 Correct 26 ms 21592 KB Output is correct
11 Correct 25 ms 21596 KB Output is correct
12 Correct 32 ms 21596 KB Output is correct
13 Correct 26 ms 21596 KB Output is correct
14 Correct 26 ms 21592 KB Output is correct
15 Correct 31 ms 21592 KB Output is correct
16 Correct 8 ms 16984 KB Output is correct
17 Correct 7 ms 16732 KB Output is correct
18 Correct 8 ms 16988 KB Output is correct
19 Correct 13 ms 18364 KB Output is correct
20 Correct 21 ms 19804 KB Output is correct
21 Correct 27 ms 21592 KB Output is correct
22 Correct 27 ms 21332 KB Output is correct
23 Correct 30 ms 21592 KB Output is correct
24 Correct 28 ms 21328 KB Output is correct
25 Correct 27 ms 21476 KB Output is correct
26 Correct 29 ms 21596 KB Output is correct
27 Correct 28 ms 21592 KB Output is correct
28 Correct 26 ms 21596 KB Output is correct
29 Correct 29 ms 21588 KB Output is correct
30 Correct 27 ms 21596 KB Output is correct
31 Correct 8 ms 16732 KB Output is correct
32 Correct 7 ms 16728 KB Output is correct
33 Correct 8 ms 16732 KB Output is correct
34 Correct 8 ms 16984 KB Output is correct
35 Correct 9 ms 17064 KB Output is correct
36 Correct 9 ms 17076 KB Output is correct
37 Correct 11 ms 17500 KB Output is correct
38 Correct 12 ms 17500 KB Output is correct
39 Correct 16 ms 18268 KB Output is correct
40 Correct 25 ms 19952 KB Output is correct
41 Correct 34 ms 21592 KB Output is correct
42 Correct 34 ms 21596 KB Output is correct
43 Correct 33 ms 21588 KB Output is correct
44 Correct 34 ms 21596 KB Output is correct
45 Correct 33 ms 21596 KB Output is correct
46 Correct 33 ms 21584 KB Output is correct
47 Correct 33 ms 21596 KB Output is correct
48 Correct 32 ms 21596 KB Output is correct
49 Correct 33 ms 21608 KB Output is correct
50 Correct 34 ms 21596 KB Output is correct
51 Correct 34 ms 21596 KB Output is correct
52 Correct 33 ms 21536 KB Output is correct
53 Correct 33 ms 21596 KB Output is correct
54 Correct 35 ms 21596 KB Output is correct
55 Correct 33 ms 21596 KB Output is correct
56 Correct 42 ms 21524 KB Output is correct
57 Correct 33 ms 21596 KB Output is correct
58 Correct 32 ms 21596 KB Output is correct
59 Correct 34 ms 21596 KB Output is correct
60 Correct 34 ms 21584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 16728 KB Output is correct
2 Correct 7 ms 16732 KB Output is correct
3 Correct 7 ms 16732 KB Output is correct
4 Correct 8 ms 16796 KB Output is correct
5 Correct 7 ms 16732 KB Output is correct
6 Correct 7 ms 16732 KB Output is correct
7 Correct 8 ms 16732 KB Output is correct
8 Correct 8 ms 16732 KB Output is correct
9 Correct 8 ms 16732 KB Output is correct
10 Correct 8 ms 16648 KB Output is correct
11 Correct 8 ms 16728 KB Output is correct
12 Correct 8 ms 16732 KB Output is correct
13 Correct 8 ms 16852 KB Output is correct
14 Correct 13 ms 18268 KB Output is correct
15 Correct 24 ms 19804 KB Output is correct
16 Correct 26 ms 21436 KB Output is correct
17 Correct 23 ms 21492 KB Output is correct
18 Correct 24 ms 21596 KB Output is correct
19 Correct 34 ms 21572 KB Output is correct
20 Correct 26 ms 21592 KB Output is correct
21 Correct 25 ms 21596 KB Output is correct
22 Correct 32 ms 21596 KB Output is correct
23 Correct 26 ms 21596 KB Output is correct
24 Correct 26 ms 21592 KB Output is correct
25 Correct 31 ms 21592 KB Output is correct
26 Correct 8 ms 16984 KB Output is correct
27 Correct 7 ms 16732 KB Output is correct
28 Correct 8 ms 16988 KB Output is correct
29 Correct 13 ms 18364 KB Output is correct
30 Correct 21 ms 19804 KB Output is correct
31 Correct 27 ms 21592 KB Output is correct
32 Correct 27 ms 21332 KB Output is correct
33 Correct 30 ms 21592 KB Output is correct
34 Correct 28 ms 21328 KB Output is correct
35 Correct 27 ms 21476 KB Output is correct
36 Correct 29 ms 21596 KB Output is correct
37 Correct 28 ms 21592 KB Output is correct
38 Correct 26 ms 21596 KB Output is correct
39 Correct 29 ms 21588 KB Output is correct
40 Correct 27 ms 21596 KB Output is correct
41 Correct 8 ms 16732 KB Output is correct
42 Correct 7 ms 16728 KB Output is correct
43 Correct 8 ms 16732 KB Output is correct
44 Correct 8 ms 16984 KB Output is correct
45 Correct 9 ms 17064 KB Output is correct
46 Correct 9 ms 17076 KB Output is correct
47 Correct 11 ms 17500 KB Output is correct
48 Correct 12 ms 17500 KB Output is correct
49 Correct 16 ms 18268 KB Output is correct
50 Correct 25 ms 19952 KB Output is correct
51 Correct 34 ms 21592 KB Output is correct
52 Correct 34 ms 21596 KB Output is correct
53 Correct 33 ms 21588 KB Output is correct
54 Correct 34 ms 21596 KB Output is correct
55 Correct 33 ms 21596 KB Output is correct
56 Correct 33 ms 21584 KB Output is correct
57 Correct 33 ms 21596 KB Output is correct
58 Correct 32 ms 21596 KB Output is correct
59 Correct 33 ms 21608 KB Output is correct
60 Correct 34 ms 21596 KB Output is correct
61 Correct 34 ms 21596 KB Output is correct
62 Correct 33 ms 21536 KB Output is correct
63 Correct 33 ms 21596 KB Output is correct
64 Correct 35 ms 21596 KB Output is correct
65 Correct 33 ms 21596 KB Output is correct
66 Correct 42 ms 21524 KB Output is correct
67 Correct 33 ms 21596 KB Output is correct
68 Correct 32 ms 21596 KB Output is correct
69 Correct 34 ms 21596 KB Output is correct
70 Correct 34 ms 21584 KB Output is correct
71 Correct 12 ms 17496 KB Output is correct
72 Correct 12 ms 17500 KB Output is correct
73 Correct 12 ms 17716 KB Output is correct
74 Correct 13 ms 17500 KB Output is correct
75 Correct 13 ms 17500 KB Output is correct
76 Correct 18 ms 18484 KB Output is correct
77 Correct 18 ms 18524 KB Output is correct
78 Correct 18 ms 18528 KB Output is correct
79 Correct 18 ms 18524 KB Output is correct
80 Correct 19 ms 18520 KB Output is correct
81 Correct 28 ms 20044 KB Output is correct
82 Correct 28 ms 20048 KB Output is correct
83 Correct 28 ms 20060 KB Output is correct
84 Correct 28 ms 20052 KB Output is correct
85 Correct 29 ms 20040 KB Output is correct
86 Correct 27 ms 20316 KB Output is correct
87 Correct 28 ms 20308 KB Output is correct
88 Correct 29 ms 20288 KB Output is correct
89 Correct 31 ms 20316 KB Output is correct
90 Correct 30 ms 20368 KB Output is correct
91 Correct 49 ms 22992 KB Output is correct
92 Correct 53 ms 23000 KB Output is correct
93 Correct 46 ms 23120 KB Output is correct
94 Correct 47 ms 22988 KB Output is correct
95 Correct 46 ms 22992 KB Output is correct
96 Correct 48 ms 24780 KB Output is correct
97 Correct 51 ms 24716 KB Output is correct
98 Correct 50 ms 25020 KB Output is correct
99 Correct 50 ms 24776 KB Output is correct
100 Correct 49 ms 24796 KB Output is correct
101 Correct 50 ms 24700 KB Output is correct
102 Correct 50 ms 24776 KB Output is correct
103 Correct 52 ms 24776 KB Output is correct
104 Correct 58 ms 24708 KB Output is correct
105 Correct 51 ms 24788 KB Output is correct
106 Correct 54 ms 25560 KB Output is correct
107 Correct 50 ms 25472 KB Output is correct
108 Correct 48 ms 25548 KB Output is correct
109 Correct 54 ms 25548 KB Output is correct
110 Correct 54 ms 25568 KB Output is correct
111 Correct 50 ms 25544 KB Output is correct
112 Correct 60 ms 25544 KB Output is correct
113 Correct 48 ms 25468 KB Output is correct
114 Correct 50 ms 25440 KB Output is correct
115 Correct 51 ms 25544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 16728 KB Output is correct
2 Correct 7 ms 16732 KB Output is correct
3 Correct 7 ms 16732 KB Output is correct
4 Correct 8 ms 16796 KB Output is correct
5 Correct 7 ms 16732 KB Output is correct
6 Correct 7 ms 16732 KB Output is correct
7 Correct 8 ms 16732 KB Output is correct
8 Correct 8 ms 16732 KB Output is correct
9 Correct 8 ms 16732 KB Output is correct
10 Correct 8 ms 16648 KB Output is correct
11 Correct 8 ms 16728 KB Output is correct
12 Correct 8 ms 16732 KB Output is correct
13 Correct 8 ms 16852 KB Output is correct
14 Correct 13 ms 18268 KB Output is correct
15 Correct 24 ms 19804 KB Output is correct
16 Correct 26 ms 21436 KB Output is correct
17 Correct 23 ms 21492 KB Output is correct
18 Correct 24 ms 21596 KB Output is correct
19 Correct 34 ms 21572 KB Output is correct
20 Correct 26 ms 21592 KB Output is correct
21 Correct 25 ms 21596 KB Output is correct
22 Correct 32 ms 21596 KB Output is correct
23 Correct 26 ms 21596 KB Output is correct
24 Correct 26 ms 21592 KB Output is correct
25 Correct 31 ms 21592 KB Output is correct
26 Correct 8 ms 16984 KB Output is correct
27 Correct 7 ms 16732 KB Output is correct
28 Correct 8 ms 16988 KB Output is correct
29 Correct 13 ms 18364 KB Output is correct
30 Correct 21 ms 19804 KB Output is correct
31 Correct 27 ms 21592 KB Output is correct
32 Correct 27 ms 21332 KB Output is correct
33 Correct 30 ms 21592 KB Output is correct
34 Correct 28 ms 21328 KB Output is correct
35 Correct 27 ms 21476 KB Output is correct
36 Correct 29 ms 21596 KB Output is correct
37 Correct 28 ms 21592 KB Output is correct
38 Correct 26 ms 21596 KB Output is correct
39 Correct 29 ms 21588 KB Output is correct
40 Correct 27 ms 21596 KB Output is correct
41 Correct 8 ms 16732 KB Output is correct
42 Correct 7 ms 16728 KB Output is correct
43 Correct 8 ms 16732 KB Output is correct
44 Correct 8 ms 16984 KB Output is correct
45 Correct 9 ms 17064 KB Output is correct
46 Correct 9 ms 17076 KB Output is correct
47 Correct 11 ms 17500 KB Output is correct
48 Correct 12 ms 17500 KB Output is correct
49 Correct 16 ms 18268 KB Output is correct
50 Correct 25 ms 19952 KB Output is correct
51 Correct 34 ms 21592 KB Output is correct
52 Correct 34 ms 21596 KB Output is correct
53 Correct 33 ms 21588 KB Output is correct
54 Correct 34 ms 21596 KB Output is correct
55 Correct 33 ms 21596 KB Output is correct
56 Correct 33 ms 21584 KB Output is correct
57 Correct 33 ms 21596 KB Output is correct
58 Correct 32 ms 21596 KB Output is correct
59 Correct 33 ms 21608 KB Output is correct
60 Correct 34 ms 21596 KB Output is correct
61 Correct 34 ms 21596 KB Output is correct
62 Correct 33 ms 21536 KB Output is correct
63 Correct 33 ms 21596 KB Output is correct
64 Correct 35 ms 21596 KB Output is correct
65 Correct 33 ms 21596 KB Output is correct
66 Correct 42 ms 21524 KB Output is correct
67 Correct 33 ms 21596 KB Output is correct
68 Correct 32 ms 21596 KB Output is correct
69 Correct 34 ms 21596 KB Output is correct
70 Correct 34 ms 21584 KB Output is correct
71 Correct 12 ms 17496 KB Output is correct
72 Correct 12 ms 17500 KB Output is correct
73 Correct 12 ms 17716 KB Output is correct
74 Correct 13 ms 17500 KB Output is correct
75 Correct 13 ms 17500 KB Output is correct
76 Correct 18 ms 18484 KB Output is correct
77 Correct 18 ms 18524 KB Output is correct
78 Correct 18 ms 18528 KB Output is correct
79 Correct 18 ms 18524 KB Output is correct
80 Correct 19 ms 18520 KB Output is correct
81 Correct 28 ms 20044 KB Output is correct
82 Correct 28 ms 20048 KB Output is correct
83 Correct 28 ms 20060 KB Output is correct
84 Correct 28 ms 20052 KB Output is correct
85 Correct 29 ms 20040 KB Output is correct
86 Correct 27 ms 20316 KB Output is correct
87 Correct 28 ms 20308 KB Output is correct
88 Correct 29 ms 20288 KB Output is correct
89 Correct 31 ms 20316 KB Output is correct
90 Correct 30 ms 20368 KB Output is correct
91 Correct 49 ms 22992 KB Output is correct
92 Correct 53 ms 23000 KB Output is correct
93 Correct 46 ms 23120 KB Output is correct
94 Correct 47 ms 22988 KB Output is correct
95 Correct 46 ms 22992 KB Output is correct
96 Correct 48 ms 24780 KB Output is correct
97 Correct 51 ms 24716 KB Output is correct
98 Correct 50 ms 25020 KB Output is correct
99 Correct 50 ms 24776 KB Output is correct
100 Correct 49 ms 24796 KB Output is correct
101 Correct 50 ms 24700 KB Output is correct
102 Correct 50 ms 24776 KB Output is correct
103 Correct 52 ms 24776 KB Output is correct
104 Correct 58 ms 24708 KB Output is correct
105 Correct 51 ms 24788 KB Output is correct
106 Correct 54 ms 25560 KB Output is correct
107 Correct 50 ms 25472 KB Output is correct
108 Correct 48 ms 25548 KB Output is correct
109 Correct 54 ms 25548 KB Output is correct
110 Correct 54 ms 25568 KB Output is correct
111 Correct 50 ms 25544 KB Output is correct
112 Correct 60 ms 25544 KB Output is correct
113 Correct 48 ms 25468 KB Output is correct
114 Correct 50 ms 25440 KB Output is correct
115 Correct 51 ms 25544 KB Output is correct
116 Correct 4556 ms 20052 KB Output is correct
117 Correct 5322 ms 20496 KB Output is correct
118 Execution timed out 7022 ms 19976 KB Time limit exceeded
119 Halted 0 ms 0 KB -