Submission #476418

# Submission time Handle Problem Language Result Execution time Memory
476418 2021-09-26T14:16:16 Z neki Diversity (CEOI21_diversity) C++14
64 / 100
7000 ms 18560 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() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    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)
......
   57 |         loop(i, 0, cs.size()){
      |              ~~~~~~~~~~~~~~~       
diversity.cpp:57:9: note: in expansion of macro 'loop'
   57 |         loop(i, 0, cs.size()){
      |         ^~~~
# Verdict Execution time Memory 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 0 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 2 ms 332 KB Output is correct
4 Correct 13 ms 1100 KB Output is correct
5 Correct 22 ms 1868 KB Output is correct
6 Correct 26 ms 2672 KB Output is correct
7 Correct 27 ms 2636 KB Output is correct
8 Correct 25 ms 2636 KB Output is correct
9 Correct 28 ms 2636 KB Output is correct
10 Correct 32 ms 2636 KB Output is correct
11 Correct 33 ms 2636 KB Output is correct
12 Correct 34 ms 2664 KB Output is correct
13 Correct 29 ms 2680 KB Output is correct
14 Correct 31 ms 2656 KB Output is correct
15 Correct 31 ms 2636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 2 ms 332 KB Output is correct
4 Correct 13 ms 1100 KB Output is correct
5 Correct 22 ms 1868 KB Output is correct
6 Correct 26 ms 2672 KB Output is correct
7 Correct 27 ms 2636 KB Output is correct
8 Correct 25 ms 2636 KB Output is correct
9 Correct 28 ms 2636 KB Output is correct
10 Correct 32 ms 2636 KB Output is correct
11 Correct 33 ms 2636 KB Output is correct
12 Correct 34 ms 2664 KB Output is correct
13 Correct 29 ms 2680 KB Output is correct
14 Correct 31 ms 2656 KB Output is correct
15 Correct 31 ms 2636 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 10 ms 1100 KB Output is correct
20 Correct 22 ms 1868 KB Output is correct
21 Correct 31 ms 2680 KB Output is correct
22 Correct 29 ms 2636 KB Output is correct
23 Correct 28 ms 2676 KB Output is correct
24 Correct 34 ms 2676 KB Output is correct
25 Correct 38 ms 2660 KB Output is correct
26 Correct 36 ms 2672 KB Output is correct
27 Correct 32 ms 2636 KB Output is correct
28 Correct 29 ms 2636 KB Output is correct
29 Correct 30 ms 2672 KB Output is correct
30 Correct 32 ms 2636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 2 ms 332 KB Output is correct
4 Correct 13 ms 1100 KB Output is correct
5 Correct 22 ms 1868 KB Output is correct
6 Correct 26 ms 2672 KB Output is correct
7 Correct 27 ms 2636 KB Output is correct
8 Correct 25 ms 2636 KB Output is correct
9 Correct 28 ms 2636 KB Output is correct
10 Correct 32 ms 2636 KB Output is correct
11 Correct 33 ms 2636 KB Output is correct
12 Correct 34 ms 2664 KB Output is correct
13 Correct 29 ms 2680 KB Output is correct
14 Correct 31 ms 2656 KB Output is correct
15 Correct 31 ms 2636 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 10 ms 1100 KB Output is correct
20 Correct 22 ms 1868 KB Output is correct
21 Correct 31 ms 2680 KB Output is correct
22 Correct 29 ms 2636 KB Output is correct
23 Correct 28 ms 2676 KB Output is correct
24 Correct 34 ms 2676 KB Output is correct
25 Correct 38 ms 2660 KB Output is correct
26 Correct 36 ms 2672 KB Output is correct
27 Correct 32 ms 2636 KB Output is correct
28 Correct 29 ms 2636 KB Output is correct
29 Correct 30 ms 2672 KB Output is correct
30 Correct 32 ms 2636 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 2 ms 332 KB Output is correct
35 Correct 2 ms 332 KB Output is correct
36 Correct 2 ms 460 KB Output is correct
37 Correct 8 ms 716 KB Output is correct
38 Correct 10 ms 724 KB Output is correct
39 Correct 16 ms 1116 KB Output is correct
40 Correct 31 ms 1896 KB Output is correct
41 Correct 52 ms 2680 KB Output is correct
42 Correct 44 ms 2676 KB Output is correct
43 Correct 45 ms 2672 KB Output is correct
44 Correct 45 ms 2728 KB Output is correct
45 Correct 40 ms 2636 KB Output is correct
46 Correct 46 ms 2728 KB Output is correct
47 Correct 41 ms 2672 KB Output is correct
48 Correct 42 ms 2756 KB Output is correct
49 Correct 48 ms 2636 KB Output is correct
50 Correct 42 ms 2716 KB Output is correct
51 Correct 40 ms 2676 KB Output is correct
52 Correct 40 ms 2732 KB Output is correct
53 Correct 43 ms 2796 KB Output is correct
54 Correct 45 ms 2676 KB Output is correct
55 Correct 41 ms 2724 KB Output is correct
56 Correct 48 ms 2680 KB Output is correct
57 Correct 48 ms 2680 KB Output is correct
58 Correct 53 ms 2636 KB Output is correct
59 Correct 46 ms 2716 KB Output is correct
60 Correct 40 ms 2680 KB Output is correct
# Verdict Execution time Memory 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 0 ms 204 KB Output is correct
8 Correct 1 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 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 2 ms 332 KB Output is correct
14 Correct 13 ms 1100 KB Output is correct
15 Correct 22 ms 1868 KB Output is correct
16 Correct 26 ms 2672 KB Output is correct
17 Correct 27 ms 2636 KB Output is correct
18 Correct 25 ms 2636 KB Output is correct
19 Correct 28 ms 2636 KB Output is correct
20 Correct 32 ms 2636 KB Output is correct
21 Correct 33 ms 2636 KB Output is correct
22 Correct 34 ms 2664 KB Output is correct
23 Correct 29 ms 2680 KB Output is correct
24 Correct 31 ms 2656 KB Output is correct
25 Correct 31 ms 2636 KB Output is correct
26 Correct 0 ms 204 KB Output is correct
27 Correct 0 ms 204 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 10 ms 1100 KB Output is correct
30 Correct 22 ms 1868 KB Output is correct
31 Correct 31 ms 2680 KB Output is correct
32 Correct 29 ms 2636 KB Output is correct
33 Correct 28 ms 2676 KB Output is correct
34 Correct 34 ms 2676 KB Output is correct
35 Correct 38 ms 2660 KB Output is correct
36 Correct 36 ms 2672 KB Output is correct
37 Correct 32 ms 2636 KB Output is correct
38 Correct 29 ms 2636 KB Output is correct
39 Correct 30 ms 2672 KB Output is correct
40 Correct 32 ms 2636 KB Output is correct
41 Correct 1 ms 332 KB Output is correct
42 Correct 1 ms 332 KB Output is correct
43 Correct 1 ms 332 KB Output is correct
44 Correct 2 ms 332 KB Output is correct
45 Correct 2 ms 332 KB Output is correct
46 Correct 2 ms 460 KB Output is correct
47 Correct 8 ms 716 KB Output is correct
48 Correct 10 ms 724 KB Output is correct
49 Correct 16 ms 1116 KB Output is correct
50 Correct 31 ms 1896 KB Output is correct
51 Correct 52 ms 2680 KB Output is correct
52 Correct 44 ms 2676 KB Output is correct
53 Correct 45 ms 2672 KB Output is correct
54 Correct 45 ms 2728 KB Output is correct
55 Correct 40 ms 2636 KB Output is correct
56 Correct 46 ms 2728 KB Output is correct
57 Correct 41 ms 2672 KB Output is correct
58 Correct 42 ms 2756 KB Output is correct
59 Correct 48 ms 2636 KB Output is correct
60 Correct 42 ms 2716 KB Output is correct
61 Correct 40 ms 2676 KB Output is correct
62 Correct 40 ms 2732 KB Output is correct
63 Correct 43 ms 2796 KB Output is correct
64 Correct 45 ms 2676 KB Output is correct
65 Correct 41 ms 2724 KB Output is correct
66 Correct 48 ms 2680 KB Output is correct
67 Correct 48 ms 2680 KB Output is correct
68 Correct 53 ms 2636 KB Output is correct
69 Correct 46 ms 2716 KB Output is correct
70 Correct 40 ms 2680 KB Output is correct
71 Correct 8 ms 844 KB Output is correct
72 Correct 8 ms 844 KB Output is correct
73 Correct 8 ms 844 KB Output is correct
74 Correct 10 ms 844 KB Output is correct
75 Correct 8 ms 844 KB Output is correct
76 Correct 21 ms 1380 KB Output is correct
77 Correct 26 ms 1448 KB Output is correct
78 Correct 25 ms 1376 KB Output is correct
79 Correct 25 ms 1376 KB Output is correct
80 Correct 21 ms 1492 KB Output is correct
81 Correct 45 ms 2596 KB Output is correct
82 Correct 43 ms 2544 KB Output is correct
83 Correct 39 ms 2764 KB Output is correct
84 Correct 38 ms 2612 KB Output is correct
85 Correct 42 ms 2632 KB Output is correct
86 Correct 46 ms 3296 KB Output is correct
87 Correct 48 ms 3268 KB Output is correct
88 Correct 46 ms 3296 KB Output is correct
89 Correct 51 ms 3340 KB Output is correct
90 Correct 53 ms 3396 KB Output is correct
91 Correct 136 ms 9228 KB Output is correct
92 Correct 113 ms 9188 KB Output is correct
93 Correct 110 ms 9192 KB Output is correct
94 Correct 98 ms 9192 KB Output is correct
95 Correct 118 ms 9448 KB Output is correct
96 Correct 254 ms 15776 KB Output is correct
97 Correct 198 ms 15796 KB Output is correct
98 Correct 193 ms 15760 KB Output is correct
99 Correct 258 ms 15804 KB Output is correct
100 Correct 168 ms 15736 KB Output is correct
101 Correct 194 ms 15792 KB Output is correct
102 Correct 184 ms 15780 KB Output is correct
103 Correct 187 ms 15804 KB Output is correct
104 Correct 173 ms 15796 KB Output is correct
105 Correct 211 ms 16092 KB Output is correct
106 Correct 235 ms 18520 KB Output is correct
107 Correct 250 ms 18476 KB Output is correct
108 Correct 256 ms 18560 KB Output is correct
109 Correct 248 ms 18468 KB Output is correct
110 Correct 230 ms 18492 KB Output is correct
111 Correct 224 ms 18492 KB Output is correct
112 Correct 244 ms 18536 KB Output is correct
113 Correct 238 ms 18540 KB Output is correct
114 Correct 287 ms 18448 KB Output is correct
115 Correct 274 ms 18532 KB Output is correct
# Verdict Execution time Memory 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 0 ms 204 KB Output is correct
8 Correct 1 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 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 2 ms 332 KB Output is correct
14 Correct 13 ms 1100 KB Output is correct
15 Correct 22 ms 1868 KB Output is correct
16 Correct 26 ms 2672 KB Output is correct
17 Correct 27 ms 2636 KB Output is correct
18 Correct 25 ms 2636 KB Output is correct
19 Correct 28 ms 2636 KB Output is correct
20 Correct 32 ms 2636 KB Output is correct
21 Correct 33 ms 2636 KB Output is correct
22 Correct 34 ms 2664 KB Output is correct
23 Correct 29 ms 2680 KB Output is correct
24 Correct 31 ms 2656 KB Output is correct
25 Correct 31 ms 2636 KB Output is correct
26 Correct 0 ms 204 KB Output is correct
27 Correct 0 ms 204 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 10 ms 1100 KB Output is correct
30 Correct 22 ms 1868 KB Output is correct
31 Correct 31 ms 2680 KB Output is correct
32 Correct 29 ms 2636 KB Output is correct
33 Correct 28 ms 2676 KB Output is correct
34 Correct 34 ms 2676 KB Output is correct
35 Correct 38 ms 2660 KB Output is correct
36 Correct 36 ms 2672 KB Output is correct
37 Correct 32 ms 2636 KB Output is correct
38 Correct 29 ms 2636 KB Output is correct
39 Correct 30 ms 2672 KB Output is correct
40 Correct 32 ms 2636 KB Output is correct
41 Correct 1 ms 332 KB Output is correct
42 Correct 1 ms 332 KB Output is correct
43 Correct 1 ms 332 KB Output is correct
44 Correct 2 ms 332 KB Output is correct
45 Correct 2 ms 332 KB Output is correct
46 Correct 2 ms 460 KB Output is correct
47 Correct 8 ms 716 KB Output is correct
48 Correct 10 ms 724 KB Output is correct
49 Correct 16 ms 1116 KB Output is correct
50 Correct 31 ms 1896 KB Output is correct
51 Correct 52 ms 2680 KB Output is correct
52 Correct 44 ms 2676 KB Output is correct
53 Correct 45 ms 2672 KB Output is correct
54 Correct 45 ms 2728 KB Output is correct
55 Correct 40 ms 2636 KB Output is correct
56 Correct 46 ms 2728 KB Output is correct
57 Correct 41 ms 2672 KB Output is correct
58 Correct 42 ms 2756 KB Output is correct
59 Correct 48 ms 2636 KB Output is correct
60 Correct 42 ms 2716 KB Output is correct
61 Correct 40 ms 2676 KB Output is correct
62 Correct 40 ms 2732 KB Output is correct
63 Correct 43 ms 2796 KB Output is correct
64 Correct 45 ms 2676 KB Output is correct
65 Correct 41 ms 2724 KB Output is correct
66 Correct 48 ms 2680 KB Output is correct
67 Correct 48 ms 2680 KB Output is correct
68 Correct 53 ms 2636 KB Output is correct
69 Correct 46 ms 2716 KB Output is correct
70 Correct 40 ms 2680 KB Output is correct
71 Correct 8 ms 844 KB Output is correct
72 Correct 8 ms 844 KB Output is correct
73 Correct 8 ms 844 KB Output is correct
74 Correct 10 ms 844 KB Output is correct
75 Correct 8 ms 844 KB Output is correct
76 Correct 21 ms 1380 KB Output is correct
77 Correct 26 ms 1448 KB Output is correct
78 Correct 25 ms 1376 KB Output is correct
79 Correct 25 ms 1376 KB Output is correct
80 Correct 21 ms 1492 KB Output is correct
81 Correct 45 ms 2596 KB Output is correct
82 Correct 43 ms 2544 KB Output is correct
83 Correct 39 ms 2764 KB Output is correct
84 Correct 38 ms 2612 KB Output is correct
85 Correct 42 ms 2632 KB Output is correct
86 Correct 46 ms 3296 KB Output is correct
87 Correct 48 ms 3268 KB Output is correct
88 Correct 46 ms 3296 KB Output is correct
89 Correct 51 ms 3340 KB Output is correct
90 Correct 53 ms 3396 KB Output is correct
91 Correct 136 ms 9228 KB Output is correct
92 Correct 113 ms 9188 KB Output is correct
93 Correct 110 ms 9192 KB Output is correct
94 Correct 98 ms 9192 KB Output is correct
95 Correct 118 ms 9448 KB Output is correct
96 Correct 254 ms 15776 KB Output is correct
97 Correct 198 ms 15796 KB Output is correct
98 Correct 193 ms 15760 KB Output is correct
99 Correct 258 ms 15804 KB Output is correct
100 Correct 168 ms 15736 KB Output is correct
101 Correct 194 ms 15792 KB Output is correct
102 Correct 184 ms 15780 KB Output is correct
103 Correct 187 ms 15804 KB Output is correct
104 Correct 173 ms 15796 KB Output is correct
105 Correct 211 ms 16092 KB Output is correct
106 Correct 235 ms 18520 KB Output is correct
107 Correct 250 ms 18476 KB Output is correct
108 Correct 256 ms 18560 KB Output is correct
109 Correct 248 ms 18468 KB Output is correct
110 Correct 230 ms 18492 KB Output is correct
111 Correct 224 ms 18492 KB Output is correct
112 Correct 244 ms 18536 KB Output is correct
113 Correct 238 ms 18540 KB Output is correct
114 Correct 287 ms 18448 KB Output is correct
115 Correct 274 ms 18532 KB Output is correct
116 Correct 384 ms 2340 KB Output is correct
117 Correct 506 ms 2332 KB Output is correct
118 Correct 634 ms 2788 KB Output is correct
119 Correct 1732 ms 2756 KB Output is correct
120 Correct 2876 ms 2852 KB Output is correct
121 Correct 3648 ms 3248 KB Output is correct
122 Correct 5787 ms 3312 KB Output is correct
123 Correct 5992 ms 4164 KB Output is correct
124 Execution timed out 7095 ms 3908 KB Time limit exceeded
125 Halted 0 ms 0 KB -