답안 #476417

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
476417 2021-09-26T14:14:22 Z neki Diversity (CEOI21_diversity) C++14
64 / 100
7000 ms 20544 KB
#include <bits/stdc++.h>
#define ll long long
#define loop(i, a, b) for(ll i=a;i<b;++i)
#define pool(i, a, b) for(ll i=a-1;i>=b;--i)
#define fore(i, a) for(auto&& i:a)
#define fi first
#define se second
#define ps(a) push_back(a)
#define pb(a) pop_back(a)
#define eb(...) emplace_back(__VA_ARGS__)
#define sc scanf
#define vc vector
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(), a.end()
#define llmax LLONG_MAX/2
#define llmin -LLONG_MAX/2
using namespace std;
#define mn 500100
#define par pair<ll, ll>
#define ld long double
#define mod 1000000007

ll cnt[300100];
int main() {
    ll n, q;cin >> n >> q;
    vc<ll> a(n);loop(i, 0, n) cin >> a[i];
    
    vc<array<ll, 3>> que(q);
    loop(i, 0, q){ cin >> que[i][0] >> que[i][1];--que[i][0], --que[i][1];}
    loop(i, 0, q) que[i][2]=i;
    
    const ll m=550;
    sort(all(que), [&](array<ll, 3> a, array<ll, 3> b){
        if(a[0]/m==b[0]/m) return a[1]<b[1];
        return a[0]<b[0];
    });
    
    set<ll> act;
    function<void (ll)> add=[&](ll i){
        act.insert(a[i]);
        ++cnt[a[i]];
    };
    function<void (ll)> rem=[&](ll i){
        --cnt[a[i]];
        if(cnt[a[i]]==0) act.erase(a[i]);
    };
    function<ll ()> getans=[&](){
        ll sum=0;
        vc<ll> cs; fore(v, act) sum+=cnt[v], cs.ps(cnt[v]);
        sort(all(cs));
        
        ll ret=0;
        vc<ll> pre(2, 0);
        loop(i, 0, cs.size()){
            ret+=pre[i%2] * (sum-cs[i]-pre[i%2]);
            pre[i%2]+=cs[i];
            
            ret+=cs[i] * (sum-cs[i]);
            ret+=(cs[i] * cs[i] + cs[i])/2;
        }
        return ret;
    };
    
    vc<ll> ans(q);
    ll l=0, r=-1;
    loop(i, 0, q){
        ll ql=que[i][0], qr=que[i][1];
        
        while(r<qr) add(++r);
        while(r>qr) rem(r--);
        
        while(l<ql) rem(l++);
        while(l>ql) add(--l);
        
        ans[que[i][2]]=getans();
    }
    
    loop(i, 0, q) cout << ans[i]<<endl;
}

Compilation message

