Submission #678207

# Submission time Handle Problem Language Result Execution time Memory
678207 2023-01-05T10:01:45 Z gesgha Diversity (CEOI21_diversity) C++17
64 / 100
7000 ms 4004 KB
#include <bits/stdc++.h>
#define fr(i, a, b) for (int i = a; i <= b; i++)
#define rf(i, a, b) for (int i = a; i >= b; i--)
#define fe(x, y) for(auto& x : y)

#define fi first
#define se second
#define pb push_back

#define all(x) x.begin(), x.end()
#define pw(x) (1LL << (x))
#define sz(x) (int)x.size()

using namespace std;

template <typename T>
using ve = vector <T>;

template <typename T>
bool umx(T& a, T b) {return a < b ? a = b, 1 : 0;}

template <typename T>
bool umn(T& a, T b) {return a > b ? a = b, 1 : 0;}


using ll = long long;
using pii = pair <int, int>;
using pll = pair <ll, ll>;


const int oo = 2e9;
const ll OO = 1e18;
const int N = 3e5 + 100;
int n, q;
int a[N];

void slv(int l, int r) {
    ll ans = 0;

    ve <int> cnt(N, 0);
    fr(i, l, r) cnt[a[i]]++;
    sort(all(cnt));
    ve <int> A(r - l + 1, 0);
    int p1 = 0, p2 = sz(A) - 1;

    int mv = 1;
    fe(x, cnt) {
        if (x == 0) continue;
        if (mv%2) {
            while(x > 0) {
                A[p1++] = mv;
                x--;
            }
        } else {
            while(x > 0) {
                A[p2--] = mv;
                x--;
            }
        }
        mv++;
    }
    fr(i, 0, sz(A) - 1) {
        if (!i || A[i] != A[i - 1]) ans += 1LL * (sz(A) - i) * (i + 1);
        else ans += sz(A) - i;
    }
    cout << ans << "\n";
}


