Submission #713118

# Submission time Handle Problem Language Result Execution time Memory
713118 2023-03-21T08:07:01 Z Pety Diversity (CEOI21_diversity) C++14
64 / 100
60 ms 10380 KB
#include <bits/stdc++.h>

using namespace std;

int n, a[300002], q, l, r, fr[300002], pref[300002], suf[300002];

int main () 
{
  ios_base::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);
  cin >> n >> q;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    fr[a[i]]++;
  }
  cin >> l >> r;
  vector<pair<int, int>>a, b;
  for (int i = 1; i <= 300000; i++)
    if (fr[i])
      a.push_back({fr[i], i});
  sort(a.begin(), a.end());
  b.push_back({0, 0});
  for (int i = 0; i < a.size(); i += 2)
    b.push_back(a[i]);
  for (int i = (a.size() % 2 ? a.size() - 2 : a.size() - 1); i >= 0; i -= 2)
    b.push_back(a[i]);
  for (int i = 1; i < b.size(); i++)
    pref[i] = pref[i - 1] + b[i].first;
  for (int i = b.size() - 1; i >= 1; i--)
    suf[i] = suf[i + 1] + b[i].first;
  long long ans = 0;
  for (int i = 1; i < b.size(); i++) {
    long long val = 1ll * pref[i - 1] * suf[i + 1];
    val += 1ll * b[i].first * suf[i + 1];
    val += 1ll * b[i].first * pref[i - 1];
    val += 1ll * b[i].first * (b[i].first + 1) / 2;
    ans += val;
  }
  cout << ans;
  return 0;
}

Compilation message

diversity.cpp: In function 'int main()':
diversity.cpp:23:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |   for (int i = 0; i < a.size(); i += 2)
      |                   ~~^~~~~~~~~~
diversity.cpp:27:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |   for (int i = 1; i < b.size(); i++)
      |                   ~~^~~~~~~~~~
