Submission #650649

# Submission time Handle Problem Language Result Execution time Memory
650649 2022-10-14T11:47:14 Z 1bin Diversity (CEOI21_diversity) C++14
64 / 100
7000 ms 4632 KB
#include <bits/stdc++.h>

using namespace std;

#define all(v) v.begin(), v.end()
typedef long long ll;
const int NMAX = 3e5 + 5;
const int b = 550;
ll n, Q, a[NMAX], ans[NMAX], l, r, c[NMAX], cnt[NMAX], ls, rs, x, y, res;
set<int> mp;
struct query{
    int i, l, r;
    bool operator <(const query& x){
        if(l / b == x.l / b) return (l / b & 1) ? r > x.r : r < x.r;
        else return l / b < x.l / b;
    }
} q[NMAX];

void f(int x, int v){
    if(--cnt[c[x]] == 0) mp.erase(c[x]);
    c[x] += v;
    if(!cnt[c[x]]++) mp.emplace(c[x]);
    return;
}

ll cal(ll l, ll x, ll c){ return x * (x + 1) * (2 * x + 1) / 6 * c * c + c * (l - c) * x * (x + 1) + (l - c) * (l - c) * x;}

int main(void){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    
    cin >> n >> Q;
    for(int i = 1; i <= n; i++) cin >> a[i];
    for(int i = 0; i < Q; i++) cin >> q[i].l >> q[i].r, q[i].i = i;
    sort(q, q + Q);
    l = 1, r = 0;
    for(int i = 0; i < Q; i++){
        while(l > q[i].l) f(a[--l], 1);
        while(r < q[i].r) f(a[++r], 1);
        while(l < q[i].l) f(a[l++], -1);
        while(r > q[i].r) f(a[r--], -1);
        ls = rs = res = 0;
        for(auto& c : mp){
            if(!c) continue;
            ll n = r - l + 1, t = cnt[c];
            x = (t + 1) / 2; y = t - x;
            res += (n * n + c) * t;
            res -= cal(ls, x, c) + cal(n - ls - c - (x - 1) * c, x, c);
            res -= cal(rs, y, c) + cal(n - rs - c - (y - 1) * c, y, c);
            ls += x * c; rs += y * c;
            if(x > y) swap(ls, rs);
        }
        ans[q[i].i] = res / 2;
    }
    
    for(int i = 0; i < Q; i++) cout << ans[i] << '\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 17 ms 1340 KB Output is correct
5 Correct 35 ms 2444 KB Output is correct
6 Correct 45 ms 3044 KB Output is correct
7 Correct 37 ms 3916 KB Output is correct
8 Correct 45 ms 3000 KB Output is correct
9 Correct 42 ms 3048 KB Output is correct
10 Correct 41 ms 3408 KB Output is correct
11 Correct 42 ms 3188 KB Output is correct
12 Correct 42 ms 3064 KB Output is correct
13 Correct 42 ms 3020 KB Output is correct
14 Correct 40 ms 3164 KB Output is correct
15 Correct 40 ms 3176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 17 ms 1340 KB Output is correct
5 Correct 35 ms 2444 KB Output is correct
6 Correct 45 ms 3044 KB Output is correct
7 Correct 37 ms 3916 KB Output is correct
8 Correct 45 ms 3000 KB Output is correct
9 Correct 42 ms 3048 KB Output is correct
10 Correct 41 ms 3408 KB Output is correct
11 Correct 42 ms 3188 KB Output is correct
12 Correct 42 ms 3064 KB Output is correct
13 Correct 42 ms 3020 KB Output is correct
14 Correct 40 ms 3164 KB Output is correct
15 Correct 40 ms 3176 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Correct 17 ms 1168 KB Output is correct
20 Correct 34 ms 2108 KB Output is correct
21 Correct 52 ms 3040 KB Output is correct
22 Correct 52 ms 2884 KB Output is correct
23 Correct 59 ms 3148 KB Output is correct
24 Correct 49 ms 3036 KB Output is correct
25 Correct 48 ms 3004 KB Output is correct
26 Correct 50 ms 2924 KB Output is correct
27 Correct 48 ms 3020 KB Output is correct
28 Correct 47 ms 3280 KB Output is correct
29 Correct 49 ms 2964 KB Output is correct
30 Correct 63 ms 3024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 17 ms 1340 KB Output is correct
5 Correct 35 ms 2444 KB Output is correct
6 Correct 45 ms 3044 KB Output is correct
7 Correct 37 ms 3916 KB Output is correct
8 Correct 45 ms 3000 KB Output is correct
9 Correct 42 ms 3048 KB Output is correct
10 Correct 41 ms 3408 KB Output is correct
11 Correct 42 ms 3188 KB Output is correct
12 Correct 42 ms 3064 KB Output is correct
13 Correct 42 ms 3020 KB Output is correct
14 Correct 40 ms 3164 KB Output is correct
15 Correct 40 ms 3176 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Correct 17 ms 1168 KB Output is correct
20 Correct 34 ms 2108 KB Output is correct
21 Correct 52 ms 3040 KB Output is correct
22 Correct 52 ms 2884 KB Output is correct
23 Correct 59 ms 3148 KB Output is correct
24 Correct 49 ms 3036 KB Output is correct
25 Correct 48 ms 3004 KB Output is correct
26 Correct 50 ms 2924 KB Output is correct
27 Correct 48 ms 3020 KB Output is correct
28 Correct 47 ms 3280 KB Output is correct
29 Correct 49 ms 2964 KB Output is correct
30 Correct 63 ms 3024 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 1 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 7 ms 724 KB Output is correct
38 Correct 5 ms 724 KB Output is correct
39 Correct 10 ms 1080 KB Output is correct
40 Correct 24 ms 1948 KB Output is correct
41 Correct 38 ms 2644 KB Output is correct
42 Correct 43 ms 2732 KB Output is correct
43 Correct 41 ms 2672 KB Output is correct
44 Correct 43 ms 2724 KB Output is correct
45 Correct 42 ms 2644 KB Output is correct
46 Correct 40 ms 2724 KB Output is correct
47 Correct 39 ms 2724 KB Output is correct
48 Correct 39 ms 2632 KB Output is correct
49 Correct 40 ms 2720 KB Output is correct
50 Correct 38 ms 2616 KB Output is correct
51 Correct 40 ms 2732 KB Output is correct
52 Correct 43 ms 2712 KB Output is correct
53 Correct 39 ms 2660 KB Output is correct
54 Correct 41 ms 2644 KB Output is correct
55 Correct 41 ms 2740 KB Output is correct
56 Correct 42 ms 2716 KB Output is correct
57 Correct 42 ms 2724 KB Output is correct
58 Correct 38 ms 2720 KB Output is correct
59 Correct 38 ms 2644 KB Output is correct
60 Correct 38 ms 2644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
14 Correct 17 ms 1340 KB Output is correct
15 Correct 35 ms 2444 KB Output is correct
16 Correct 45 ms 3044 KB Output is correct
17 Correct 37 ms 3916 KB Output is correct
18 Correct 45 ms 3000 KB Output is correct
19 Correct 42 ms 3048 KB Output is correct
20 Correct 41 ms 3408 KB Output is correct
21 Correct 42 ms 3188 KB Output is correct
22 Correct 42 ms 3064 KB Output is correct
23 Correct 42 ms 3020 KB Output is correct
24 Correct 40 ms 3164 KB Output is correct
25 Correct 40 ms 3176 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 2 ms 340 KB Output is correct
29 Correct 17 ms 1168 KB Output is correct
30 Correct 34 ms 2108 KB Output is correct
31 Correct 52 ms 3040 KB Output is correct
32 Correct 52 ms 2884 KB Output is correct
33 Correct 59 ms 3148 KB Output is correct
34 Correct 49 ms 3036 KB Output is correct
35 Correct 48 ms 3004 KB Output is correct
36 Correct 50 ms 2924 KB Output is correct
37 Correct 48 ms 3020 KB Output is correct
38 Correct 47 ms 3280 KB Output is correct
39 Correct 49 ms 2964 KB Output is correct
40 Correct 63 ms 3024 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 1 ms 340 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 7 ms 724 KB Output is correct
48 Correct 5 ms 724 KB Output is correct
49 Correct 10 ms 1080 KB Output is correct
50 Correct 24 ms 1948 KB Output is correct
51 Correct 38 ms 2644 KB Output is correct
52 Correct 43 ms 2732 KB Output is correct
53 Correct 41 ms 2672 KB Output is correct
54 Correct 43 ms 2724 KB Output is correct
55 Correct 42 ms 2644 KB Output is correct
56 Correct 40 ms 2724 KB Output is correct
57 Correct 39 ms 2724 KB Output is correct
58 Correct 39 ms 2632 KB Output is correct
59 Correct 40 ms 2720 KB Output is correct
60 Correct 38 ms 2616 KB Output is correct
61 Correct 40 ms 2732 KB Output is correct
62 Correct 43 ms 2712 KB Output is correct
63 Correct 39 ms 2660 KB Output is correct
64 Correct 41 ms 2644 KB Output is correct
65 Correct 41 ms 2740 KB Output is correct
66 Correct 42 ms 2716 KB Output is correct
67 Correct 42 ms 2724 KB Output is correct
68 Correct 38 ms 2720 KB Output is correct
69 Correct 38 ms 2644 KB Output is correct
70 Correct 38 ms 2644 KB Output is correct
71 Correct 4 ms 704 KB Output is correct
72 Correct 4 ms 764 KB Output is correct
73 Correct 4 ms 724 KB Output is correct
74 Correct 5 ms 724 KB Output is correct
75 Correct 5 ms 724 KB Output is correct
76 Correct 8 ms 1180 KB Output is correct
77 Correct 9 ms 1180 KB Output is correct
78 Correct 8 ms 1152 KB Output is correct
79 Correct 12 ms 1084 KB Output is correct
80 Correct 13 ms 1188 KB Output is correct
81 Correct 19 ms 1996 KB Output is correct
82 Correct 21 ms 2004 KB Output is correct
83 Correct 21 ms 1968 KB Output is correct
84 Correct 16 ms 1892 KB Output is correct
85 Correct 18 ms 2004 KB Output is correct
86 Correct 18 ms 2004 KB Output is correct
87 Correct 19 ms 2040 KB Output is correct
88 Correct 18 ms 2076 KB Output is correct
89 Correct 19 ms 2068 KB Output is correct
90 Correct 18 ms 1964 KB Output is correct
91 Correct 27 ms 3404 KB Output is correct
92 Correct 28 ms 3424 KB Output is correct
93 Correct 29 ms 3384 KB Output is correct
94 Correct 28 ms 3476 KB Output is correct
95 Correct 31 ms 3404 KB Output is correct
96 Correct 34 ms 4160 KB Output is correct
97 Correct 33 ms 4236 KB Output is correct
98 Correct 33 ms 4172 KB Output is correct
99 Correct 36 ms 4172 KB Output is correct
100 Correct 31 ms 4156 KB Output is correct
101 Correct 33 ms 4236 KB Output is correct
102 Correct 31 ms 4240 KB Output is correct
103 Correct 32 ms 4208 KB Output is correct
104 Correct 30 ms 4152 KB Output is correct
105 Correct 31 ms 4176 KB Output is correct
106 Correct 31 ms 4632 KB Output is correct
107 Correct 32 ms 4596 KB Output is correct
108 Correct 32 ms 4584 KB Output is correct
109 Correct 31 ms 4564 KB Output is correct
110 Correct 31 ms 4632 KB Output is correct
111 Correct 34 ms 4600 KB Output is correct
112 Correct 34 ms 4564 KB Output is correct
113 Correct 30 ms 4540 KB Output is correct
114 Correct 31 ms 4632 KB Output is correct
115 Correct 31 ms 4564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
14 Correct 17 ms 1340 KB Output is correct
15 Correct 35 ms 2444 KB Output is correct
16 Correct 45 ms 3044 KB Output is correct
17 Correct 37 ms 3916 KB Output is correct
18 Correct 45 ms 3000 KB Output is correct
19 Correct 42 ms 3048 KB Output is correct
20 Correct 41 ms 3408 KB Output is correct
21 Correct 42 ms 3188 KB Output is correct
22 Correct 42 ms 3064 KB Output is correct
23 Correct 42 ms 3020 KB Output is correct
24 Correct 40 ms 3164 KB Output is correct
25 Correct 40 ms 3176 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 2 ms 340 KB Output is correct
29 Correct 17 ms 1168 KB Output is correct
30 Correct 34 ms 2108 KB Output is correct
31 Correct 52 ms 3040 KB Output is correct
32 Correct 52 ms 2884 KB Output is correct
33 Correct 59 ms 3148 KB Output is correct
34 Correct 49 ms 3036 KB Output is correct
35 Correct 48 ms 3004 KB Output is correct
36 Correct 50 ms 2924 KB Output is correct
37 Correct 48 ms 3020 KB Output is correct
38 Correct 47 ms 3280 KB Output is correct
39 Correct 49 ms 2964 KB Output is correct
40 Correct 63 ms 3024 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 1 ms 340 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 7 ms 724 KB Output is correct
48 Correct 5 ms 724 KB Output is correct
49 Correct 10 ms 1080 KB Output is correct
50 Correct 24 ms 1948 KB Output is correct
51 Correct 38 ms 2644 KB Output is correct
52 Correct 43 ms 2732 KB Output is correct
53 Correct 41 ms 2672 KB Output is correct
54 Correct 43 ms 2724 KB Output is correct
55 Correct 42 ms 2644 KB Output is correct
56 Correct 40 ms 2724 KB Output is correct
57 Correct 39 ms 2724 KB Output is correct
58 Correct 39 ms 2632 KB Output is correct
59 Correct 40 ms 2720 KB Output is correct
60 Correct 38 ms 2616 KB Output is correct
61 Correct 40 ms 2732 KB Output is correct
62 Correct 43 ms 2712 KB Output is correct
63 Correct 39 ms 2660 KB Output is correct
64 Correct 41 ms 2644 KB Output is correct
65 Correct 41 ms 2740 KB Output is correct
66 Correct 42 ms 2716 KB Output is correct
67 Correct 42 ms 2724 KB Output is correct
68 Correct 38 ms 2720 KB Output is correct
69 Correct 38 ms 2644 KB Output is correct
70 Correct 38 ms 2644 KB Output is correct
71 Correct 4 ms 704 KB Output is correct
72 Correct 4 ms 764 KB Output is correct
73 Correct 4 ms 724 KB Output is correct
74 Correct 5 ms 724 KB Output is correct
75 Correct 5 ms 724 KB Output is correct
76 Correct 8 ms 1180 KB Output is correct
77 Correct 9 ms 1180 KB Output is correct
78 Correct 8 ms 1152 KB Output is correct
79 Correct 12 ms 1084 KB Output is correct
80 Correct 13 ms 1188 KB Output is correct
81 Correct 19 ms 1996 KB Output is correct
82 Correct 21 ms 2004 KB Output is correct
83 Correct 21 ms 1968 KB Output is correct
84 Correct 16 ms 1892 KB Output is correct
85 Correct 18 ms 2004 KB Output is correct
86 Correct 18 ms 2004 KB Output is correct
87 Correct 19 ms 2040 KB Output is correct
88 Correct 18 ms 2076 KB Output is correct
89 Correct 19 ms 2068 KB Output is correct
90 Correct 18 ms 1964 KB Output is correct
91 Correct 27 ms 3404 KB Output is correct
92 Correct 28 ms 3424 KB Output is correct
93 Correct 29 ms 3384 KB Output is correct
94 Correct 28 ms 3476 KB Output is correct
95 Correct 31 ms 3404 KB Output is correct
96 Correct 34 ms 4160 KB Output is correct
97 Correct 33 ms 4236 KB Output is correct
98 Correct 33 ms 4172 KB Output is correct
99 Correct 36 ms 4172 KB Output is correct
100 Correct 31 ms 4156 KB Output is correct
101 Correct 33 ms 4236 KB Output is correct
102 Correct 31 ms 4240 KB Output is correct
103 Correct 32 ms 4208 KB Output is correct
104 Correct 30 ms 4152 KB Output is correct
105 Correct 31 ms 4176 KB Output is correct
106 Correct 31 ms 4632 KB Output is correct
107 Correct 32 ms 4596 KB Output is correct
108 Correct 32 ms 4584 KB Output is correct
109 Correct 31 ms 4564 KB Output is correct
110 Correct 31 ms 4632 KB Output is correct
111 Correct 34 ms 4600 KB Output is correct
112 Correct 34 ms 4564 KB Output is correct
113 Correct 30 ms 4540 KB Output is correct
114 Correct 31 ms 4632 KB Output is correct
115 Correct 31 ms 4564 KB Output is correct
116 Correct 917 ms 1788 KB Output is correct
117 Correct 728 ms 1912 KB Output is correct
118 Correct 1351 ms 2236 KB Output is correct
119 Correct 599 ms 2236 KB Output is correct
120 Correct 377 ms 2236 KB Output is correct
121 Correct 799 ms 2636 KB Output is correct
122 Correct 485 ms 2640 KB Output is correct
123 Correct 2421 ms 3560 KB Output is correct
124 Correct 869 ms 3576 KB Output is correct
125 Correct 744 ms 3660 KB Output is correct
126 Execution timed out 7019 ms 3844 KB Time limit exceeded
127 Halted 0 ms 0 KB -