Submission #650648

# Submission time Handle Problem Language Result Execution time Memory
650648 2022-10-14T11:40:49 Z 1bin Diversity (CEOI21_diversity) C++14
64 / 100
7000 ms 6592 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;
map<int, 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(--mp[c[x]] == 0) mp.erase(c[x]);
    cnt[c[x]]--;
    c[x] += v;
    mp[c[x]] = ++cnt[c[x]];
    //for(int i = 1; i <= 3; i++) cout << cnt[i] << ' ';
    //cout << '\n';
    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;
        //cout << "start qury \n";
        for(auto& [c, t] : mp){
            if(!c) continue;
            x = (t + 1) / 2; y = t - x;
            ll n = r - l + 1;
            //cout << c << ' ' << t << '\n';
            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;
}

Compilation message

diversity.cpp: In function 'int main()':
diversity.cpp:46:19: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   46 |         for(auto& [c, t] : mp){
      |                   ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 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 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 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 14 ms 1276 KB Output is correct
5 Correct 32 ms 2836 KB Output is correct
6 Correct 54 ms 3880 KB Output is correct
7 Correct 44 ms 4548 KB Output is correct
8 Correct 49 ms 3660 KB Output is correct
9 Correct 46 ms 3716 KB Output is correct
10 Correct 45 ms 4012 KB Output is correct
11 Correct 45 ms 3788 KB Output is correct
12 Correct 46 ms 3708 KB Output is correct
13 Correct 48 ms 3720 KB Output is correct
14 Correct 45 ms 3920 KB Output is correct
15 Correct 44 ms 3736 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 14 ms 1276 KB Output is correct
5 Correct 32 ms 2836 KB Output is correct
6 Correct 54 ms 3880 KB Output is correct
7 Correct 44 ms 4548 KB Output is correct
8 Correct 49 ms 3660 KB Output is correct
9 Correct 46 ms 3716 KB Output is correct
10 Correct 45 ms 4012 KB Output is correct
11 Correct 45 ms 3788 KB Output is correct
12 Correct 46 ms 3708 KB Output is correct
13 Correct 48 ms 3720 KB Output is correct
14 Correct 45 ms 3920 KB Output is correct
15 Correct 44 ms 3736 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 468 KB Output is correct
19 Correct 18 ms 1492 KB Output is correct
20 Correct 35 ms 2556 KB Output is correct
21 Correct 50 ms 3880 KB Output is correct
22 Correct 72 ms 3772 KB Output is correct
23 Correct 51 ms 3820 KB Output is correct
24 Correct 54 ms 3640 KB Output is correct
25 Correct 52 ms 3768 KB Output is correct
26 Correct 56 ms 3736 KB Output is correct
27 Correct 53 ms 3788 KB Output is correct
28 Correct 50 ms 3988 KB Output is correct
29 Correct 52 ms 3736 KB Output is correct
30 Correct 56 ms 3788 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 14 ms 1276 KB Output is correct
5 Correct 32 ms 2836 KB Output is correct
6 Correct 54 ms 3880 KB Output is correct
7 Correct 44 ms 4548 KB Output is correct
8 Correct 49 ms 3660 KB Output is correct
9 Correct 46 ms 3716 KB Output is correct
10 Correct 45 ms 4012 KB Output is correct
11 Correct 45 ms 3788 KB Output is correct
12 Correct 46 ms 3708 KB Output is correct
13 Correct 48 ms 3720 KB Output is correct
14 Correct 45 ms 3920 KB Output is correct
15 Correct 44 ms 3736 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 468 KB Output is correct
19 Correct 18 ms 1492 KB Output is correct
20 Correct 35 ms 2556 KB Output is correct
21 Correct 50 ms 3880 KB Output is correct
22 Correct 72 ms 3772 KB Output is correct
23 Correct 51 ms 3820 KB Output is correct
24 Correct 54 ms 3640 KB Output is correct
25 Correct 52 ms 3768 KB Output is correct
26 Correct 56 ms 3736 KB Output is correct
27 Correct 53 ms 3788 KB Output is correct
28 Correct 50 ms 3988 KB Output is correct
29 Correct 52 ms 3736 KB Output is correct
30 Correct 56 ms 3788 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 3 ms 472 KB Output is correct
35 Correct 2 ms 468 KB Output is correct
36 Correct 2 ms 468 KB Output is correct
37 Correct 9 ms 852 KB Output is correct
38 Correct 8 ms 852 KB Output is correct
39 Correct 18 ms 1500 KB Output is correct
40 Correct 39 ms 2708 KB Output is correct
41 Correct 64 ms 3848 KB Output is correct
42 Correct 63 ms 3908 KB Output is correct
43 Correct 64 ms 3744 KB Output is correct
44 Correct 63 ms 3848 KB Output is correct
45 Correct 63 ms 3796 KB Output is correct
46 Correct 64 ms 3800 KB Output is correct
47 Correct 59 ms 3756 KB Output is correct
48 Correct 60 ms 3848 KB Output is correct
49 Correct 60 ms 3860 KB Output is correct
50 Correct 65 ms 3864 KB Output is correct
51 Correct 64 ms 3864 KB Output is correct
52 Correct 65 ms 3872 KB Output is correct
53 Correct 63 ms 3872 KB Output is correct
54 Correct 69 ms 3872 KB Output is correct
55 Correct 61 ms 3772 KB Output is correct
56 Correct 79 ms 3868 KB Output is correct
57 Correct 76 ms 3840 KB Output is correct
58 Correct 61 ms 3864 KB Output is correct
59 Correct 60 ms 3848 KB Output is correct
60 Correct 59 ms 3872 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 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 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 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 14 ms 1276 KB Output is correct
15 Correct 32 ms 2836 KB Output is correct
16 Correct 54 ms 3880 KB Output is correct
17 Correct 44 ms 4548 KB Output is correct
18 Correct 49 ms 3660 KB Output is correct
19 Correct 46 ms 3716 KB Output is correct
20 Correct 45 ms 4012 KB Output is correct
21 Correct 45 ms 3788 KB Output is correct
22 Correct 46 ms 3708 KB Output is correct
23 Correct 48 ms 3720 KB Output is correct
24 Correct 45 ms 3920 KB Output is correct
25 Correct 44 ms 3736 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 468 KB Output is correct
29 Correct 18 ms 1492 KB Output is correct
30 Correct 35 ms 2556 KB Output is correct
31 Correct 50 ms 3880 KB Output is correct
32 Correct 72 ms 3772 KB Output is correct
33 Correct 51 ms 3820 KB Output is correct
34 Correct 54 ms 3640 KB Output is correct
35 Correct 52 ms 3768 KB Output is correct
36 Correct 56 ms 3736 KB Output is correct
37 Correct 53 ms 3788 KB Output is correct
38 Correct 50 ms 3988 KB Output is correct
39 Correct 52 ms 3736 KB Output is correct
40 Correct 56 ms 3788 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 3 ms 472 KB Output is correct
45 Correct 2 ms 468 KB Output is correct
46 Correct 2 ms 468 KB Output is correct
47 Correct 9 ms 852 KB Output is correct
48 Correct 8 ms 852 KB Output is correct
49 Correct 18 ms 1500 KB Output is correct
50 Correct 39 ms 2708 KB Output is correct
51 Correct 64 ms 3848 KB Output is correct
52 Correct 63 ms 3908 KB Output is correct
53 Correct 64 ms 3744 KB Output is correct
54 Correct 63 ms 3848 KB Output is correct
55 Correct 63 ms 3796 KB Output is correct
56 Correct 64 ms 3800 KB Output is correct
57 Correct 59 ms 3756 KB Output is correct
58 Correct 60 ms 3848 KB Output is correct
59 Correct 60 ms 3860 KB Output is correct
60 Correct 65 ms 3864 KB Output is correct
61 Correct 64 ms 3864 KB Output is correct
62 Correct 65 ms 3872 KB Output is correct
63 Correct 63 ms 3872 KB Output is correct
64 Correct 69 ms 3872 KB Output is correct
65 Correct 61 ms 3772 KB Output is correct
66 Correct 79 ms 3868 KB Output is correct
67 Correct 76 ms 3840 KB Output is correct
68 Correct 61 ms 3864 KB Output is correct
69 Correct 60 ms 3848 KB Output is correct
70 Correct 59 ms 3872 KB Output is correct
71 Correct 7 ms 984 KB Output is correct
72 Correct 6 ms 980 KB Output is correct
73 Correct 7 ms 984 KB Output is correct
74 Correct 7 ms 860 KB Output is correct
75 Correct 7 ms 980 KB Output is correct
76 Correct 15 ms 1576 KB Output is correct
77 Correct 12 ms 1612 KB Output is correct
78 Correct 13 ms 1656 KB Output is correct
79 Correct 13 ms 1624 KB Output is correct
80 Correct 13 ms 1624 KB Output is correct
81 Correct 27 ms 2912 KB Output is correct
82 Correct 26 ms 2824 KB Output is correct
83 Correct 27 ms 2940 KB Output is correct
84 Correct 25 ms 2892 KB Output is correct
85 Correct 24 ms 2832 KB Output is correct
86 Correct 25 ms 3124 KB Output is correct
87 Correct 24 ms 3048 KB Output is correct
88 Correct 24 ms 3032 KB Output is correct
89 Correct 26 ms 3072 KB Output is correct
90 Correct 25 ms 3080 KB Output is correct
91 Correct 33 ms 5140 KB Output is correct
92 Correct 32 ms 5232 KB Output is correct
93 Correct 46 ms 5300 KB Output is correct
94 Correct 32 ms 5160 KB Output is correct
95 Correct 37 ms 5120 KB Output is correct
96 Correct 36 ms 6100 KB Output is correct
97 Correct 39 ms 6036 KB Output is correct
98 Correct 40 ms 6052 KB Output is correct
99 Correct 42 ms 6104 KB Output is correct
100 Correct 39 ms 6108 KB Output is correct
101 Correct 35 ms 6096 KB Output is correct
102 Correct 35 ms 6072 KB Output is correct
103 Correct 35 ms 6008 KB Output is correct
104 Correct 36 ms 6080 KB Output is correct
105 Correct 38 ms 6076 KB Output is correct
106 Correct 41 ms 6472 KB Output is correct
107 Correct 35 ms 6476 KB Output is correct
108 Correct 35 ms 6544 KB Output is correct
109 Correct 34 ms 6480 KB Output is correct
110 Correct 34 ms 6592 KB Output is correct
111 Correct 34 ms 6516 KB Output is correct
112 Correct 37 ms 6528 KB Output is correct
113 Correct 41 ms 6464 KB Output is correct
114 Correct 35 ms 6488 KB Output is correct
115 Correct 38 ms 6520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 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 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 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 14 ms 1276 KB Output is correct
15 Correct 32 ms 2836 KB Output is correct
16 Correct 54 ms 3880 KB Output is correct
17 Correct 44 ms 4548 KB Output is correct
18 Correct 49 ms 3660 KB Output is correct
19 Correct 46 ms 3716 KB Output is correct
20 Correct 45 ms 4012 KB Output is correct
21 Correct 45 ms 3788 KB Output is correct
22 Correct 46 ms 3708 KB Output is correct
23 Correct 48 ms 3720 KB Output is correct
24 Correct 45 ms 3920 KB Output is correct
25 Correct 44 ms 3736 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 468 KB Output is correct
29 Correct 18 ms 1492 KB Output is correct
30 Correct 35 ms 2556 KB Output is correct
31 Correct 50 ms 3880 KB Output is correct
32 Correct 72 ms 3772 KB Output is correct
33 Correct 51 ms 3820 KB Output is correct
34 Correct 54 ms 3640 KB Output is correct
35 Correct 52 ms 3768 KB Output is correct
36 Correct 56 ms 3736 KB Output is correct
37 Correct 53 ms 3788 KB Output is correct
38 Correct 50 ms 3988 KB Output is correct
39 Correct 52 ms 3736 KB Output is correct
40 Correct 56 ms 3788 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 3 ms 472 KB Output is correct
45 Correct 2 ms 468 KB Output is correct
46 Correct 2 ms 468 KB Output is correct
47 Correct 9 ms 852 KB Output is correct
48 Correct 8 ms 852 KB Output is correct
49 Correct 18 ms 1500 KB Output is correct
50 Correct 39 ms 2708 KB Output is correct
51 Correct 64 ms 3848 KB Output is correct
52 Correct 63 ms 3908 KB Output is correct
53 Correct 64 ms 3744 KB Output is correct
54 Correct 63 ms 3848 KB Output is correct
55 Correct 63 ms 3796 KB Output is correct
56 Correct 64 ms 3800 KB Output is correct
57 Correct 59 ms 3756 KB Output is correct
58 Correct 60 ms 3848 KB Output is correct
59 Correct 60 ms 3860 KB Output is correct
60 Correct 65 ms 3864 KB Output is correct
61 Correct 64 ms 3864 KB Output is correct
62 Correct 65 ms 3872 KB Output is correct
63 Correct 63 ms 3872 KB Output is correct
64 Correct 69 ms 3872 KB Output is correct
65 Correct 61 ms 3772 KB Output is correct
66 Correct 79 ms 3868 KB Output is correct
67 Correct 76 ms 3840 KB Output is correct
68 Correct 61 ms 3864 KB Output is correct
69 Correct 60 ms 3848 KB Output is correct
70 Correct 59 ms 3872 KB Output is correct
71 Correct 7 ms 984 KB Output is correct
72 Correct 6 ms 980 KB Output is correct
73 Correct 7 ms 984 KB Output is correct
74 Correct 7 ms 860 KB Output is correct
75 Correct 7 ms 980 KB Output is correct
76 Correct 15 ms 1576 KB Output is correct
77 Correct 12 ms 1612 KB Output is correct
78 Correct 13 ms 1656 KB Output is correct
79 Correct 13 ms 1624 KB Output is correct
80 Correct 13 ms 1624 KB Output is correct
81 Correct 27 ms 2912 KB Output is correct
82 Correct 26 ms 2824 KB Output is correct
83 Correct 27 ms 2940 KB Output is correct
84 Correct 25 ms 2892 KB Output is correct
85 Correct 24 ms 2832 KB Output is correct
86 Correct 25 ms 3124 KB Output is correct
87 Correct 24 ms 3048 KB Output is correct
88 Correct 24 ms 3032 KB Output is correct
89 Correct 26 ms 3072 KB Output is correct
90 Correct 25 ms 3080 KB Output is correct
91 Correct 33 ms 5140 KB Output is correct
92 Correct 32 ms 5232 KB Output is correct
93 Correct 46 ms 5300 KB Output is correct
94 Correct 32 ms 5160 KB Output is correct
95 Correct 37 ms 5120 KB Output is correct
96 Correct 36 ms 6100 KB Output is correct
97 Correct 39 ms 6036 KB Output is correct
98 Correct 40 ms 6052 KB Output is correct
99 Correct 42 ms 6104 KB Output is correct
100 Correct 39 ms 6108 KB Output is correct
101 Correct 35 ms 6096 KB Output is correct
102 Correct 35 ms 6072 KB Output is correct
103 Correct 35 ms 6008 KB Output is correct
104 Correct 36 ms 6080 KB Output is correct
105 Correct 38 ms 6076 KB Output is correct
106 Correct 41 ms 6472 KB Output is correct
107 Correct 35 ms 6476 KB Output is correct
108 Correct 35 ms 6544 KB Output is correct
109 Correct 34 ms 6480 KB Output is correct
110 Correct 34 ms 6592 KB Output is correct
111 Correct 34 ms 6516 KB Output is correct
112 Correct 37 ms 6528 KB Output is correct
113 Correct 41 ms 6464 KB Output is correct
114 Correct 35 ms 6488 KB Output is correct
115 Correct 38 ms 6520 KB Output is correct
116 Correct 1278 ms 2296 KB Output is correct
117 Correct 1111 ms 2292 KB Output is correct
118 Correct 1873 ms 2952 KB Output is correct
119 Correct 1239 ms 2992 KB Output is correct
120 Correct 845 ms 3020 KB Output is correct
121 Correct 1840 ms 3720 KB Output is correct
122 Correct 1301 ms 3652 KB Output is correct
123 Correct 5473 ms 4944 KB Output is correct
124 Correct 2684 ms 5140 KB Output is correct
125 Correct 2035 ms 5188 KB Output is correct
126 Execution timed out 7023 ms 5440 KB Time limit exceeded
127 Halted 0 ms 0 KB -