diversity.cpp:32:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |   for (int i = 1; i < b.size(); i++) {
      |                   ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 328 KB Output is correct
2 Correct 1 ms 324 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 324 KB Output is correct
10 Correct 1 ms 324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 324 KB Output is correct
3 Correct 1 ms 376 KB Output is correct
4 Correct 7 ms 852 KB Output is correct
5 Correct 11 ms 1436 KB Output is correct
6 Correct 18 ms 2136 KB Output is correct
7 Correct 17 ms 2088 KB Output is correct
8 Correct 18 ms 2084 KB Output is correct
9 Correct 16 ms 2132 KB Output is correct
10 Correct 18 ms 2176 KB Output is correct
11 Correct 18 ms 2096 KB Output is correct
12 Correct 19 ms 2112 KB Output is correct
13 Correct 23 ms 2132 KB Output is correct
14 Correct 18 ms 2108 KB Output is correct
15 Correct 18 ms 2092 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 324 KB Output is correct
3 Correct 1 ms 376 KB Output is correct
4 Correct 7 ms 852 KB Output is correct
5 Correct 11 ms 1436 KB Output is correct
6 Correct 18 ms 2136 KB Output is correct
7 Correct 17 ms 2088 KB Output is correct
8 Correct 18 ms 2084 KB Output is correct
9 Correct 16 ms 2132 KB Output is correct
10 Correct 18 ms 2176 KB Output is correct
11 Correct 18 ms 2096 KB Output is correct
12 Correct 19 ms 2112 KB Output is correct
13 Correct 23 ms 2132 KB Output is correct
14 Correct 18 ms 2108 KB Output is correct
15 Correct 18 ms 2092 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 8 ms 1108 KB Output is correct
20 Correct 12 ms 1596 KB Output is correct
21 Correct 18 ms 2264 KB Output is correct
22 Correct 19 ms 2260 KB Output is correct
23 Correct 19 ms 2336 KB Output is correct
24 Correct 23 ms 2224 KB Output is correct
25 Correct 20 ms 2244 KB Output is correct
26 Correct 20 ms 2260 KB Output is correct
27 Correct 19 ms 2252 KB Output is correct
28 Correct 21 ms 2144 KB Output is correct
29 Correct 19 ms 2132 KB Output is correct
30 Correct 19 ms 2248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 324 KB Output is correct
3 Correct 1 ms 376 KB Output is correct
4 Correct 7 ms 852 KB Output is correct
5 Correct 11 ms 1436 KB Output is correct
6 Correct 18 ms 2136 KB Output is correct
7 Correct 17 ms 2088 KB Output is correct
8 Correct 18 ms 2084 KB Output is correct
9 Correct 16 ms 2132 KB Output is correct
10 Correct 18 ms 2176 KB Output is correct
11 Correct 18 ms 2096 KB Output is correct
12 Correct 19 ms 2112 KB Output is correct
13 Correct 23 ms 2132 KB Output is correct
14 Correct 18 ms 2108 KB Output is correct
15 Correct 18 ms 2092 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 8 ms 1108 KB Output is correct
20 Correct 12 ms 1596 KB Output is correct
21 Correct 18 ms 2264 KB Output is correct
22 Correct 19 ms 2260 KB Output is correct
23 Correct 19 ms 2336 KB Output is correct
24 Correct 23 ms 2224 KB Output is correct
25 Correct 20 ms 2244 KB Output is correct
26 Correct 20 ms 2260 KB Output is correct
27 Correct 19 ms 2252 KB Output is correct
28 Correct 21 ms 2144 KB Output is correct
29 Correct 19 ms 2132 KB Output is correct
30 Correct 19 ms 2248 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 2 ms 340 KB Output is correct
35 Correct 2 ms 332 KB Output is correct
36 Correct 2 ms 340 KB Output is correct
37 Correct 4 ms 724 KB Output is correct
38 Correct 5 ms 724 KB Output is correct
39 Correct 11 ms 1064 KB Output is correct
40 Correct 13 ms 1880 KB Output is correct
41 Correct 21 ms 2644 KB Output is correct
42 Correct 22 ms 2600 KB Output is correct
43 Correct 19 ms 2568 KB Output is correct
44 Correct 19 ms 2580 KB Output is correct
45 Correct 20 ms 2592 KB Output is correct
46 Correct 19 ms 2620 KB Output is correct
47 Correct 20 ms 2612 KB Output is correct
48 Correct 20 ms 2676 KB Output is correct
49 Correct 23 ms 2588 KB Output is correct
50 Correct 21 ms 2644 KB Output is correct
51 Correct 19 ms 2616 KB Output is correct
52 Correct 24 ms 2660 KB Output is correct
53 Correct 23 ms 2596 KB Output is correct
54 Correct 20 ms 2660 KB Output is correct
55 Correct 20 ms 2628 KB Output is correct
56 Correct 22 ms 2576 KB Output is correct
57 Correct 20 ms 2636 KB Output is correct
58 Correct 19 ms 2680 KB Output is correct
59 Correct 19 ms 2608 KB Output is correct
60 Correct 23 ms 2584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 328 KB Output is correct
2 Correct 1 ms 324 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 324 KB Output is correct
10 Correct 1 ms 324 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 324 KB Output is correct
13 Correct 1 ms 376 KB Output is correct
14 Correct 7 ms 852 KB Output is correct
15 Correct 11 ms 1436 KB Output is correct
16 Correct 18 ms 2136 KB Output is correct
17 Correct 17 ms 2088 KB Output is correct
18 Correct 18 ms 2084 KB Output is correct
19 Correct 16 ms 2132 KB Output is correct
20 Correct 18 ms 2176 KB Output is correct
21 Correct 18 ms 2096 KB Output is correct
22 Correct 19 ms 2112 KB Output is correct
23 Correct 23 ms 2132 KB Output is correct
24 Correct 18 ms 2108 KB Output is correct
25 Correct 18 ms 2092 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 8 ms 1108 KB Output is correct
30 Correct 12 ms 1596 KB Output is correct
31 Correct 18 ms 2264 KB Output is correct
32 Correct 19 ms 2260 KB Output is correct
33 Correct 19 ms 2336 KB Output is correct
34 Correct 23 ms 2224 KB Output is correct
35 Correct 20 ms 2244 KB Output is correct
36 Correct 20 ms 2260 KB Output is correct
37 Correct 19 ms 2252 KB Output is correct
38 Correct 21 ms 2144 KB Output is correct
39 Correct 19 ms 2132 KB Output is correct
40 Correct 19 ms 2248 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 2 ms 340 KB Output is correct
45 Correct 2 ms 332 KB Output is correct
46 Correct 2 ms 340 KB Output is correct
47 Correct 4 ms 724 KB Output is correct
48 Correct 5 ms 724 KB Output is correct
49 Correct 11 ms 1064 KB Output is correct
50 Correct 13 ms 1880 KB Output is correct
51 Correct 21 ms 2644 KB Output is correct
52 Correct 22 ms 2600 KB Output is correct
53 Correct 19 ms 2568 KB Output is correct
54 Correct 19 ms 2580 KB Output is correct
55 Correct 20 ms 2592 KB Output is correct
56 Correct 19 ms 2620 KB Output is correct
57 Correct 20 ms 2612 KB Output is correct
58 Correct 20 ms 2676 KB Output is correct
59 Correct 23 ms 2588 KB Output is correct
60 Correct 21 ms 2644 KB Output is correct
61 Correct 19 ms 2616 KB Output is correct
62 Correct 24 ms 2660 KB Output is correct
63 Correct 23 ms 2596 KB Output is correct
64 Correct 20 ms 2660 KB Output is correct
65 Correct 20 ms 2628 KB Output is correct
66 Correct 22 ms 2576 KB Output is correct
67 Correct 20 ms 2636 KB Output is correct
68 Correct 19 ms 2680 KB Output is correct
69 Correct 19 ms 2608 KB Output is correct
70 Correct 23 ms 2584 KB Output is correct
71 Correct 5 ms 724 KB Output is correct
72 Correct 5 ms 724 KB Output is correct
73 Correct 5 ms 720 KB Output is correct
74 Correct 5 ms 724 KB Output is correct
75 Correct 4 ms 724 KB Output is correct
76 Correct 8 ms 1364 KB Output is correct
77 Correct 10 ms 1364 KB Output is correct
78 Correct 8 ms 1336 KB Output is correct
79 Correct 9 ms 1388 KB Output is correct
80 Correct 8 ms 1332 KB Output is correct
81 Correct 16 ms 2532 KB Output is correct
82 Correct 19 ms 2380 KB Output is correct
83 Correct 16 ms 2380 KB Output is correct
84 Correct 18 ms 2516 KB Output is correct
85 Correct 17 ms 2436 KB Output is correct
86 Correct 21 ms 2840 KB Output is correct
87 Correct 18 ms 2848 KB Output is correct
88 Correct 19 ms 2780 KB Output is correct
89 Correct 18 ms 2772 KB Output is correct
90 Correct 19 ms 2772 KB Output is correct
91 Correct 38 ms 6092 KB Output is correct
92 Correct 37 ms 6092 KB Output is correct
93 Correct 48 ms 6124 KB Output is correct
94 Correct 36 ms 6116 KB Output is correct
95 Correct 35 ms 6092 KB Output is correct
96 Correct 47 ms 8952 KB Output is correct
97 Correct 48 ms 8904 KB Output is correct
98 Correct 60 ms 8992 KB Output is correct
99 Correct 51 ms 8952 KB Output is correct
100 Correct 48 ms 8960 KB Output is correct
101 Correct 46 ms 8904 KB Output is correct
102 Correct 46 ms 8960 KB Output is correct
103 Correct 49 ms 8904 KB Output is correct
104 Correct 53 ms 8992 KB Output is correct
105 Correct 51 ms 8960 KB Output is correct
106 Correct 48 ms 10312 KB Output is correct
107 Correct 54 ms 10376 KB Output is correct
108 Correct 47 ms 10360 KB Output is correct
109 Correct 47 ms 10348 KB Output is correct
110 Correct 55 ms 10340 KB Output is correct
111 Correct 48 ms 10352 KB Output is correct
112 Correct 51 ms 10340 KB Output is correct
113 Correct 53 ms 10360 KB Output is correct
114 Correct 49 ms 10380 KB Output is correct
115 Correct 53 ms 10356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 328 KB Output is correct
2 Correct 1 ms 324 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 324 KB Output is correct
10 Correct 1 ms 324 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 324 KB Output is correct
13 Correct 1 ms 376 KB Output is correct
14 Correct 7 ms 852 KB Output is correct
15 Correct 11 ms 1436 KB Output is correct
16 Correct 18 ms 2136 KB Output is correct
17 Correct 17 ms 2088 KB Output is correct
18 Correct 18 ms 2084 KB Output is correct
19 Correct 16 ms 2132 KB Output is correct
20 Correct 18 ms 2176 KB Output is correct
21 Correct 18 ms 2096 KB Output is correct
22 Correct 19 ms 2112 KB Output is correct
23 Correct 23 ms 2132 KB Output is correct
24 Correct 18 ms 2108 KB Output is correct
25 Correct 18 ms 2092 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 8 ms 1108 KB Output is correct
30 Correct 12 ms 1596 KB Output is correct
31 Correct 18 ms 2264 KB Output is correct
32 Correct 19 ms 2260 KB Output is correct
33 Correct 19 ms 2336 KB Output is correct
34 Correct 23 ms 2224 KB Output is correct
35 Correct 20 ms 2244 KB Output is correct
36 Correct 20 ms 2260 KB Output is correct
37 Correct 19 ms 2252 KB Output is correct
38 Correct 21 ms 2144 KB Output is correct
39 Correct 19 ms 2132 KB Output is correct
40 Correct 19 ms 2248 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 2 ms 340 KB Output is correct
45 Correct 2 ms 332 KB Output is correct
46 Correct 2 ms 340 KB Output is correct
47 Correct 4 ms 724 KB Output is correct
48 Correct 5 ms 724 KB Output is correct
49 Correct 11 ms 1064 KB Output is correct
50 Correct 13 ms 1880 KB Output is correct
51 Correct 21 ms 2644 KB Output is correct
52 Correct 22 ms 2600 KB Output is correct
53 Correct 19 ms 2568 KB Output is correct
54 Correct 19 ms 2580 KB Output is correct
55 Correct 20 ms 2592 KB Output is correct
56 Correct 19 ms 2620 KB Output is correct
57 Correct 20 ms 2612 KB Output is correct
58 Correct 20 ms 2676 KB Output is correct
59 Correct 23 ms 2588 KB Output is correct
60 Correct 21 ms 2644 KB Output is correct
61 Correct 19 ms 2616 KB Output is correct
62 Correct 24 ms 2660 KB Output is correct
63 Correct 23 ms 2596 KB Output is correct
64 Correct 20 ms 2660 KB Output is correct
65 Correct 20 ms 2628 KB Output is correct
66 Correct 22 ms 2576 KB Output is correct
67 Correct 20 ms 2636 KB Output is correct
68 Correct 19 ms 2680 KB Output is correct
69 Correct 19 ms 2608 KB Output is correct
70 Correct 23 ms 2584 KB Output is correct
71 Correct 5 ms 724 KB Output is correct
72 Correct 5 ms 724 KB Output is correct
73 Correct 5 ms 720 KB Output is correct
74 Correct 5 ms 724 KB Output is correct
75 Correct 4 ms 724 KB Output is correct
76 Correct 8 ms 1364 KB Output is correct
77 Correct 10 ms 1364 KB Output is correct
78 Correct 8 ms 1336 KB Output is correct
79 Correct 9 ms 1388 KB Output is correct
80 Correct 8 ms 1332 KB Output is correct
81 Correct 16 ms 2532 KB Output is correct
82 Correct 19 ms 2380 KB Output is correct
83 Correct 16 ms 2380 KB Output is correct
84 Correct 18 ms 2516 KB Output is correct
85 Correct 17 ms 2436 KB Output is correct
86 Correct 21 ms 2840 KB Output is correct
87 Correct 18 ms 2848 KB Output is correct
88 Correct 19 ms 2780 KB Output is correct
89 Correct 18 ms 2772 KB Output is correct
90 Correct 19 ms 2772 KB Output is correct
91 Correct 38 ms 6092 KB Output is correct
92 Correct 37 ms 6092 KB Output is correct
93 Correct 48 ms 6124 KB Output is correct
94 Correct 36 ms 6116 KB Output is correct
95 Correct 35 ms 6092 KB Output is correct
96 Correct 47 ms 8952 KB Output is correct
97 Correct 48 ms 8904 KB Output is correct
98 Correct 60 ms 8992 KB Output is correct
99 Correct 51 ms 8952 KB Output is correct
100 Correct 48 ms 8960 KB Output is correct
101 Correct 46 ms 8904 KB Output is correct
102 Correct 46 ms 8960 KB Output is correct
103 Correct 49 ms 8904 KB Output is correct
104 Correct 53 ms 8992 KB Output is correct
105 Correct 51 ms 8960 KB Output is correct
106 Correct 48 ms 10312 KB Output is correct
107 Correct 54 ms 10376 KB Output is correct
108 Correct 47 ms 10360 KB Output is correct
109 Correct 47 ms 10348 KB Output is correct
110 Correct 55 ms 10340 KB Output is correct
111 Correct 48 ms 10352 KB Output is correct
112 Correct 51 ms 10340 KB Output is correct
113 Correct 53 ms 10360 KB Output is correct
114 Correct 49 ms 10380 KB Output is correct
115 Correct 53 ms 10356 KB Output is correct
116 Incorrect 1 ms 468 KB Output isn't correct
117 Halted 0 ms 0 KB -