int main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif // LOCAL
    cin.tie(0);
    ios_base::sync_with_stdio(0);

    cin >> n >> q;
    fr(i, 0, n - 1) cin >> a[i];
    while (q--) {
        int l, r;
        cin >> l >> r; l--; r--;
        slv(l, r);
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1492 KB Output is correct
2 Correct 5 ms 1492 KB Output is correct
3 Correct 6 ms 1492 KB Output is correct
4 Correct 5 ms 1492 KB Output is correct
5 Correct 6 ms 1492 KB Output is correct
6 Correct 5 ms 1492 KB Output is correct
7 Correct 7 ms 1492 KB Output is correct
8 Correct 5 ms 1492 KB Output is correct
9 Correct 6 ms 1492 KB Output is correct
10 Correct 6 ms 1492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1492 KB Output is correct
2 Correct 7 ms 1512 KB Output is correct
3 Correct 6 ms 1492 KB Output is correct
4 Correct 12 ms 2284 KB Output is correct
5 Correct 17 ms 3204 KB Output is correct
6 Correct 23 ms 3916 KB Output is correct
7 Correct 22 ms 3924 KB Output is correct
8 Correct 21 ms 3916 KB Output is correct
9 Correct 21 ms 3924 KB Output is correct
10 Correct 23 ms 3892 KB Output is correct
11 Correct 22 ms 3948 KB Output is correct
12 Correct 26 ms 3916 KB Output is correct
13 Correct 25 ms 3936 KB Output is correct
14 Correct 22 ms 3956 KB Output is correct
15 Correct 23 ms 3892 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1492 KB Output is correct
2 Correct 7 ms 1512 KB Output is correct
3 Correct 6 ms 1492 KB Output is correct
4 Correct 12 ms 2284 KB Output is correct
5 Correct 17 ms 3204 KB Output is correct
6 Correct 23 ms 3916 KB Output is correct
7 Correct 22 ms 3924 KB Output is correct
8 Correct 21 ms 3916 KB Output is correct
9 Correct 21 ms 3924 KB Output is correct
10 Correct 23 ms 3892 KB Output is correct
11 Correct 22 ms 3948 KB Output is correct
12 Correct 26 ms 3916 KB Output is correct
13 Correct 25 ms 3936 KB Output is correct
14 Correct 22 ms 3956 KB Output is correct
15 Correct 23 ms 3892 KB Output is correct
16 Correct 6 ms 1492 KB Output is correct
17 Correct 7 ms 1528 KB Output is correct
18 Correct 6 ms 1620 KB Output is correct
19 Correct 12 ms 2528 KB Output is correct
20 Correct 18 ms 3160 KB Output is correct
21 Correct 23 ms 3868 KB Output is correct
22 Correct 26 ms 3916 KB Output is correct
23 Correct 24 ms 3876 KB Output is correct
24 Correct 24 ms 3916 KB Output is correct
25 Correct 24 ms 3936 KB Output is correct
26 Correct 23 ms 3912 KB Output is correct
27 Correct 23 ms 3960 KB Output is correct
28 Correct 27 ms 3904 KB Output is correct
29 Correct 27 ms 3916 KB Output is correct
30 Correct 26 ms 3920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1492 KB Output is correct
2 Correct 7 ms 1512 KB Output is correct
3 Correct 6 ms 1492 KB Output is correct
4 Correct 12 ms 2284 KB Output is correct
5 Correct 17 ms 3204 KB Output is correct
6 Correct 23 ms 3916 KB Output is correct
7 Correct 22 ms 3924 KB Output is correct
8 Correct 21 ms 3916 KB Output is correct
9 Correct 21 ms 3924 KB Output is correct
10 Correct 23 ms 3892 KB Output is correct
11 Correct 22 ms 3948 KB Output is correct
12 Correct 26 ms 3916 KB Output is correct
13 Correct 25 ms 3936 KB Output is correct
14 Correct 22 ms 3956 KB Output is correct
15 Correct 23 ms 3892 KB Output is correct
16 Correct 6 ms 1492 KB Output is correct
17 Correct 7 ms 1528 KB Output is correct
18 Correct 6 ms 1620 KB Output is correct
19 Correct 12 ms 2528 KB Output is correct
20 Correct 18 ms 3160 KB Output is correct
21 Correct 23 ms 3868 KB Output is correct
22 Correct 26 ms 3916 KB Output is correct
23 Correct 24 ms 3876 KB Output is correct
24 Correct 24 ms 3916 KB Output is correct
25 Correct 24 ms 3936 KB Output is correct
26 Correct 23 ms 3912 KB Output is correct
27 Correct 23 ms 3960 KB Output is correct
28 Correct 27 ms 3904 KB Output is correct
29 Correct 27 ms 3916 KB Output is correct
30 Correct 26 ms 3920 KB Output is correct
31 Correct 6 ms 1492 KB Output is correct
32 Correct 5 ms 1492 KB Output is correct
33 Correct 6 ms 1492 KB Output is correct
34 Correct 7 ms 1616 KB Output is correct
35 Correct 7 ms 1524 KB Output is correct
36 Correct 6 ms 1640 KB Output is correct
37 Correct 9 ms 2032 KB Output is correct
38 Correct 9 ms 1984 KB Output is correct
39 Correct 13 ms 2376 KB Output is correct
40 Correct 21 ms 3156 KB Output is correct
41 Correct 27 ms 3904 KB Output is correct
42 Correct 25 ms 3916 KB Output is correct
43 Correct 25 ms 3988 KB Output is correct
44 Correct 24 ms 3908 KB Output is correct
45 Correct 25 ms 3916 KB Output is correct
46 Correct 26 ms 3960 KB Output is correct
47 Correct 26 ms 3940 KB Output is correct
48 Correct 25 ms 3944 KB Output is correct
49 Correct 37 ms 3904 KB Output is correct
50 Correct 26 ms 3920 KB Output is correct
51 Correct 26 ms 3916 KB Output is correct
52 Correct 25 ms 3976 KB Output is correct
53 Correct 24 ms 3912 KB Output is correct
54 Correct 25 ms 3932 KB Output is correct
55 Correct 25 ms 3916 KB Output is correct
56 Correct 24 ms 3948 KB Output is correct
57 Correct 25 ms 3924 KB Output is correct
58 Correct 28 ms 3932 KB Output is correct
59 Correct 25 ms 3892 KB Output is correct
60 Correct 26 ms 3936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1492 KB Output is correct
2 Correct 5 ms 1492 KB Output is correct
3 Correct 6 ms 1492 KB Output is correct
4 Correct 5 ms 1492 KB Output is correct
5 Correct 6 ms 1492 KB Output is correct
6 Correct 5 ms 1492 KB Output is correct
7 Correct 7 ms 1492 KB Output is correct
8 Correct 5 ms 1492 KB Output is correct
9 Correct 6 ms 1492 KB Output is correct
10 Correct 6 ms 1492 KB Output is correct
11 Correct 6 ms 1492 KB Output is correct
12 Correct 7 ms 1512 KB Output is correct
13 Correct 6 ms 1492 KB Output is correct
14 Correct 12 ms 2284 KB Output is correct
15 Correct 17 ms 3204 KB Output is correct
16 Correct 23 ms 3916 KB Output is correct
17 Correct 22 ms 3924 KB Output is correct
18 Correct 21 ms 3916 KB Output is correct
19 Correct 21 ms 3924 KB Output is correct
20 Correct 23 ms 3892 KB Output is correct
21 Correct 22 ms 3948 KB Output is correct
22 Correct 26 ms 3916 KB Output is correct
23 Correct 25 ms 3936 KB Output is correct
24 Correct 22 ms 3956 KB Output is correct
25 Correct 23 ms 3892 KB Output is correct
26 Correct 6 ms 1492 KB Output is correct
27 Correct 7 ms 1528 KB Output is correct
28 Correct 6 ms 1620 KB Output is correct
29 Correct 12 ms 2528 KB Output is correct
30 Correct 18 ms 3160 KB Output is correct
31 Correct 23 ms 3868 KB Output is correct
32 Correct 26 ms 3916 KB Output is correct
33 Correct 24 ms 3876 KB Output is correct
34 Correct 24 ms 3916 KB Output is correct
35 Correct 24 ms 3936 KB Output is correct
36 Correct 23 ms 3912 KB Output is correct
37 Correct 23 ms 3960 KB Output is correct
38 Correct 27 ms 3904 KB Output is correct
39 Correct 27 ms 3916 KB Output is correct
40 Correct 26 ms 3920 KB Output is correct
41 Correct 6 ms 1492 KB Output is correct
42 Correct 5 ms 1492 KB Output is correct
43 Correct 6 ms 1492 KB Output is correct
44 Correct 7 ms 1616 KB Output is correct
45 Correct 7 ms 1524 KB Output is correct
46 Correct 6 ms 1640 KB Output is correct
47 Correct 9 ms 2032 KB Output is correct
48 Correct 9 ms 1984 KB Output is correct
49 Correct 13 ms 2376 KB Output is correct
50 Correct 21 ms 3156 KB Output is correct
51 Correct 27 ms 3904 KB Output is correct
52 Correct 25 ms 3916 KB Output is correct
53 Correct 25 ms 3988 KB Output is correct
54 Correct 24 ms 3908 KB Output is correct
55 Correct 25 ms 3916 KB Output is correct
56 Correct 26 ms 3960 KB Output is correct
57 Correct 26 ms 3940 KB Output is correct
58 Correct 25 ms 3944 KB Output is correct
59 Correct 37 ms 3904 KB Output is correct
60 Correct 26 ms 3920 KB Output is correct
61 Correct 26 ms 3916 KB Output is correct
62 Correct 25 ms 3976 KB Output is correct
63 Correct 24 ms 3912 KB Output is correct
64 Correct 25 ms 3932 KB Output is correct
65 Correct 25 ms 3916 KB Output is correct
66 Correct 24 ms 3948 KB Output is correct
67 Correct 25 ms 3924 KB Output is correct
68 Correct 28 ms 3932 KB Output is correct
69 Correct 25 ms 3892 KB Output is correct
70 Correct 26 ms 3936 KB Output is correct
71 Correct 10 ms 1988 KB Output is correct
72 Correct 10 ms 2016 KB Output is correct
73 Correct 10 ms 2016 KB Output is correct
74 Correct 10 ms 1972 KB Output is correct
75 Correct 10 ms 1912 KB Output is correct
76 Correct 14 ms 2384 KB Output is correct
77 Correct 12 ms 2384 KB Output is correct
78 Correct 15 ms 2380 KB Output is correct
79 Correct 13 ms 2388 KB Output is correct
80 Correct 13 ms 2376 KB Output is correct
81 Correct 22 ms 3144 KB Output is correct
82 Correct 20 ms 3112 KB Output is correct
83 Correct 21 ms 3276 KB Output is correct
84 Correct 21 ms 3176 KB Output is correct
85 Correct 21 ms 3100 KB Output is correct
86 Correct 21 ms 3144 KB Output is correct
87 Correct 25 ms 3132 KB Output is correct
88 Correct 22 ms 3104 KB Output is correct
89 Correct 22 ms 3208 KB Output is correct
90 Correct 21 ms 3168 KB Output is correct
91 Correct 28 ms 3912 KB Output is correct
92 Correct 28 ms 3964 KB Output is correct
93 Correct 28 ms 3916 KB Output is correct
94 Correct 30 ms 3956 KB Output is correct
95 Correct 28 ms 3964 KB Output is correct
96 Correct 31 ms 3904 KB Output is correct
97 Correct 33 ms 3904 KB Output is correct
98 Correct 32 ms 3924 KB Output is correct
99 Correct 31 ms 3956 KB Output is correct
100 Correct 31 ms 3904 KB Output is correct
101 Correct 31 ms 3916 KB Output is correct
102 Correct 41 ms 3872 KB Output is correct
103 Correct 35 ms 3916 KB Output is correct
104 Correct 31 ms 3968 KB Output is correct
105 Correct 32 ms 3916 KB Output is correct
106 Correct 32 ms 4004 KB Output is correct
107 Correct 30 ms 3852 KB Output is correct
108 Correct 31 ms 3872 KB Output is correct
109 Correct 30 ms 3904 KB Output is correct
110 Correct 31 ms 3880 KB Output is correct
111 Correct 31 ms 3948 KB Output is correct
112 Correct 31 ms 3944 KB Output is correct
113 Correct 33 ms 3844 KB Output is correct
114 Correct 30 ms 3960 KB Output is correct
115 Correct 31 ms 3876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1492 KB Output is correct
2 Correct 5 ms 1492 KB Output is correct
3 Correct 6 ms 1492 KB Output is correct
4 Correct 5 ms 1492 KB Output is correct
5 Correct 6 ms 1492 KB Output is correct
6 Correct 5 ms 1492 KB Output is correct
7 Correct 7 ms 1492 KB Output is correct
8 Correct 5 ms 1492 KB Output is correct
9 Correct 6 ms 1492 KB Output is correct
10 Correct 6 ms 1492 KB Output is correct
11 Correct 6 ms 1492 KB Output is correct
12 Correct 7 ms 1512 KB Output is correct
13 Correct 6 ms 1492 KB Output is correct
14 Correct 12 ms 2284 KB Output is correct
15 Correct 17 ms 3204 KB Output is correct
16 Correct 23 ms 3916 KB Output is correct
17 Correct 22 ms 3924 KB Output is correct
18 Correct 21 ms 3916 KB Output is correct
19 Correct 21 ms 3924 KB Output is correct
20 Correct 23 ms 3892 KB Output is correct
21 Correct 22 ms 3948 KB Output is correct
22 Correct 26 ms 3916 KB Output is correct
23 Correct 25 ms 3936 KB Output is correct
24 Correct 22 ms 3956 KB Output is correct
25 Correct 23 ms 3892 KB Output is correct
26 Correct 6 ms 1492 KB Output is correct
27 Correct 7 ms 1528 KB Output is correct
28 Correct 6 ms 1620 KB Output is correct
29 Correct 12 ms 2528 KB Output is correct
30 Correct 18 ms 3160 KB Output is correct
31 Correct 23 ms 3868 KB Output is correct
32 Correct 26 ms 3916 KB Output is correct
33 Correct 24 ms 3876 KB Output is correct
34 Correct 24 ms 3916 KB Output is correct
35 Correct 24 ms 3936 KB Output is correct
36 Correct 23 ms 3912 KB Output is correct
37 Correct 23 ms 3960 KB Output is correct
38 Correct 27 ms 3904 KB Output is correct
39 Correct 27 ms 3916 KB Output is correct
40 Correct 26 ms 3920 KB Output is correct
41 Correct 6 ms 1492 KB Output is correct
42 Correct 5 ms 1492 KB Output is correct
43 Correct 6 ms 1492 KB Output is correct
44 Correct 7 ms 1616 KB Output is correct
45 Correct 7 ms 1524 KB Output is correct
46 Correct 6 ms 1640 KB Output is correct
47 Correct 9 ms 2032 KB Output is correct
48 Correct 9 ms 1984 KB Output is correct
49 Correct 13 ms 2376 KB Output is correct
50 Correct 21 ms 3156 KB Output is correct
51 Correct 27 ms 3904 KB Output is correct
52 Correct 25 ms 3916 KB Output is correct
53 Correct 25 ms 3988 KB Output is correct
54 Correct 24 ms 3908 KB Output is correct
55 Correct 25 ms 3916 KB Output is correct
56 Correct 26 ms 3960 KB Output is correct
57 Correct 26 ms 3940 KB Output is correct
58 Correct 25 ms 3944 KB Output is correct
59 Correct 37 ms 3904 KB Output is correct
60 Correct 26 ms 3920 KB Output is correct
61 Correct 26 ms 3916 KB Output is correct
62 Correct 25 ms 3976 KB Output is correct
63 Correct 24 ms 3912 KB Output is correct
64 Correct 25 ms 3932 KB Output is correct
65 Correct 25 ms 3916 KB Output is correct
66 Correct 24 ms 3948 KB Output is correct
67 Correct 25 ms 3924 KB Output is correct
68 Correct 28 ms 3932 KB Output is correct
69 Correct 25 ms 3892 KB Output is correct
70 Correct 26 ms 3936 KB Output is correct
71 Correct 10 ms 1988 KB Output is correct
72 Correct 10 ms 2016 KB Output is correct
73 Correct 10 ms 2016 KB Output is correct
74 Correct 10 ms 1972 KB Output is correct
75 Correct 10 ms 1912 KB Output is correct
76 Correct 14 ms 2384 KB Output is correct
77 Correct 12 ms 2384 KB Output is correct
78 Correct 15 ms 2380 KB Output is correct
79 Correct 13 ms 2388 KB Output is correct
80 Correct 13 ms 2376 KB Output is correct
81 Correct 22 ms 3144 KB Output is correct
82 Correct 20 ms 3112 KB Output is correct
83 Correct 21 ms 3276 KB Output is correct
84 Correct 21 ms 3176 KB Output is correct
85 Correct 21 ms 3100 KB Output is correct
86 Correct 21 ms 3144 KB Output is correct
87 Correct 25 ms 3132 KB Output is correct
88 Correct 22 ms 3104 KB Output is correct
89 Correct 22 ms 3208 KB Output is correct
90 Correct 21 ms 3168 KB Output is correct
91 Correct 28 ms 3912 KB Output is correct
92 Correct 28 ms 3964 KB Output is correct
93 Correct 28 ms 3916 KB Output is correct
94 Correct 30 ms 3956 KB Output is correct
95 Correct 28 ms 3964 KB Output is correct
96 Correct 31 ms 3904 KB Output is correct
97 Correct 33 ms 3904 KB Output is correct
98 Correct 32 ms 3924 KB Output is correct
99 Correct 31 ms 3956 KB Output is correct
100 Correct 31 ms 3904 KB Output is correct
101 Correct 31 ms 3916 KB Output is correct
102 Correct 41 ms 3872 KB Output is correct
103 Correct 35 ms 3916 KB Output is correct
104 Correct 31 ms 3968 KB Output is correct
105 Correct 32 ms 3916 KB Output is correct
106 Correct 32 ms 4004 KB Output is correct
107 Correct 30 ms 3852 KB Output is correct
108 Correct 31 ms 3872 KB Output is correct
109 Correct 30 ms 3904 KB Output is correct
110 Correct 31 ms 3880 KB Output is correct
111 Correct 31 ms 3948 KB Output is correct
112 Correct 31 ms 3944 KB Output is correct
113 Correct 33 ms 3844 KB Output is correct
114 Correct 30 ms 3960 KB Output is correct
115 Correct 31 ms 3876 KB Output is correct
116 Execution timed out 7006 ms 1816 KB Time limit exceeded
117 Halted 0 ms 0 KB -