답안 #995596

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
995596 2024-06-09T12:34:05 Z asdasdqwer Diversity (CEOI21_diversity) C++14
64 / 100
244 ms 46160 KB
#include <bits/stdc++.h>
using namespace std;

#define int int64_t
#define pii array<int,2>

struct Segtree {
    vector<int> seg, lz;
    int n;
    Segtree(int sz) {
        n=1;
        while (n<sz)n*=2;
        seg.assign(2*n,0);
        lz.assign(2*n,0);
    }

    void pushdown(int x, int l) {
        if (lz[x] == 0) return;
        lz[2*x+1] += lz[x];
        lz[2*x+2] += lz[x];
        seg[2*x+1] += (l/2) * lz[x];
        seg[2*x+2] += (l/2) * lz[x];
        lz[x]=0;
    }

    void inc(int l, int r, int v, int x, int lx, int rx) {
        if (lx >= r || rx <= l) return;
        if (lx >= l && rx <= r) {
            seg[x] += (rx-lx) * v;
            lz[x] += v;
            return;
        }

        pushdown(x, rx-lx);

        int m=(lx+rx)/2;
        inc(l, r, v, 2*x+1, lx, m);
        inc(l, r, v, 2*x+2, m, rx);
        seg[x] = seg[2*x+1] + seg[2*x+2];
    }

    void inc(int l, int r, int v) {
        inc(l, r, v, 0, 0, n);
    }

    int get(int l, int r, int x, int lx, int rx) {
        if (lx >= r || rx <= l) return 0;
        if (lx >= l && rx <= r) {
            return seg[x];
        }

        pushdown(x, rx-lx);

        int m=(lx+rx)/2;
        return get(l, r, 2*x+1, lx, m) + get(l, r, 2*x+2, m, rx);
    }

    int get(int l, int r) {
        return get(l, r, 0, 0, n);
    }
};

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n,q;cin>>n>>q;
    vector<int> a(n);
    for (int &x:a)cin>>x;
    sort(a.begin(), a.end());

    vector<int> b = a;
    b.erase(unique(b.begin(), b.end()), b.end());

    // coordinate compression
    map<int,int> mp;
    for (int i=0;i<(int)b.size();i++) {
        mp[b[i]]=i;
    }

    for (int &x:a) {
        x = mp[x];
    }

    vector<int> cnt(b.size());

    for (int i=0;i<n;i++) {
        cnt[a[i]]++;
    }

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

    vector<int> newarr(n);
    deque<int> idx;
    for (int i=0;i<n;i++) idx.push_back(i);

    for (int i=0;i<(int)cnt.size();i++) {
        if (i % 2 == 0) {
            for (int j=0;j<cnt[i];j++) {
                int id = idx.back();idx.pop_back();
                newarr[id] = i;
            }
        }

        else {
            for (int j=0;j<cnt[i];j++) {
                int id = idx.front();idx.pop_front();
                newarr[id] = i;
            }
        }
    }

    int res = n;
    Segtree sg(n);
    for (int i=0;i<n;i++) {
        if (i != 0 && newarr[i] != newarr[i-1]) {
            sg.inc(0, i, 1);
        }

        res += sg.seg[0];
        sg.inc(i, i+1, 1);
    }

    cout<<res<<"\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 456 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 3 ms 1116 KB Output is correct
