Submission #476422

# Submission time Handle Problem Language Result Execution time Memory
476422 2021-09-26T14:33:20 Z neki Diversity (CEOI21_diversity) C++14
64 / 100
70 ms 22856 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

vc<ll> a;
ll cnt[300100];
deque<ll> act;
deque<ll>::iterator poi[300100];
void add(ll i){
    if(cnt[a[i]]==0)act.push_front(a[i]), poi[a[i]]=act.begin();
    ++cnt[a[i]];
}

void rem(ll i){
    --cnt[a[i]];
    if(cnt[a[i]]==0) act.erase(poi[a[i]]);
}

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;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n, q;cin >> n >> q;
    a.resize(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];
    });
    
    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 function 'long long int getans()':
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)
......
   45 |     loop(i, 0, cs.size()){
      |          ~~~~~~~~~~~~~~~           
diversity.cpp:45:5: note: in expansion of macro 'loop'
   45 |     loop(i, 0, cs.size()){
      |     ^~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9676 KB Output is correct
2 Correct 5 ms 9676 KB Output is correct
3 Correct 5 ms 9676 KB Output is correct
4 Correct 4 ms 9676 KB Output is correct
5 Correct 4 ms 9648 KB Output is correct
6 Correct 5 ms 9676 KB Output is correct
7 Correct 5 ms 9676 KB Output is correct
8 Correct 4 ms 9676 KB Output is correct
9 Correct 4 ms 9676 KB Output is correct
10 Correct 5 ms 9676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 9676 KB Output is correct
2 Correct 4 ms 9676 KB Output is correct
3 Correct 5 ms 9676 KB Output is correct
4 Correct 10 ms 10512 KB Output is correct
5 Correct 16 ms 11288 KB Output is correct
6 Correct 24 ms 12080 KB Output is correct
7 Correct 26 ms 12080 KB Output is correct
8 Correct 27 ms 11980 KB Output is correct
9 Correct 25 ms 12060 KB Output is correct
10 Correct 26 ms 12076 KB Output is correct
11 Correct 22 ms 12072 KB Output is correct
12 Correct 28 ms 12080 KB Output is correct
13 Correct 27 ms 12072 KB Output is correct
14 Correct 23 ms 12076 KB Output is correct
15 Correct 28 ms 12080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 9676 KB Output is correct
2 Correct 4 ms 9676 KB Output is correct
3 Correct 5 ms 9676 KB Output is correct
4 Correct 10 ms 10512 KB Output is correct
5 Correct 16 ms 11288 KB Output is correct
6 Correct 24 ms 12080 KB Output is correct
7 Correct 26 ms 12080 KB Output is correct
8 Correct 27 ms 11980 KB Output is correct
9 Correct 25 ms 12060 KB Output is correct
10 Correct 26 ms 12076 KB Output is correct
11 Correct 22 ms 12072 KB Output is correct
12 Correct 28 ms 12080 KB Output is correct
13 Correct 27 ms 12072 KB Output is correct
14 Correct 23 ms 12076 KB Output is correct
15 Correct 28 ms 12080 KB Output is correct
16 Correct 6 ms 9676 KB Output is correct
17 Correct 5 ms 9676 KB Output is correct
18 Correct 6 ms 9676 KB Output is correct
19 Correct 11 ms 10444 KB Output is correct
20 Correct 18 ms 11292 KB Output is correct
21 Correct 29 ms 12052 KB Output is correct
22 Correct 24 ms 11980 KB Output is correct
23 Correct 24 ms 12080 KB Output is correct
24 Correct 24 ms 11980 KB Output is correct
25 Correct 31 ms 12068 KB Output is correct
26 Correct 24 ms 11980 KB Output is correct
27 Correct 28 ms 12076 KB Output is correct
28 Correct 27 ms 12076 KB Output is correct
29 Correct 24 ms 12080 KB Output is correct
30 Correct 28 ms 12072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 9676 KB Output is correct
2 Correct 4 ms 9676 KB Output is correct
3 Correct 5 ms 9676 KB Output is correct
4 Correct 10 ms 10512 KB Output is correct
5 Correct 16 ms 11288 KB Output is correct
6 Correct 24 ms 12080 KB Output is correct
7 Correct 26 ms 12080 KB Output is correct
8 Correct 27 ms 11980 KB Output is correct
9 Correct 25 ms 12060 KB Output is correct
10 Correct 26 ms 12076 KB Output is correct
11 Correct 22 ms 12072 KB Output is correct
12 Correct 28 ms 12080 KB Output is correct
13 Correct 27 ms 12072 KB Output is correct
14 Correct 23 ms 12076 KB Output is correct
15 Correct 28 ms 12080 KB Output is correct
16 Correct 6 ms 9676 KB Output is correct
17 Correct 5 ms 9676 KB Output is correct
18 Correct 6 ms 9676 KB Output is correct
19 Correct 11 ms 10444 KB Output is correct
20 Correct 18 ms 11292 KB Output is correct
21 Correct 29 ms 12052 KB Output is correct
22 Correct 24 ms 11980 KB Output is correct
23 Correct 24 ms 12080 KB Output is correct
24 Correct 24 ms 11980 KB Output is correct
25 Correct 31 ms 12068 KB Output is correct
26 Correct 24 ms 11980 KB Output is correct
27 Correct 28 ms 12076 KB Output is correct
28 Correct 27 ms 12076 KB Output is correct
29 Correct 24 ms 12080 KB Output is correct
30 Correct 28 ms 12072 KB Output is correct
31 Correct 4 ms 9676 KB Output is correct
32 Correct 5 ms 9676 KB Output is correct
33 Correct 5 ms 9676 KB Output is correct
34 Correct 5 ms 9676 KB Output is correct
35 Correct 5 ms 9676 KB Output is correct
36 Correct 6 ms 9796 KB Output is correct
37 Correct 10 ms 10136 KB Output is correct
38 Correct 10 ms 10060 KB Output is correct
39 Correct 12 ms 10444 KB Output is correct
40 Correct 21 ms 11212 KB Output is correct
41 Correct 26 ms 11980 KB Output is correct
42 Correct 27 ms 12108 KB Output is correct
43 Correct 34 ms 12052 KB Output is correct
44 Correct 26 ms 12068 KB Output is correct
45 Correct 26 ms 11980 KB Output is correct
46 Correct 26 ms 12076 KB Output is correct
47 Correct 25 ms 12076 KB Output is correct
48 Correct 31 ms 12068 KB Output is correct
49 Correct 27 ms 12084 KB Output is correct
50 Correct 40 ms 12068 KB Output is correct
51 Correct 30 ms 12068 KB Output is correct
52 Correct 30 ms 12060 KB Output is correct
53 Correct 29 ms 12056 KB Output is correct
54 Correct 29 ms 12080 KB Output is correct
55 Correct 27 ms 12076 KB Output is correct
56 Correct 26 ms 12076 KB Output is correct
57 Correct 32 ms 12120 KB Output is correct
58 Correct 26 ms 11980 KB Output is correct
59 Correct 30 ms 12076 KB Output is correct
60 Correct 27 ms 12072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9676 KB Output is correct
2 Correct 5 ms 9676 KB Output is correct
3 Correct 5 ms 9676 KB Output is correct
4 Correct 4 ms 9676 KB Output is correct
5 Correct 4 ms 9648 KB Output is correct
6 Correct 5 ms 9676 KB Output is correct
7 Correct 5 ms 9676 KB Output is correct
8 Correct 4 ms 9676 KB Output is correct
9 Correct 4 ms 9676 KB Output is correct
10 Correct 5 ms 9676 KB Output is correct
11 Correct 4 ms 9676 KB Output is correct
12 Correct 4 ms 9676 KB Output is correct
13 Correct 5 ms 9676 KB Output is correct
14 Correct 10 ms 10512 KB Output is correct
15 Correct 16 ms 11288 KB Output is correct
16 Correct 24 ms 12080 KB Output is correct
17 Correct 26 ms 12080 KB Output is correct
18 Correct 27 ms 11980 KB Output is correct
19 Correct 25 ms 12060 KB Output is correct
20 Correct 26 ms 12076 KB Output is correct
21 Correct 22 ms 12072 KB Output is correct
22 Correct 28 ms 12080 KB Output is correct
23 Correct 27 ms 12072 KB Output is correct
24 Correct 23 ms 12076 KB Output is correct
25 Correct 28 ms 12080 KB Output is correct
26 Correct 6 ms 9676 KB Output is correct
27 Correct 5 ms 9676 KB Output is correct
28 Correct 6 ms 9676 KB Output is correct
29 Correct 11 ms 10444 KB Output is correct
30 Correct 18 ms 11292 KB Output is correct
31 Correct 29 ms 12052 KB Output is correct
32 Correct 24 ms 11980 KB Output is correct
33 Correct 24 ms 12080 KB Output is correct
34 Correct 24 ms 11980 KB Output is correct
35 Correct 31 ms 12068 KB Output is correct
36 Correct 24 ms 11980 KB Output is correct
37 Correct 28 ms 12076 KB Output is correct
38 Correct 27 ms 12076 KB Output is correct
39 Correct 24 ms 12080 KB Output is correct
40 Correct 28 ms 12072 KB Output is correct
41 Correct 4 ms 9676 KB Output is correct
42 Correct 5 ms 9676 KB Output is correct
43 Correct 5 ms 9676 KB Output is correct
44 Correct 5 ms 9676 KB Output is correct
45 Correct 5 ms 9676 KB Output is correct
46 Correct 6 ms 9796 KB Output is correct
47 Correct 10 ms 10136 KB Output is correct
48 Correct 10 ms 10060 KB Output is correct
49 Correct 12 ms 10444 KB Output is correct
50 Correct 21 ms 11212 KB Output is correct
51 Correct 26 ms 11980 KB Output is correct
52 Correct 27 ms 12108 KB Output is correct
53 Correct 34 ms 12052 KB Output is correct
54 Correct 26 ms 12068 KB Output is correct
55 Correct 26 ms 11980 KB Output is correct
56 Correct 26 ms 12076 KB Output is correct
57 Correct 25 ms 12076 KB Output is correct
58 Correct 31 ms 12068 KB Output is correct
59 Correct 27 ms 12084 KB Output is correct
60 Correct 40 ms 12068 KB Output is correct
61 Correct 30 ms 12068 KB Output is correct
62 Correct 30 ms 12060 KB Output is correct
63 Correct 29 ms 12056 KB Output is correct
64 Correct 29 ms 12080 KB Output is correct
65 Correct 27 ms 12076 KB Output is correct
66 Correct 26 ms 12076 KB Output is correct
67 Correct 32 ms 12120 KB Output is correct
68 Correct 26 ms 11980 KB Output is correct
69 Correct 30 ms 12076 KB Output is correct
70 Correct 27 ms 12072 KB Output is correct
71 Correct 8 ms 10188 KB Output is correct
72 Correct 9 ms 10188 KB Output is correct
73 Correct 9 ms 10188 KB Output is correct
74 Correct 10 ms 10188 KB Output is correct
75 Correct 9 ms 10184 KB Output is correct
76 Correct 15 ms 10636 KB Output is correct
77 Correct 15 ms 10704 KB Output is correct
78 Correct 15 ms 10700 KB Output is correct
79 Correct 17 ms 10676 KB Output is correct
80 Correct 13 ms 10588 KB Output is correct
81 Correct 21 ms 11552 KB Output is correct
82 Correct 21 ms 11588 KB Output is correct
83 Correct 21 ms 11556 KB Output is correct
84 Correct 22 ms 11552 KB Output is correct
85 Correct 24 ms 11588 KB Output is correct
86 Correct 24 ms 11940 KB Output is correct
87 Correct 23 ms 11928 KB Output is correct
88 Correct 22 ms 11980 KB Output is correct
89 Correct 24 ms 11940 KB Output is correct
90 Correct 23 ms 11972 KB Output is correct
91 Correct 37 ms 14756 KB Output is correct
92 Correct 38 ms 14756 KB Output is correct
93 Correct 43 ms 14752 KB Output is correct
94 Correct 38 ms 14728 KB Output is correct
95 Correct 37 ms 14788 KB Output is correct
96 Correct 50 ms 17436 KB Output is correct
97 Correct 49 ms 17372 KB Output is correct
98 Correct 49 ms 17424 KB Output is correct
99 Correct 49 ms 17404 KB Output is correct
100 Correct 53 ms 17464 KB Output is correct
101 Correct 49 ms 17432 KB Output is correct
102 Correct 49 ms 17420 KB Output is correct
103 Correct 51 ms 17464 KB Output is correct
104 Correct 52 ms 17336 KB Output is correct
105 Correct 56 ms 17372 KB Output is correct
106 Correct 52 ms 18232 KB Output is correct
107 Correct 70 ms 18180 KB Output is correct
108 Correct 51 ms 18232 KB Output is correct
109 Correct 51 ms 18196 KB Output is correct
110 Correct 59 ms 18204 KB Output is correct
111 Correct 57 ms 18208 KB Output is correct
112 Correct 51 ms 18232 KB Output is correct
113 Correct 52 ms 18144 KB Output is correct
114 Correct 56 ms 18196 KB Output is correct
115 Correct 52 ms 18196 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9676 KB Output is correct
2 Correct 5 ms 9676 KB Output is correct
3 Correct 5 ms 9676 KB Output is correct
4 Correct 4 ms 9676 KB Output is correct
5 Correct 4 ms 9648 KB Output is correct
6 Correct 5 ms 9676 KB Output is correct
7 Correct 5 ms 9676 KB Output is correct
8 Correct 4 ms 9676 KB Output is correct
9 Correct 4 ms 9676 KB Output is correct
10 Correct 5 ms 9676 KB Output is correct
11 Correct 4 ms 9676 KB Output is correct
12 Correct 4 ms 9676 KB Output is correct
13 Correct 5 ms 9676 KB Output is correct
14 Correct 10 ms 10512 KB Output is correct
15 Correct 16 ms 11288 KB Output is correct
16 Correct 24 ms 12080 KB Output is correct
17 Correct 26 ms 12080 KB Output is correct
18 Correct 27 ms 11980 KB Output is correct
19 Correct 25 ms 12060 KB Output is correct
20 Correct 26 ms 12076 KB Output is correct
21 Correct 22 ms 12072 KB Output is correct
22 Correct 28 ms 12080 KB Output is correct
23 Correct 27 ms 12072 KB Output is correct
24 Correct 23 ms 12076 KB Output is correct
25 Correct 28 ms 12080 KB Output is correct
26 Correct 6 ms 9676 KB Output is correct
27 Correct 5 ms 9676 KB Output is correct
28 Correct 6 ms 9676 KB Output is correct
29 Correct 11 ms 10444 KB Output is correct
30 Correct 18 ms 11292 KB Output is correct
31 Correct 29 ms 12052 KB Output is correct
32 Correct 24 ms 11980 KB Output is correct
33 Correct 24 ms 12080 KB Output is correct
34 Correct 24 ms 11980 KB Output is correct
35 Correct 31 ms 12068 KB Output is correct
36 Correct 24 ms 11980 KB Output is correct
37 Correct 28 ms 12076 KB Output is correct
38 Correct 27 ms 12076 KB Output is correct
39 Correct 24 ms 12080 KB Output is correct
40 Correct 28 ms 12072 KB Output is correct
41 Correct 4 ms 9676 KB Output is correct
42 Correct 5 ms 9676 KB Output is correct
43 Correct 5 ms 9676 KB Output is correct
44 Correct 5 ms 9676 KB Output is correct
45 Correct 5 ms 9676 KB Output is correct
46 Correct 6 ms 9796 KB Output is correct
47 Correct 10 ms 10136 KB Output is correct
48 Correct 10 ms 10060 KB Output is correct
49 Correct 12 ms 10444 KB Output is correct
50 Correct 21 ms 11212 KB Output is correct
51 Correct 26 ms 11980 KB Output is correct
52 Correct 27 ms 12108 KB Output is correct
53 Correct 34 ms 12052 KB Output is correct
54 Correct 26 ms 12068 KB Output is correct
55 Correct 26 ms 11980 KB Output is correct
56 Correct 26 ms 12076 KB Output is correct
57 Correct 25 ms 12076 KB Output is correct
58 Correct 31 ms 12068 KB Output is correct
59 Correct 27 ms 12084 KB Output is correct
60 Correct 40 ms 12068 KB Output is correct
61 Correct 30 ms 12068 KB Output is correct
62 Correct 30 ms 12060 KB Output is correct
63 Correct 29 ms 12056 KB Output is correct
64 Correct 29 ms 12080 KB Output is correct
65 Correct 27 ms 12076 KB Output is correct
66 Correct 26 ms 12076 KB Output is correct
67 Correct 32 ms 12120 KB Output is correct
68 Correct 26 ms 11980 KB Output is correct
69 Correct 30 ms 12076 KB Output is correct
70 Correct 27 ms 12072 KB Output is correct
71 Correct 8 ms 10188 KB Output is correct
72 Correct 9 ms 10188 KB Output is correct
73 Correct 9 ms 10188 KB Output is correct
74 Correct 10 ms 10188 KB Output is correct
75 Correct 9 ms 10184 KB Output is correct
76 Correct 15 ms 10636 KB Output is correct
77 Correct 15 ms 10704 KB Output is correct
78 Correct 15 ms 10700 KB Output is correct
79 Correct 17 ms 10676 KB Output is correct
80 Correct 13 ms 10588 KB Output is correct
81 Correct 21 ms 11552 KB Output is correct
82 Correct 21 ms 11588 KB Output is correct
83 Correct 21 ms 11556 KB Output is correct
84 Correct 22 ms 11552 KB Output is correct
85 Correct 24 ms 11588 KB Output is correct
86 Correct 24 ms 11940 KB Output is correct
87 Correct 23 ms 11928 KB Output is correct
88 Correct 22 ms 11980 KB Output is correct
89 Correct 24 ms 11940 KB Output is correct
90 Correct 23 ms 11972 KB Output is correct
91 Correct 37 ms 14756 KB Output is correct
92 Correct 38 ms 14756 KB Output is correct
93 Correct 43 ms 14752 KB Output is correct
94 Correct 38 ms 14728 KB Output is correct
95 Correct 37 ms 14788 KB Output is correct
96 Correct 50 ms 17436 KB Output is correct
97 Correct 49 ms 17372 KB Output is correct
98 Correct 49 ms 17424 KB Output is correct
99 Correct 49 ms 17404 KB Output is correct
100 Correct 53 ms 17464 KB Output is correct
101 Correct 49 ms 17432 KB Output is correct
102 Correct 49 ms 17420 KB Output is correct
103 Correct 51 ms 17464 KB Output is correct
104 Correct 52 ms 17336 KB Output is correct
105 Correct 56 ms 17372 KB Output is correct
106 Correct 52 ms 18232 KB Output is correct
107 Correct 70 ms 18180 KB Output is correct
108 Correct 51 ms 18232 KB Output is correct
109 Correct 51 ms 18196 KB Output is correct
110 Correct 59 ms 18204 KB Output is correct
111 Correct 57 ms 18208 KB Output is correct
112 Correct 51 ms 18232 KB Output is correct
113 Correct 52 ms 18144 KB Output is correct
114 Correct 56 ms 18196 KB Output is correct
115 Correct 52 ms 18196 KB Output is correct
116 Runtime error 29 ms 22856 KB Execution killed with signal 11
117 Halted 0 ms 0 KB -