diversity.cpp: In lambda function:
diversity.cpp:3:35: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    3 | #define loop(i, a, b) for(ll i=a;i<b;++i)
......
   55 |         loop(i, 0, cs.size()){
      |              ~~~~~~~~~~~~~~~       
diversity.cpp:55:9: note: in expansion of macro 'loop'
   55 |         loop(i, 0, cs.size()){
      |         ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 3 ms 388 KB Output is correct
4 Correct 19 ms 1280 KB Output is correct
5 Correct 40 ms 2240 KB Output is correct
6 Correct 61 ms 3384 KB Output is correct
7 Correct 58 ms 3236 KB Output is correct
8 Correct 56 ms 3276 KB Output is correct
9 Correct 64 ms 3256 KB Output is correct
10 Correct 62 ms 3264 KB Output is correct
11 Correct 58 ms 3264 KB Output is correct
12 Correct 57 ms 3380 KB Output is correct
13 Correct 58 ms 3260 KB Output is correct
14 Correct 57 ms 3272 KB Output is correct
15 Correct 61 ms 3260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 3 ms 388 KB Output is correct
4 Correct 19 ms 1280 KB Output is correct
5 Correct 40 ms 2240 KB Output is correct
6 Correct 61 ms 3384 KB Output is correct
7 Correct 58 ms 3236 KB Output is correct
8 Correct 56 ms 3276 KB Output is correct
9 Correct 64 ms 3256 KB Output is correct
10 Correct 62 ms 3264 KB Output is correct
11 Correct 58 ms 3264 KB Output is correct
12 Correct 57 ms 3380 KB Output is correct
13 Correct 58 ms 3260 KB Output is correct
14 Correct 57 ms 3272 KB Output is correct
15 Correct 61 ms 3260 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 2 ms 332 KB Output is correct
19 Correct 23 ms 1228 KB Output is correct
20 Correct 42 ms 2360 KB Output is correct
21 Correct 63 ms 3532 KB Output is correct
22 Correct 63 ms 3392 KB Output is correct
23 Correct 68 ms 3392 KB Output is correct
24 Correct 70 ms 3392 KB Output is correct
25 Correct 67 ms 3404 KB Output is correct
26 Correct 62 ms 3392 KB Output is correct
27 Correct 65 ms 3408 KB Output is correct
28 Correct 64 ms 3260 KB Output is correct
29 Correct 68 ms 3268 KB Output is correct
30 Correct 67 ms 3392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 3 ms 388 KB Output is correct
4 Correct 19 ms 1280 KB Output is correct
5 Correct 40 ms 2240 KB Output is correct
6 Correct 61 ms 3384 KB Output is correct
7 Correct 58 ms 3236 KB Output is correct
8 Correct 56 ms 3276 KB Output is correct
9 Correct 64 ms 3256 KB Output is correct
10 Correct 62 ms 3264 KB Output is correct
11 Correct 58 ms 3264 KB Output is correct
12 Correct 57 ms 3380 KB Output is correct
13 Correct 58 ms 3260 KB Output is correct
14 Correct 57 ms 3272 KB Output is correct
15 Correct 61 ms 3260 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 2 ms 332 KB Output is correct
19 Correct 23 ms 1228 KB Output is correct
20 Correct 42 ms 2360 KB Output is correct
21 Correct 63 ms 3532 KB Output is correct
22 Correct 63 ms 3392 KB Output is correct
23 Correct 68 ms 3392 KB Output is correct
24 Correct 70 ms 3392 KB Output is correct
25 Correct 67 ms 3404 KB Output is correct
26 Correct 62 ms 3392 KB Output is correct
27 Correct 65 ms 3408 KB Output is correct
28 Correct 64 ms 3260 KB Output is correct
29 Correct 68 ms 3268 KB Output is correct
30 Correct 67 ms 3392 KB Output is correct
31 Correct 1 ms 204 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
34 Correct 3 ms 388 KB Output is correct
35 Correct 3 ms 400 KB Output is correct
36 Correct 3 ms 460 KB Output is correct
37 Correct 14 ms 844 KB Output is correct
38 Correct 17 ms 892 KB Output is correct
39 Correct 32 ms 1460 KB Output is correct
40 Correct 57 ms 2628 KB Output is correct
41 Correct 84 ms 3776 KB Output is correct
42 Correct 89 ms 3780 KB Output is correct
43 Correct 90 ms 3776 KB Output is correct
44 Correct 93 ms 3784 KB Output is correct
45 Correct 85 ms 3780 KB Output is correct
46 Correct 86 ms 3784 KB Output is correct
47 Correct 90 ms 3796 KB Output is correct
48 Correct 84 ms 3788 KB Output is correct
49 Correct 91 ms 3904 KB Output is correct
50 Correct 86 ms 3776 KB Output is correct
51 Correct 86 ms 3780 KB Output is correct
52 Correct 89 ms 3780 KB Output is correct
53 Correct 83 ms 3780 KB Output is correct
54 Correct 92 ms 3900 KB Output is correct
55 Correct 85 ms 3776 KB Output is correct
56 Correct 92 ms 3776 KB Output is correct
57 Correct 84 ms 3824 KB Output is correct
58 Correct 85 ms 3780 KB Output is correct
59 Correct 90 ms 3776 KB Output is correct
60 Correct 86 ms 3772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 3 ms 388 KB Output is correct
14 Correct 19 ms 1280 KB Output is correct
15 Correct 40 ms 2240 KB Output is correct
16 Correct 61 ms 3384 KB Output is correct
17 Correct 58 ms 3236 KB Output is correct
18 Correct 56 ms 3276 KB Output is correct
19 Correct 64 ms 3256 KB Output is correct
20 Correct 62 ms 3264 KB Output is correct
21 Correct 58 ms 3264 KB Output is correct
22 Correct 57 ms 3380 KB Output is correct
23 Correct 58 ms 3260 KB Output is correct
24 Correct 57 ms 3272 KB Output is correct
25 Correct 61 ms 3260 KB Output is correct
26 Correct 0 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 2 ms 332 KB Output is correct
29 Correct 23 ms 1228 KB Output is correct
30 Correct 42 ms 2360 KB Output is correct
31 Correct 63 ms 3532 KB Output is correct
32 Correct 63 ms 3392 KB Output is correct
33 Correct 68 ms 3392 KB Output is correct
34 Correct 70 ms 3392 KB Output is correct
35 Correct 67 ms 3404 KB Output is correct
36 Correct 62 ms 3392 KB Output is correct
37 Correct 65 ms 3408 KB Output is correct
38 Correct 64 ms 3260 KB Output is correct
39 Correct 68 ms 3268 KB Output is correct
40 Correct 67 ms 3392 KB Output is correct
41 Correct 1 ms 204 KB Output is correct
42 Correct 1 ms 204 KB Output is correct
43 Correct 1 ms 204 KB Output is correct
44 Correct 3 ms 388 KB Output is correct
45 Correct 3 ms 400 KB Output is correct
46 Correct 3 ms 460 KB Output is correct
47 Correct 14 ms 844 KB Output is correct
48 Correct 17 ms 892 KB Output is correct
49 Correct 32 ms 1460 KB Output is correct
50 Correct 57 ms 2628 KB Output is correct
51 Correct 84 ms 3776 KB Output is correct
52 Correct 89 ms 3780 KB Output is correct
53 Correct 90 ms 3776 KB Output is correct
54 Correct 93 ms 3784 KB Output is correct
55 Correct 85 ms 3780 KB Output is correct
56 Correct 86 ms 3784 KB Output is correct
57 Correct 90 ms 3796 KB Output is correct
58 Correct 84 ms 3788 KB Output is correct
59 Correct 91 ms 3904 KB Output is correct
60 Correct 86 ms 3776 KB Output is correct
61 Correct 86 ms 3780 KB Output is correct
62 Correct 89 ms 3780 KB Output is correct
63 Correct 83 ms 3780 KB Output is correct
64 Correct 92 ms 3900 KB Output is correct
65 Correct 85 ms 3776 KB Output is correct
66 Correct 92 ms 3776 KB Output is correct
67 Correct 84 ms 3824 KB Output is correct
68 Correct 85 ms 3780 KB Output is correct
69 Correct 90 ms 3776 KB Output is correct
70 Correct 86 ms 3772 KB Output is correct
71 Correct 18 ms 972 KB Output is correct
72 Correct 18 ms 1036 KB Output is correct
73 Correct 18 ms 1028 KB Output is correct
74 Correct 18 ms 1016 KB Output is correct
75 Correct 17 ms 972 KB Output is correct
76 Correct 35 ms 1792 KB Output is correct
77 Correct 37 ms 1796 KB Output is correct
78 Correct 36 ms 1800 KB Output is correct
79 Correct 38 ms 1860 KB Output is correct
80 Correct 35 ms 1860 KB Output is correct
81 Correct 73 ms 3500 KB Output is correct
82 Correct 75 ms 3500 KB Output is correct
83 Correct 75 ms 3512 KB Output is correct
84 Correct 73 ms 3524 KB Output is correct
85 Correct 75 ms 3508 KB Output is correct
86 Correct 81 ms 4316 KB Output is correct
87 Correct 84 ms 4292 KB Output is correct
88 Correct 82 ms 4320 KB Output is correct
89 Correct 93 ms 4280 KB Output is correct
90 Correct 90 ms 4284 KB Output is correct
91 Correct 174 ms 10936 KB Output is correct
92 Correct 163 ms 10944 KB Output is correct
93 Correct 163 ms 10940 KB Output is correct
94 Correct 165 ms 10932 KB Output is correct
95 Correct 159 ms 10940 KB Output is correct
96 Correct 233 ms 17672 KB Output is correct
97 Correct 236 ms 17588 KB Output is correct
98 Correct 242 ms 17592 KB Output is correct
99 Correct 251 ms 17636 KB Output is correct
100 Correct 230 ms 17588 KB Output is correct
101 Correct 242 ms 17588 KB Output is correct
102 Correct 240 ms 17628 KB Output is correct
103 Correct 226 ms 17592 KB Output is correct
104 Correct 274 ms 17584 KB Output is correct
105 Correct 242 ms 17568 KB Output is correct
106 Correct 278 ms 20432 KB Output is correct
107 Correct 277 ms 20416 KB Output is correct
108 Correct 263 ms 20544 KB Output is correct
109 Correct 288 ms 20416 KB Output is correct
110 Correct 280 ms 20412 KB Output is correct
111 Correct 256 ms 20424 KB Output is correct
112 Correct 262 ms 20400 KB Output is correct
113 Correct 282 ms 20408 KB Output is correct
114 Correct 279 ms 20536 KB Output is correct
115 Correct 279 ms 20340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 3 ms 388 KB Output is correct
14 Correct 19 ms 1280 KB Output is correct
15 Correct 40 ms 2240 KB Output is correct
16 Correct 61 ms 3384 KB Output is correct
17 Correct 58 ms 3236 KB Output is correct
18 Correct 56 ms 3276 KB Output is correct
19 Correct 64 ms 3256 KB Output is correct
20 Correct 62 ms 3264 KB Output is correct
21 Correct 58 ms 3264 KB Output is correct
22 Correct 57 ms 3380 KB Output is correct
23 Correct 58 ms 3260 KB Output is correct
24 Correct 57 ms 3272 KB Output is correct
25 Correct 61 ms 3260 KB Output is correct
26 Correct 0 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 2 ms 332 KB Output is correct
29 Correct 23 ms 1228 KB Output is correct
30 Correct 42 ms 2360 KB Output is correct
31 Correct 63 ms 3532 KB Output is correct
32 Correct 63 ms 3392 KB Output is correct
33 Correct 68 ms 3392 KB Output is correct
34 Correct 70 ms 3392 KB Output is correct
35 Correct 67 ms 3404 KB Output is correct
36 Correct 62 ms 3392 KB Output is correct
37 Correct 65 ms 3408 KB Output is correct
38 Correct 64 ms 3260 KB Output is correct
39 Correct 68 ms 3268 KB Output is correct
40 Correct 67 ms 3392 KB Output is correct
41 Correct 1 ms 204 KB Output is correct
42 Correct 1 ms 204 KB Output is correct
43 Correct 1 ms 204 KB Output is correct
44 Correct 3 ms 388 KB Output is correct
45 Correct 3 ms 400 KB Output is correct
46 Correct 3 ms 460 KB Output is correct
47 Correct 14 ms 844 KB Output is correct
48 Correct 17 ms 892 KB Output is correct
49 Correct 32 ms 1460 KB Output is correct
50 Correct 57 ms 2628 KB Output is correct
51 Correct 84 ms 3776 KB Output is correct
52 Correct 89 ms 3780 KB Output is correct
53 Correct 90 ms 3776 KB Output is correct
54 Correct 93 ms 3784 KB Output is correct
55 Correct 85 ms 3780 KB Output is correct
56 Correct 86 ms 3784 KB Output is correct
57 Correct 90 ms 3796 KB Output is correct
58 Correct 84 ms 3788 KB Output is correct
59 Correct 91 ms 3904 KB Output is correct
60 Correct 86 ms 3776 KB Output is correct
61 Correct 86 ms 3780 KB Output is correct
62 Correct 89 ms 3780 KB Output is correct
63 Correct 83 ms 3780 KB Output is correct
64 Correct 92 ms 3900 KB Output is correct
65 Correct 85 ms 3776 KB Output is correct
66 Correct 92 ms 3776 KB Output is correct
67 Correct 84 ms 3824 KB Output is correct
68 Correct 85 ms 3780 KB Output is correct
69 Correct 90 ms 3776 KB Output is correct
70 Correct 86 ms 3772 KB Output is correct
71 Correct 18 ms 972 KB Output is correct
72 Correct 18 ms 1036 KB Output is correct
73 Correct 18 ms 1028 KB Output is correct
74 Correct 18 ms 1016 KB Output is correct
75 Correct 17 ms 972 KB Output is correct
76 Correct 35 ms 1792 KB Output is correct
77 Correct 37 ms 1796 KB Output is correct
78 Correct 36 ms 1800 KB Output is correct
79 Correct 38 ms 1860 KB Output is correct
80 Correct 35 ms 1860 KB Output is correct
81 Correct 73 ms 3500 KB Output is correct
82 Correct 75 ms 3500 KB Output is correct
83 Correct 75 ms 3512 KB Output is correct
84 Correct 73 ms 3524 KB Output is correct
85 Correct 75 ms 3508 KB Output is correct
86 Correct 81 ms 4316 KB Output is correct
87 Correct 84 ms 4292 KB Output is correct
88 Correct 82 ms 4320 KB Output is correct
89 Correct 93 ms 4280 KB Output is correct
90 Correct 90 ms 4284 KB Output is correct
91 Correct 174 ms 10936 KB Output is correct
92 Correct 163 ms 10944 KB Output is correct
93 Correct 163 ms 10940 KB Output is correct
94 Correct 165 ms 10932 KB Output is correct
95 Correct 159 ms 10940 KB Output is correct
96 Correct 233 ms 17672 KB Output is correct
97 Correct 236 ms 17588 KB Output is correct
98 Correct 242 ms 17592 KB Output is correct
99 Correct 251 ms 17636 KB Output is correct
100 Correct 230 ms 17588 KB Output is correct
101 Correct 242 ms 17588 KB Output is correct
102 Correct 240 ms 17628 KB Output is correct
103 Correct 226 ms 17592 KB Output is correct
104 Correct 274 ms 17584 KB Output is correct
105 Correct 242 ms 17568 KB Output is correct
106 Correct 278 ms 20432 KB Output is correct
107 Correct 277 ms 20416 KB Output is correct
108 Correct 263 ms 20544 KB Output is correct
109 Correct 288 ms 20416 KB Output is correct
110 Correct 280 ms 20412 KB Output is correct
111 Correct 256 ms 20424 KB Output is correct
112 Correct 262 ms 20400 KB Output is correct
113 Correct 282 ms 20408 KB Output is correct
114 Correct 279 ms 20536 KB Output is correct
115 Correct 279 ms 20340 KB Output is correct
116 Correct 394 ms 2824 KB Output is correct
117 Correct 488 ms 2884 KB Output is correct
118 Correct 635 ms 3472 KB Output is correct
119 Correct 1735 ms 3584 KB Output is correct
120 Correct 2914 ms 3580 KB Output is correct
121 Correct 3734 ms 4308 KB Output is correct
122 Correct 5917 ms 4304 KB Output is correct
123 Correct 6106 ms 5520 KB Output is correct
124 Execution timed out 7089 ms 5384 KB Time limit exceeded
125 Halted 0 ms 0 KB -