4 Correct 28 ms 7776 KB Output is correct
5 Correct 50 ms 15232 KB Output is correct
6 Correct 83 ms 26964 KB Output is correct
7 Correct 79 ms 26956 KB Output is correct
8 Correct 76 ms 26964 KB Output is correct
9 Correct 86 ms 27216 KB Output is correct
10 Correct 80 ms 26968 KB Output is correct
11 Correct 79 ms 26960 KB Output is correct
12 Correct 78 ms 26964 KB Output is correct
13 Correct 102 ms 26956 KB Output is correct
14 Correct 79 ms 26968 KB Output is correct
15 Correct 77 ms 27024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 3 ms 1116 KB Output is correct
4 Correct 28 ms 7776 KB Output is correct
5 Correct 50 ms 15232 KB Output is correct
6 Correct 83 ms 26964 KB Output is correct
7 Correct 79 ms 26956 KB Output is correct
8 Correct 76 ms 26964 KB Output is correct
9 Correct 86 ms 27216 KB Output is correct
10 Correct 80 ms 26968 KB Output is correct
11 Correct 79 ms 26960 KB Output is correct
12 Correct 78 ms 26964 KB Output is correct
13 Correct 102 ms 26956 KB Output is correct
14 Correct 79 ms 26968 KB Output is correct
15 Correct 77 ms 27024 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 3 ms 1116 KB Output is correct
19 Correct 25 ms 7924 KB Output is correct
20 Correct 50 ms 15360 KB Output is correct
21 Correct 82 ms 27168 KB Output is correct
22 Correct 79 ms 26960 KB Output is correct
23 Correct 79 ms 26972 KB Output is correct
24 Correct 81 ms 26932 KB Output is correct
25 Correct 81 ms 26920 KB Output is correct
26 Correct 81 ms 26960 KB Output is correct
27 Correct 79 ms 26960 KB Output is correct
28 Correct 76 ms 26972 KB Output is correct
29 Correct 103 ms 26984 KB Output is correct
30 Correct 88 ms 26992 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 3 ms 1116 KB Output is correct
4 Correct 28 ms 7776 KB Output is correct
5 Correct 50 ms 15232 KB Output is correct
6 Correct 83 ms 26964 KB Output is correct
7 Correct 79 ms 26956 KB Output is correct
8 Correct 76 ms 26964 KB Output is correct
9 Correct 86 ms 27216 KB Output is correct
10 Correct 80 ms 26968 KB Output is correct
11 Correct 79 ms 26960 KB Output is correct
12 Correct 78 ms 26964 KB Output is correct
13 Correct 102 ms 26956 KB Output is correct
14 Correct 79 ms 26968 KB Output is correct
15 Correct 77 ms 27024 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 3 ms 1116 KB Output is correct
19 Correct 25 ms 7924 KB Output is correct
20 Correct 50 ms 15360 KB Output is correct
21 Correct 82 ms 27168 KB Output is correct
22 Correct 79 ms 26960 KB Output is correct
23 Correct 79 ms 26972 KB Output is correct
24 Correct 81 ms 26932 KB Output is correct
25 Correct 81 ms 26920 KB Output is correct
26 Correct 81 ms 26960 KB Output is correct
27 Correct 79 ms 26960 KB Output is correct
28 Correct 76 ms 26972 KB Output is correct
29 Correct 103 ms 26984 KB Output is correct
30 Correct 88 ms 26992 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 3 ms 1116 KB Output is correct
35 Correct 3 ms 1116 KB Output is correct
36 Correct 4 ms 1348 KB Output is correct
37 Correct 14 ms 4344 KB Output is correct
38 Correct 16 ms 4184 KB Output is correct
39 Correct 31 ms 8024 KB Output is correct
40 Correct 57 ms 15708 KB Output is correct
41 Correct 90 ms 27472 KB Output is correct
42 Correct 120 ms 27472 KB Output is correct
43 Correct 117 ms 27472 KB Output is correct
44 Correct 92 ms 27472 KB Output is correct
45 Correct 93 ms 27604 KB Output is correct
46 Correct 111 ms 27496 KB Output is correct
47 Correct 95 ms 27508 KB Output is correct
48 Correct 95 ms 27496 KB Output is correct
49 Correct 113 ms 27604 KB Output is correct
50 Correct 104 ms 27508 KB Output is correct
51 Correct 102 ms 27476 KB Output is correct
52 Correct 93 ms 27476 KB Output is correct
53 Correct 101 ms 27600 KB Output is correct
54 Correct 92 ms 27512 KB Output is correct
55 Correct 105 ms 27492 KB Output is correct
56 Correct 92 ms 27472 KB Output is correct
57 Correct 101 ms 27500 KB Output is correct
58 Correct 96 ms 27504 KB Output is correct
59 Correct 100 ms 27616 KB Output is correct
60 Correct 103 ms 27496 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 456 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 3 ms 1116 KB Output is correct
14 Correct 28 ms 7776 KB Output is correct
15 Correct 50 ms 15232 KB Output is correct
16 Correct 83 ms 26964 KB Output is correct
17 Correct 79 ms 26956 KB Output is correct
18 Correct 76 ms 26964 KB Output is correct
19 Correct 86 ms 27216 KB Output is correct
20 Correct 80 ms 26968 KB Output is correct
21 Correct 79 ms 26960 KB Output is correct
22 Correct 78 ms 26964 KB Output is correct
23 Correct 102 ms 26956 KB Output is correct
24 Correct 79 ms 26968 KB Output is correct
25 Correct 77 ms 27024 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 3 ms 1116 KB Output is correct
29 Correct 25 ms 7924 KB Output is correct
30 Correct 50 ms 15360 KB Output is correct
31 Correct 82 ms 27168 KB Output is correct
32 Correct 79 ms 26960 KB Output is correct
33 Correct 79 ms 26972 KB Output is correct
34 Correct 81 ms 26932 KB Output is correct
35 Correct 81 ms 26920 KB Output is correct
36 Correct 81 ms 26960 KB Output is correct
37 Correct 79 ms 26960 KB Output is correct
38 Correct 76 ms 26972 KB Output is correct
39 Correct 103 ms 26984 KB Output is correct
40 Correct 88 ms 26992 KB Output is correct
41 Correct 1 ms 344 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 3 ms 1116 KB Output is correct
45 Correct 3 ms 1116 KB Output is correct
46 Correct 4 ms 1348 KB Output is correct
47 Correct 14 ms 4344 KB Output is correct
48 Correct 16 ms 4184 KB Output is correct
49 Correct 31 ms 8024 KB Output is correct
50 Correct 57 ms 15708 KB Output is correct
51 Correct 90 ms 27472 KB Output is correct
52 Correct 120 ms 27472 KB Output is correct
53 Correct 117 ms 27472 KB Output is correct
54 Correct 92 ms 27472 KB Output is correct
55 Correct 93 ms 27604 KB Output is correct
56 Correct 111 ms 27496 KB Output is correct
57 Correct 95 ms 27508 KB Output is correct
58 Correct 95 ms 27496 KB Output is correct
59 Correct 113 ms 27604 KB Output is correct
60 Correct 104 ms 27508 KB Output is correct
61 Correct 102 ms 27476 KB Output is correct
62 Correct 93 ms 27476 KB Output is correct
63 Correct 101 ms 27600 KB Output is correct
64 Correct 92 ms 27512 KB Output is correct
65 Correct 105 ms 27492 KB Output is correct
66 Correct 92 ms 27472 KB Output is correct
67 Correct 101 ms 27500 KB Output is correct
68 Correct 96 ms 27504 KB Output is correct
69 Correct 100 ms 27616 KB Output is correct
70 Correct 103 ms 27496 KB Output is correct
71 Correct 20 ms 4440 KB Output is correct
72 Correct 16 ms 4384 KB Output is correct
73 Correct 20 ms 4492 KB Output is correct
74 Correct 16 ms 4484 KB Output is correct
75 Correct 17 ms 4488 KB Output is correct
76 Correct 33 ms 8536 KB Output is correct
77 Correct 51 ms 8356 KB Output is correct
78 Correct 41 ms 8536 KB Output is correct
79 Correct 39 ms 8540 KB Output is correct
80 Correct 38 ms 8540 KB Output is correct
81 Correct 88 ms 16664 KB Output is correct
82 Correct 94 ms 16668 KB Output is correct
83 Correct 71 ms 16548 KB Output is correct
84 Correct 66 ms 16604 KB Output is correct
85 Correct 69 ms 16428 KB Output is correct
86 Correct 78 ms 17420 KB Output is correct
87 Correct 75 ms 17492 KB Output is correct
88 Correct 78 ms 17488 KB Output is correct
89 Correct 75 ms 17488 KB Output is correct
90 Correct 76 ms 17236 KB Output is correct
91 Correct 179 ms 35156 KB Output is correct
92 Correct 161 ms 35012 KB Output is correct
93 Correct 153 ms 35152 KB Output is correct
94 Correct 163 ms 35156 KB Output is correct
95 Correct 159 ms 35244 KB Output is correct
96 Correct 204 ms 42320 KB Output is correct
97 Correct 213 ms 42312 KB Output is correct
98 Correct 213 ms 42316 KB Output is correct
99 Correct 201 ms 42320 KB Output is correct
100 Correct 202 ms 42340 KB Output is correct
101 Correct 216 ms 42332 KB Output is correct
102 Correct 198 ms 42320 KB Output is correct
103 Correct 214 ms 42340 KB Output is correct
104 Correct 206 ms 42328 KB Output is correct
105 Correct 201 ms 42320 KB Output is correct
106 Correct 218 ms 45904 KB Output is correct
107 Correct 229 ms 45680 KB Output is correct
108 Correct 244 ms 45904 KB Output is correct
109 Correct 213 ms 45904 KB Output is correct
110 Correct 223 ms 45904 KB Output is correct
111 Correct 222 ms 45908 KB Output is correct
112 Correct 225 ms 46160 KB Output is correct
113 Correct 225 ms 45908 KB Output is correct
114 Correct 218 ms 45904 KB Output is correct
115 Correct 243 ms 45680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 456 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 3 ms 1116 KB Output is correct
14 Correct 28 ms 7776 KB Output is correct
15 Correct 50 ms 15232 KB Output is correct
16 Correct 83 ms 26964 KB Output is correct
17 Correct 79 ms 26956 KB Output is correct
18 Correct 76 ms 26964 KB Output is correct
19 Correct 86 ms 27216 KB Output is correct
20 Correct 80 ms 26968 KB Output is correct
21 Correct 79 ms 26960 KB Output is correct
22 Correct 78 ms 26964 KB Output is correct
23 Correct 102 ms 26956 KB Output is correct
24 Correct 79 ms 26968 KB Output is correct
25 Correct 77 ms 27024 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 3 ms 1116 KB Output is correct
29 Correct 25 ms 7924 KB Output is correct
30 Correct 50 ms 15360 KB Output is correct
31 Correct 82 ms 27168 KB Output is correct
32 Correct 79 ms 26960 KB Output is correct
33 Correct 79 ms 26972 KB Output is correct
34 Correct 81 ms 26932 KB Output is correct
35 Correct 81 ms 26920 KB Output is correct
36 Correct 81 ms 26960 KB Output is correct
37 Correct 79 ms 26960 KB Output is correct
38 Correct 76 ms 26972 KB Output is correct
39 Correct 103 ms 26984 KB Output is correct
40 Correct 88 ms 26992 KB Output is correct
41 Correct 1 ms 344 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 3 ms 1116 KB Output is correct
45 Correct 3 ms 1116 KB Output is correct
46 Correct 4 ms 1348 KB Output is correct
47 Correct 14 ms 4344 KB Output is correct
48 Correct 16 ms 4184 KB Output is correct
49 Correct 31 ms 8024 KB Output is correct
50 Correct 57 ms 15708 KB Output is correct
51 Correct 90 ms 27472 KB Output is correct
52 Correct 120 ms 27472 KB Output is correct
53 Correct 117 ms 27472 KB Output is correct
54 Correct 92 ms 27472 KB Output is correct
55 Correct 93 ms 27604 KB Output is correct
56 Correct 111 ms 27496 KB Output is correct
57 Correct 95 ms 27508 KB Output is correct
58 Correct 95 ms 27496 KB Output is correct
59 Correct 113 ms 27604 KB Output is correct
60 Correct 104 ms 27508 KB Output is correct
61 Correct 102 ms 27476 KB Output is correct
62 Correct 93 ms 27476 KB Output is correct
63 Correct 101 ms 27600 KB Output is correct
64 Correct 92 ms 27512 KB Output is correct
65 Correct 105 ms 27492 KB Output is correct
66 Correct 92 ms 27472 KB Output is correct
67 Correct 101 ms 27500 KB Output is correct
68 Correct 96 ms 27504 KB Output is correct
69 Correct 100 ms 27616 KB Output is correct
70 Correct 103 ms 27496 KB Output is correct
71 Correct 20 ms 4440 KB Output is correct
72 Correct 16 ms 4384 KB Output is correct
73 Correct 20 ms 4492 KB Output is correct
74 Correct 16 ms 4484 KB Output is correct
75 Correct 17 ms 4488 KB Output is correct
76 Correct 33 ms 8536 KB Output is correct
77 Correct 51 ms 8356 KB Output is correct
78 Correct 41 ms 8536 KB Output is correct
79 Correct 39 ms 8540 KB Output is correct
80 Correct 38 ms 8540 KB Output is correct
81 Correct 88 ms 16664 KB Output is correct
82 Correct 94 ms 16668 KB Output is correct
83 Correct 71 ms 16548 KB Output is correct
84 Correct 66 ms 16604 KB Output is correct
85 Correct 69 ms 16428 KB Output is correct
86 Correct 78 ms 17420 KB Output is correct
87 Correct 75 ms 17492 KB Output is correct
88 Correct 78 ms 17488 KB Output is correct
89 Correct 75 ms 17488 KB Output is correct
90 Correct 76 ms 17236 KB Output is correct
91 Correct 179 ms 35156 KB Output is correct
92 Correct 161 ms 35012 KB Output is correct
93 Correct 153 ms 35152 KB Output is correct
94 Correct 163 ms 35156 KB Output is correct
95 Correct 159 ms 35244 KB Output is correct
96 Correct 204 ms 42320 KB Output is correct
97 Correct 213 ms 42312 KB Output is correct
98 Correct 213 ms 42316 KB Output is correct
99 Correct 201 ms 42320 KB Output is correct
100 Correct 202 ms 42340 KB Output is correct
101 Correct 216 ms 42332 KB Output is correct
102 Correct 198 ms 42320 KB Output is correct
103 Correct 214 ms 42340 KB Output is correct
104 Correct 206 ms 42328 KB Output is correct
105 Correct 201 ms 42320 KB Output is correct
106 Correct 218 ms 45904 KB Output is correct
107 Correct 229 ms 45680 KB Output is correct
108 Correct 244 ms 45904 KB Output is correct
109 Correct 213 ms 45904 KB Output is correct
110 Correct 223 ms 45904 KB Output is correct
111 Correct 222 ms 45908 KB Output is correct
112 Correct 225 ms 46160 KB Output is correct
113 Correct 225 ms 45908 KB Output is correct
114 Correct 218 ms 45904 KB Output is correct
115 Correct 243 ms 45680 KB Output is correct
116 Incorrect 3 ms 1372 KB Output isn't correct
117 Halted 0 ms 0 KB -