답안 #650650

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
650650 2022-10-14T11:53:59 Z 1bin Diversity (CEOI21_diversity) C++14
64 / 100
7000 ms 4632 KB
#pragma GCC optimize("Ofast,unroll-loops")
#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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 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 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 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 2 ms 432 KB Output is correct
4 Correct 15 ms 1328 KB Output is correct
5 Correct 26 ms 2444 KB Output is correct
6 Correct 50 ms 3068 KB Output is correct
7 Correct 36 ms 3928 KB Output is correct
8 Correct 41 ms 3020 KB Output is correct
9 Correct 43 ms 3148 KB Output is correct
10 Correct 48 ms 3372 KB Output is correct
11 Correct 46 ms 3216 KB Output is correct
12 Correct 41 ms 2984 KB Output is correct
13 Correct 41 ms 3060 KB Output is correct
14 Correct 40 ms 3168 KB Output is correct
15 Correct 44 ms 3152 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 2 ms 432 KB Output is correct
4 Correct 15 ms 1328 KB Output is correct
5 Correct 26 ms 2444 KB Output is correct
6 Correct 50 ms 3068 KB Output is correct
7 Correct 36 ms 3928 KB Output is correct
8 Correct 41 ms 3020 KB Output is correct
9 Correct 43 ms 3148 KB Output is correct
10 Correct 48 ms 3372 KB Output is correct
11 Correct 46 ms 3216 KB Output is correct
12 Correct 41 ms 2984 KB Output is correct
13 Correct 41 ms 3060 KB Output is correct
14 Correct 40 ms 3168 KB Output is correct
15 Correct 44 ms 3152 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 16 ms 1236 KB Output is correct
20 Correct 35 ms 2132 KB Output is correct
21 Correct 51 ms 3120 KB Output is correct
22 Correct 53 ms 2996 KB Output is correct
23 Correct 47 ms 3012 KB Output is correct
24 Correct 49 ms 2900 KB Output is correct
25 Correct 47 ms 2900 KB Output is correct
26 Correct 53 ms 2944 KB Output is correct
27 Correct 62 ms 2944 KB Output is correct
28 Correct 53 ms 3192 KB Output is correct
29 Correct 50 ms 2892 KB Output is correct
30 Correct 53 ms 2992 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 2 ms 432 KB Output is correct
4 Correct 15 ms 1328 KB Output is correct
5 Correct 26 ms 2444 KB Output is correct
6 Correct 50 ms 3068 KB Output is correct
7 Correct 36 ms 3928 KB Output is correct
8 Correct 41 ms 3020 KB Output is correct
9 Correct 43 ms 3148 KB Output is correct
10 Correct 48 ms 3372 KB Output is correct
11 Correct 46 ms 3216 KB Output is correct
12 Correct 41 ms 2984 KB Output is correct
13 Correct 41 ms 3060 KB Output is correct
14 Correct 40 ms 3168 KB Output is correct
15 Correct 44 ms 3152 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 16 ms 1236 KB Output is correct
20 Correct 35 ms 2132 KB Output is correct
21 Correct 51 ms 3120 KB Output is correct
22 Correct 53 ms 2996 KB Output is correct
23 Correct 47 ms 3012 KB Output is correct
24 Correct 49 ms 2900 KB Output is correct
25 Correct 47 ms 2900 KB Output is correct
26 Correct 53 ms 2944 KB Output is correct
27 Correct 62 ms 2944 KB Output is correct
28 Correct 53 ms 3192 KB Output is correct
29 Correct 50 ms 2892 KB Output is correct
30 Correct 53 ms 2992 KB Output is correct
31 Correct 0 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 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 6 ms 724 KB Output is correct
38 Correct 5 ms 724 KB Output is correct
39 Correct 11 ms 1108 KB Output is correct
40 Correct 24 ms 1952 KB Output is correct
41 Correct 38 ms 2636 KB Output is correct
42 Correct 42 ms 2644 KB Output is correct
43 Correct 40 ms 2644 KB Output is correct
44 Correct 40 ms 2728 KB Output is correct
45 Correct 41 ms 2644 KB Output is correct
46 Correct 41 ms 2840 KB Output is correct
47 Correct 39 ms 2636 KB Output is correct
48 Correct 41 ms 2716 KB Output is correct
49 Correct 37 ms 2708 KB Output is correct
50 Correct 40 ms 2724 KB Output is correct
51 Correct 44 ms 2708 KB Output is correct
52 Correct 45 ms 2644 KB Output is correct
53 Correct 41 ms 2688 KB Output is correct
54 Correct 43 ms 2732 KB Output is correct
55 Correct 43 ms 2700 KB Output is correct
56 Correct 40 ms 2692 KB Output is correct
57 Correct 36 ms 2724 KB Output is correct
58 Correct 37 ms 2712 KB Output is correct
59 Correct 43 ms 2636 KB Output is correct
60 Correct 41 ms 2644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 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 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 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 2 ms 432 KB Output is correct
14 Correct 15 ms 1328 KB Output is correct
15 Correct 26 ms 2444 KB Output is correct
16 Correct 50 ms 3068 KB Output is correct
17 Correct 36 ms 3928 KB Output is correct
18 Correct 41 ms 3020 KB Output is correct
19 Correct 43 ms 3148 KB Output is correct
20 Correct 48 ms 3372 KB Output is correct
21 Correct 46 ms 3216 KB Output is correct
22 Correct 41 ms 2984 KB Output is correct
23 Correct 41 ms 3060 KB Output is correct
24 Correct 40 ms 3168 KB Output is correct
25 Correct 44 ms 3152 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 16 ms 1236 KB Output is correct
30 Correct 35 ms 2132 KB Output is correct
31 Correct 51 ms 3120 KB Output is correct
32 Correct 53 ms 2996 KB Output is correct
33 Correct 47 ms 3012 KB Output is correct
34 Correct 49 ms 2900 KB Output is correct
35 Correct 47 ms 2900 KB Output is correct
36 Correct 53 ms 2944 KB Output is correct
37 Correct 62 ms 2944 KB Output is correct
38 Correct 53 ms 3192 KB Output is correct
39 Correct 50 ms 2892 KB Output is correct
40 Correct 53 ms 2992 KB Output is correct
41 Correct 0 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 340 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 6 ms 724 KB Output is correct
48 Correct 5 ms 724 KB Output is correct
49 Correct 11 ms 1108 KB Output is correct
50 Correct 24 ms 1952 KB Output is correct
51 Correct 38 ms 2636 KB Output is correct
52 Correct 42 ms 2644 KB Output is correct
53 Correct 40 ms 2644 KB Output is correct
54 Correct 40 ms 2728 KB Output is correct
55 Correct 41 ms 2644 KB Output is correct
56 Correct 41 ms 2840 KB Output is correct
57 Correct 39 ms 2636 KB Output is correct
58 Correct 41 ms 2716 KB Output is correct
59 Correct 37 ms 2708 KB Output is correct
60 Correct 40 ms 2724 KB Output is correct
61 Correct 44 ms 2708 KB Output is correct
62 Correct 45 ms 2644 KB Output is correct
63 Correct 41 ms 2688 KB Output is correct
64 Correct 43 ms 2732 KB Output is correct
65 Correct 43 ms 2700 KB Output is correct
66 Correct 40 ms 2692 KB Output is correct
67 Correct 36 ms 2724 KB Output is correct
68 Correct 37 ms 2712 KB Output is correct
69 Correct 43 ms 2636 KB Output is correct
70 Correct 41 ms 2644 KB Output is correct
71 Correct 5 ms 724 KB Output is correct
72 Correct 4 ms 724 KB Output is correct
73 Correct 4 ms 724 KB Output is correct
74 Correct 6 ms 724 KB Output is correct
75 Correct 5 ms 724 KB Output is correct
76 Correct 9 ms 1108 KB Output is correct
77 Correct 8 ms 1168 KB Output is correct
78 Correct 11 ms 1108 KB Output is correct
79 Correct 8 ms 1108 KB Output is correct
80 Correct 9 ms 1140 KB Output is correct
81 Correct 16 ms 1968 KB Output is correct
82 Correct 17 ms 1880 KB Output is correct
83 Correct 16 ms 1928 KB Output is correct
84 Correct 16 ms 1996 KB Output is correct
85 Correct 16 ms 2000 KB Output is correct
86 Correct 17 ms 2016 KB Output is correct
87 Correct 16 ms 2004 KB Output is correct
88 Correct 17 ms 2048 KB Output is correct
89 Correct 17 ms 2008 KB Output is correct
90 Correct 18 ms 2004 KB Output is correct
91 Correct 27 ms 3444 KB Output is correct
92 Correct 26 ms 3500 KB Output is correct
93 Correct 25 ms 3440 KB Output is correct
94 Correct 30 ms 3400 KB Output is correct
95 Correct 28 ms 3548 KB Output is correct
96 Correct 38 ms 4180 KB Output is correct
97 Correct 30 ms 4248 KB Output is correct
98 Correct 28 ms 4204 KB Output is correct
99 Correct 34 ms 4140 KB Output is correct
100 Correct 32 ms 4136 KB Output is correct
101 Correct 31 ms 4180 KB Output is correct
102 Correct 29 ms 4220 KB Output is correct
103 Correct 29 ms 4180 KB Output is correct
104 Correct 33 ms 4152 KB Output is correct
105 Correct 32 ms 4256 KB Output is correct
106 Correct 31 ms 4584 KB Output is correct
107 Correct 32 ms 4556 KB Output is correct
108 Correct 30 ms 4608 KB Output is correct
109 Correct 32 ms 4564 KB Output is correct
110 Correct 30 ms 4564 KB Output is correct
111 Correct 31 ms 4596 KB Output is correct
112 Correct 30 ms 4624 KB Output is correct
113 Correct 30 ms 4532 KB Output is correct
114 Correct 32 ms 4632 KB Output is correct
115 Correct 30 ms 4544 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 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 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 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 2 ms 432 KB Output is correct
14 Correct 15 ms 1328 KB Output is correct
15 Correct 26 ms 2444 KB Output is correct
16 Correct 50 ms 3068 KB Output is correct
17 Correct 36 ms 3928 KB Output is correct
18 Correct 41 ms 3020 KB Output is correct
19 Correct 43 ms 3148 KB Output is correct
20 Correct 48 ms 3372 KB Output is correct
21 Correct 46 ms 3216 KB Output is correct
22 Correct 41 ms 2984 KB Output is correct
23 Correct 41 ms 3060 KB Output is correct
24 Correct 40 ms 3168 KB Output is correct
25 Correct 44 ms 3152 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 16 ms 1236 KB Output is correct
30 Correct 35 ms 2132 KB Output is correct
31 Correct 51 ms 3120 KB Output is correct
32 Correct 53 ms 2996 KB Output is correct
33 Correct 47 ms 3012 KB Output is correct
34 Correct 49 ms 2900 KB Output is correct
35 Correct 47 ms 2900 KB Output is correct
36 Correct 53 ms 2944 KB Output is correct
37 Correct 62 ms 2944 KB Output is correct
38 Correct 53 ms 3192 KB Output is correct
39 Correct 50 ms 2892 KB Output is correct
40 Correct 53 ms 2992 KB Output is correct
41 Correct 0 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 340 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 6 ms 724 KB Output is correct
48 Correct 5 ms 724 KB Output is correct
49 Correct 11 ms 1108 KB Output is correct
50 Correct 24 ms 1952 KB Output is correct
51 Correct 38 ms 2636 KB Output is correct
52 Correct 42 ms 2644 KB Output is correct
53 Correct 40 ms 2644 KB Output is correct
54 Correct 40 ms 2728 KB Output is correct
55 Correct 41 ms 2644 KB Output is correct
56 Correct 41 ms 2840 KB Output is correct
57 Correct 39 ms 2636 KB Output is correct
58 Correct 41 ms 2716 KB Output is correct
59 Correct 37 ms 2708 KB Output is correct
60 Correct 40 ms 2724 KB Output is correct
61 Correct 44 ms 2708 KB Output is correct
62 Correct 45 ms 2644 KB Output is correct
63 Correct 41 ms 2688 KB Output is correct
64 Correct 43 ms 2732 KB Output is correct
65 Correct 43 ms 2700 KB Output is correct
66 Correct 40 ms 2692 KB Output is correct
67 Correct 36 ms 2724 KB Output is correct
68 Correct 37 ms 2712 KB Output is correct
69 Correct 43 ms 2636 KB Output is correct
70 Correct 41 ms 2644 KB Output is correct
71 Correct 5 ms 724 KB Output is correct
72 Correct 4 ms 724 KB Output is correct
73 Correct 4 ms 724 KB Output is correct
74 Correct 6 ms 724 KB Output is correct
75 Correct 5 ms 724 KB Output is correct
76 Correct 9 ms 1108 KB Output is correct
77 Correct 8 ms 1168 KB Output is correct
78 Correct 11 ms 1108 KB Output is correct
79 Correct 8 ms 1108 KB Output is correct
80 Correct 9 ms 1140 KB Output is correct
81 Correct 16 ms 1968 KB Output is correct
82 Correct 17 ms 1880 KB Output is correct
83 Correct 16 ms 1928 KB Output is correct
84 Correct 16 ms 1996 KB Output is correct
85 Correct 16 ms 2000 KB Output is correct
86 Correct 17 ms 2016 KB Output is correct
87 Correct 16 ms 2004 KB Output is correct
88 Correct 17 ms 2048 KB Output is correct
89 Correct 17 ms 2008 KB Output is correct
90 Correct 18 ms 2004 KB Output is correct
91 Correct 27 ms 3444 KB Output is correct
92 Correct 26 ms 3500 KB Output is correct
93 Correct 25 ms 3440 KB Output is correct
94 Correct 30 ms 3400 KB Output is correct
95 Correct 28 ms 3548 KB Output is correct
96 Correct 38 ms 4180 KB Output is correct
97 Correct 30 ms 4248 KB Output is correct
98 Correct 28 ms 4204 KB Output is correct
99 Correct 34 ms 4140 KB Output is correct
100 Correct 32 ms 4136 KB Output is correct
101 Correct 31 ms 4180 KB Output is correct
102 Correct 29 ms 4220 KB Output is correct
103 Correct 29 ms 4180 KB Output is correct
104 Correct 33 ms 4152 KB Output is correct
105 Correct 32 ms 4256 KB Output is correct
106 Correct 31 ms 4584 KB Output is correct
107 Correct 32 ms 4556 KB Output is correct
108 Correct 30 ms 4608 KB Output is correct
109 Correct 32 ms 4564 KB Output is correct
110 Correct 30 ms 4564 KB Output is correct
111 Correct 31 ms 4596 KB Output is correct
112 Correct 30 ms 4624 KB Output is correct
113 Correct 30 ms 4532 KB Output is correct
114 Correct 32 ms 4632 KB Output is correct
115 Correct 30 ms 4544 KB Output is correct
116 Correct 981 ms 1784 KB Output is correct
117 Correct 731 ms 1784 KB Output is correct
118 Correct 1432 ms 2244 KB Output is correct
119 Correct 578 ms 2344 KB Output is correct
120 Correct 347 ms 2240 KB Output is correct
121 Correct 745 ms 2632 KB Output is correct
122 Correct 433 ms 2656 KB Output is correct
123 Correct 2426 ms 3556 KB Output is correct
124 Correct 708 ms 3572 KB Output is correct
125 Correct 526 ms 3612 KB Output is correct
126 Execution timed out 7030 ms 3692 KB Time limit exceeded
127 Halted 0 ms 0 KB -