답안 #832090

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
832090 2023-08-20T22:17:14 Z QwertyPi Diversity (CEOI21_diversity) C++14
64 / 100
257 ms 22344 KB
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define int long long
using namespace std;

const int MAXN = 3e5 + 11;
const int MAXQ = 5e4 + 11;
const int SQ = 1000;
int a[MAXN];
int ans[MAXQ];
int c[MAXN];

int s0, s1, s2;
void add(int x){
    s0 -= c[x] * (c[x] + 1) / 2;
    s1 -= c[x];
    s2 -= c[x] * c[x];
    c[x]++;
    s0 += c[x] * (c[x] + 1) / 2;
    s1 += c[x];
    s2 += c[x] * c[x];
}

void rem(int x){
    s0 -= c[x] * (c[x] + 1) / 2;
    s1 -= c[x];
    s2 -= c[x] * c[x];
    c[x]--;
    s0 += c[x] * (c[x] + 1) / 2;
    s1 += c[x];
    s2 += c[x] * c[x];
}

struct query{
    int l, r, id;
};

int32_t main(){
    int n, q; cin >> n >> q;
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }

    vector<query> Q;
    for(int i = 0; i < q; i++){
        int l, r; cin >> l >> r; --l; --r; Q.push_back({l, r, i});
    }
    sort(Q.begin(), Q.end(), [](query a, query b){
        if(a.l / SQ != b.l / SQ) return a.l / SQ < b.l / SQ;
        return a.l / SQ % 2 ? a.r > b.r : a.r < b.r;
    });

    map<int, int> c;
    for(int i = 0; i < n; i++){
        c[a[i]]++;
    }

    vector<int> cnt;
    for(auto [x, y] : c){
        cnt.push_back(y);
    }

    sort(cnt.begin(), cnt.end());

    int l = 0, r = 0;
    while(r < n) add(a[r++]);

    int ans = s0 + (s1 * s1 - s2) / 2;

    int cl = 0, cr = 0;
    for(auto x : cnt){
        if(cl > cr) swap(cl, cr);
        ans += cl * (n - cl); cl += x;
    }
    ans += cl * (n - cl);
    cout << ans << endl;
}

Compilation message

diversity.cpp: In function 'int32_t main()':
diversity.cpp:59:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   59 |     for(auto [x, y] : c){
      |              ^
diversity.cpp:65:9: warning: unused variable 'l' [-Wunused-variable]
   65 |     int l = 0, r = 0;
      |         ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 14 ms 1052 KB Output is correct
5 Correct 24 ms 1828 KB Output is correct
6 Correct 46 ms 2552 KB Output is correct
7 Correct 37 ms 2632 KB Output is correct
8 Correct 40 ms 2628 KB Output is correct
9 Correct 39 ms 2508 KB Output is correct
10 Correct 39 ms 2556 KB Output is correct
11 Correct 44 ms 2624 KB Output is correct
12 Correct 45 ms 2596 KB Output is correct
13 Correct 39 ms 2600 KB Output is correct
14 Correct 39 ms 2576 KB Output is correct
15 Correct 39 ms 2540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 14 ms 1052 KB Output is correct
5 Correct 24 ms 1828 KB Output is correct
6 Correct 46 ms 2552 KB Output is correct
7 Correct 37 ms 2632 KB Output is correct
8 Correct 40 ms 2628 KB Output is correct
9 Correct 39 ms 2508 KB Output is correct
10 Correct 39 ms 2556 KB Output is correct
11 Correct 44 ms 2624 KB Output is correct
12 Correct 45 ms 2596 KB Output is correct
13 Correct 39 ms 2600 KB Output is correct
14 Correct 39 ms 2576 KB Output is correct
15 Correct 39 ms 2540 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Correct 17 ms 1024 KB Output is correct
20 Correct 31 ms 1784 KB Output is correct
21 Correct 44 ms 2580 KB Output is correct
22 Correct 57 ms 2616 KB Output is correct
23 Correct 46 ms 2632 KB Output is correct
24 Correct 44 ms 2636 KB Output is correct
25 Correct 49 ms 2544 KB Output is correct
26 Correct 57 ms 2584 KB Output is correct
27 Correct 43 ms 2592 KB Output is correct
28 Correct 46 ms 2644 KB Output is correct
29 Correct 42 ms 2580 KB Output is correct
30 Correct 47 ms 2632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 14 ms 1052 KB Output is correct
5 Correct 24 ms 1828 KB Output is correct
6 Correct 46 ms 2552 KB Output is correct
7 Correct 37 ms 2632 KB Output is correct
8 Correct 40 ms 2628 KB Output is correct
9 Correct 39 ms 2508 KB Output is correct
10 Correct 39 ms 2556 KB Output is correct
11 Correct 44 ms 2624 KB Output is correct
12 Correct 45 ms 2596 KB Output is correct
13 Correct 39 ms 2600 KB Output is correct
14 Correct 39 ms 2576 KB Output is correct
15 Correct 39 ms 2540 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Correct 17 ms 1024 KB Output is correct
20 Correct 31 ms 1784 KB Output is correct
21 Correct 44 ms 2580 KB Output is correct
22 Correct 57 ms 2616 KB Output is correct
23 Correct 46 ms 2632 KB Output is correct
24 Correct 44 ms 2636 KB Output is correct
25 Correct 49 ms 2544 KB Output is correct
26 Correct 57 ms 2584 KB Output is correct
27 Correct 43 ms 2592 KB Output is correct
28 Correct 46 ms 2644 KB Output is correct
29 Correct 42 ms 2580 KB Output is correct
30 Correct 47 ms 2632 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 340 KB Output is correct
34 Correct 2 ms 340 KB Output is correct
35 Correct 3 ms 340 KB Output is correct
36 Correct 3 ms 468 KB Output is correct
37 Correct 10 ms 712 KB Output is correct
38 Correct 13 ms 724 KB Output is correct
39 Correct 24 ms 1148 KB Output is correct
40 Correct 40 ms 1940 KB Output is correct
41 Correct 60 ms 2652 KB Output is correct
42 Correct 60 ms 2652 KB Output is correct
43 Correct 60 ms 2608 KB Output is correct
44 Correct 59 ms 2636 KB Output is correct
45 Correct 60 ms 2636 KB Output is correct
46 Correct 59 ms 2608 KB Output is correct
47 Correct 65 ms 2668 KB Output is correct
48 Correct 59 ms 2636 KB Output is correct
49 Correct 60 ms 2692 KB Output is correct
50 Correct 59 ms 2696 KB Output is correct
51 Correct 61 ms 2620 KB Output is correct
52 Correct 59 ms 2616 KB Output is correct
53 Correct 61 ms 2660 KB Output is correct
54 Correct 59 ms 2700 KB Output is correct
55 Correct 60 ms 2692 KB Output is correct
56 Correct 73 ms 2696 KB Output is correct
57 Correct 87 ms 2640 KB Output is correct
58 Correct 61 ms 2684 KB Output is correct
59 Correct 61 ms 2628 KB Output is correct
60 Correct 59 ms 2680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
14 Correct 14 ms 1052 KB Output is correct
15 Correct 24 ms 1828 KB Output is correct
16 Correct 46 ms 2552 KB Output is correct
17 Correct 37 ms 2632 KB Output is correct
18 Correct 40 ms 2628 KB Output is correct
19 Correct 39 ms 2508 KB Output is correct
20 Correct 39 ms 2556 KB Output is correct
21 Correct 44 ms 2624 KB Output is correct
22 Correct 45 ms 2596 KB Output is correct
23 Correct 39 ms 2600 KB Output is correct
24 Correct 39 ms 2576 KB Output is correct
25 Correct 39 ms 2540 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 2 ms 340 KB Output is correct
29 Correct 17 ms 1024 KB Output is correct
30 Correct 31 ms 1784 KB Output is correct
31 Correct 44 ms 2580 KB Output is correct
32 Correct 57 ms 2616 KB Output is correct
33 Correct 46 ms 2632 KB Output is correct
34 Correct 44 ms 2636 KB Output is correct
35 Correct 49 ms 2544 KB Output is correct
36 Correct 57 ms 2584 KB Output is correct
37 Correct 43 ms 2592 KB Output is correct
38 Correct 46 ms 2644 KB Output is correct
39 Correct 42 ms 2580 KB Output is correct
40 Correct 47 ms 2632 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 0 ms 340 KB Output is correct
44 Correct 2 ms 340 KB Output is correct
45 Correct 3 ms 340 KB Output is correct
46 Correct 3 ms 468 KB Output is correct
47 Correct 10 ms 712 KB Output is correct
48 Correct 13 ms 724 KB Output is correct
49 Correct 24 ms 1148 KB Output is correct
50 Correct 40 ms 1940 KB Output is correct
51 Correct 60 ms 2652 KB Output is correct
52 Correct 60 ms 2652 KB Output is correct
53 Correct 60 ms 2608 KB Output is correct
54 Correct 59 ms 2636 KB Output is correct
55 Correct 60 ms 2636 KB Output is correct
56 Correct 59 ms 2608 KB Output is correct
57 Correct 65 ms 2668 KB Output is correct
58 Correct 59 ms 2636 KB Output is correct
59 Correct 60 ms 2692 KB Output is correct
60 Correct 59 ms 2696 KB Output is correct
61 Correct 61 ms 2620 KB Output is correct
62 Correct 59 ms 2616 KB Output is correct
63 Correct 61 ms 2660 KB Output is correct
64 Correct 59 ms 2700 KB Output is correct
65 Correct 60 ms 2692 KB Output is correct
66 Correct 73 ms 2696 KB Output is correct
67 Correct 87 ms 2640 KB Output is correct
68 Correct 61 ms 2684 KB Output is correct
69 Correct 61 ms 2628 KB Output is correct
70 Correct 59 ms 2680 KB Output is correct
71 Correct 12 ms 852 KB Output is correct
72 Correct 14 ms 852 KB Output is correct
73 Correct 11 ms 852 KB Output is correct
74 Correct 17 ms 852 KB Output is correct
75 Correct 12 ms 852 KB Output is correct
76 Correct 25 ms 1464 KB Output is correct
77 Correct 25 ms 1528 KB Output is correct
78 Correct 26 ms 1492 KB Output is correct
79 Correct 25 ms 1524 KB Output is correct
80 Correct 25 ms 1528 KB Output is correct
81 Correct 55 ms 2736 KB Output is correct
82 Correct 55 ms 2740 KB Output is correct
83 Correct 54 ms 2760 KB Output is correct
84 Correct 54 ms 2732 KB Output is correct
85 Correct 79 ms 2696 KB Output is correct
86 Correct 87 ms 3508 KB Output is correct
87 Correct 62 ms 3456 KB Output is correct
88 Correct 67 ms 3536 KB Output is correct
89 Correct 65 ms 3524 KB Output is correct
90 Correct 62 ms 3532 KB Output is correct
91 Correct 123 ms 10532 KB Output is correct
92 Correct 143 ms 10524 KB Output is correct
93 Correct 161 ms 10512 KB Output is correct
94 Correct 137 ms 10528 KB Output is correct
95 Correct 124 ms 10560 KB Output is correct
96 Correct 173 ms 18408 KB Output is correct
97 Correct 167 ms 18360 KB Output is correct
98 Correct 174 ms 18432 KB Output is correct
99 Correct 165 ms 18424 KB Output is correct
100 Correct 164 ms 18344 KB Output is correct
101 Correct 163 ms 18376 KB Output is correct
102 Correct 174 ms 18428 KB Output is correct
103 Correct 190 ms 18364 KB Output is correct
104 Correct 160 ms 18348 KB Output is correct
105 Correct 195 ms 18348 KB Output is correct
106 Correct 192 ms 22256 KB Output is correct
107 Correct 257 ms 22268 KB Output is correct
108 Correct 202 ms 22336 KB Output is correct
109 Correct 207 ms 22328 KB Output is correct
110 Correct 193 ms 22304 KB Output is correct
111 Correct 213 ms 22300 KB Output is correct
112 Correct 187 ms 22292 KB Output is correct
113 Correct 229 ms 22320 KB Output is correct
114 Correct 189 ms 22344 KB Output is correct
115 Correct 189 ms 22240 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
14 Correct 14 ms 1052 KB Output is correct
15 Correct 24 ms 1828 KB Output is correct
16 Correct 46 ms 2552 KB Output is correct
17 Correct 37 ms 2632 KB Output is correct
18 Correct 40 ms 2628 KB Output is correct
19 Correct 39 ms 2508 KB Output is correct
20 Correct 39 ms 2556 KB Output is correct
21 Correct 44 ms 2624 KB Output is correct
22 Correct 45 ms 2596 KB Output is correct
23 Correct 39 ms 2600 KB Output is correct
24 Correct 39 ms 2576 KB Output is correct
25 Correct 39 ms 2540 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 2 ms 340 KB Output is correct
29 Correct 17 ms 1024 KB Output is correct
30 Correct 31 ms 1784 KB Output is correct
31 Correct 44 ms 2580 KB Output is correct
32 Correct 57 ms 2616 KB Output is correct
33 Correct 46 ms 2632 KB Output is correct
34 Correct 44 ms 2636 KB Output is correct
35 Correct 49 ms 2544 KB Output is correct
36 Correct 57 ms 2584 KB Output is correct
37 Correct 43 ms 2592 KB Output is correct
38 Correct 46 ms 2644 KB Output is correct
39 Correct 42 ms 2580 KB Output is correct
40 Correct 47 ms 2632 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 0 ms 340 KB Output is correct
44 Correct 2 ms 340 KB Output is correct
45 Correct 3 ms 340 KB Output is correct
46 Correct 3 ms 468 KB Output is correct
47 Correct 10 ms 712 KB Output is correct
48 Correct 13 ms 724 KB Output is correct
49 Correct 24 ms 1148 KB Output is correct
50 Correct 40 ms 1940 KB Output is correct
51 Correct 60 ms 2652 KB Output is correct
52 Correct 60 ms 2652 KB Output is correct
53 Correct 60 ms 2608 KB Output is correct
54 Correct 59 ms 2636 KB Output is correct
55 Correct 60 ms 2636 KB Output is correct
56 Correct 59 ms 2608 KB Output is correct
57 Correct 65 ms 2668 KB Output is correct
58 Correct 59 ms 2636 KB Output is correct
59 Correct 60 ms 2692 KB Output is correct
60 Correct 59 ms 2696 KB Output is correct
61 Correct 61 ms 2620 KB Output is correct
62 Correct 59 ms 2616 KB Output is correct
63 Correct 61 ms 2660 KB Output is correct
64 Correct 59 ms 2700 KB Output is correct
65 Correct 60 ms 2692 KB Output is correct
66 Correct 73 ms 2696 KB Output is correct
67 Correct 87 ms 2640 KB Output is correct
68 Correct 61 ms 2684 KB Output is correct
69 Correct 61 ms 2628 KB Output is correct
70 Correct 59 ms 2680 KB Output is correct
71 Correct 12 ms 852 KB Output is correct
72 Correct 14 ms 852 KB Output is correct
73 Correct 11 ms 852 KB Output is correct
74 Correct 17 ms 852 KB Output is correct
75 Correct 12 ms 852 KB Output is correct
76 Correct 25 ms 1464 KB Output is correct
77 Correct 25 ms 1528 KB Output is correct
78 Correct 26 ms 1492 KB Output is correct
79 Correct 25 ms 1524 KB Output is correct
80 Correct 25 ms 1528 KB Output is correct
81 Correct 55 ms 2736 KB Output is correct
82 Correct 55 ms 2740 KB Output is correct
83 Correct 54 ms 2760 KB Output is correct
84 Correct 54 ms 2732 KB Output is correct
85 Correct 79 ms 2696 KB Output is correct
86 Correct 87 ms 3508 KB Output is correct
87 Correct 62 ms 3456 KB Output is correct
88 Correct 67 ms 3536 KB Output is correct
89 Correct 65 ms 3524 KB Output is correct
90 Correct 62 ms 3532 KB Output is correct
91 Correct 123 ms 10532 KB Output is correct
92 Correct 143 ms 10524 KB Output is correct
93 Correct 161 ms 10512 KB Output is correct
94 Correct 137 ms 10528 KB Output is correct
95 Correct 124 ms 10560 KB Output is correct
96 Correct 173 ms 18408 KB Output is correct
97 Correct 167 ms 18360 KB Output is correct
98 Correct 174 ms 18432 KB Output is correct
99 Correct 165 ms 18424 KB Output is correct
100 Correct 164 ms 18344 KB Output is correct
101 Correct 163 ms 18376 KB Output is correct
102 Correct 174 ms 18428 KB Output is correct
103 Correct 190 ms 18364 KB Output is correct
104 Correct 160 ms 18348 KB Output is correct
105 Correct 195 ms 18348 KB Output is correct
106 Correct 192 ms 22256 KB Output is correct
107 Correct 257 ms 22268 KB Output is correct
108 Correct 202 ms 22336 KB Output is correct
109 Correct 207 ms 22328 KB Output is correct
110 Correct 193 ms 22304 KB Output is correct
111 Correct 213 ms 22300 KB Output is correct
112 Correct 187 ms 22292 KB Output is correct
113 Correct 229 ms 22320 KB Output is correct
114 Correct 189 ms 22344 KB Output is correct
115 Correct 189 ms 22240 KB Output is correct
116 Incorrect 24 ms 2380 KB Output isn't correct
117 Halted 0 ms 0 KB -