Submission #626043

# Submission time Handle Problem Language Result Execution time Memory
626043 2022-08-11T07:21:50 Z berr Diversity (CEOI21_diversity) C++17
64 / 100
7000 ms 36044 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
vector<int> freq(300005);
set<int> s;
int val(int a, int b, int c)
{
return a*c*(a+(c-1)*b)+b*b*((((c-1)*c*(2*c-1))/6));
}



int get()
{
int k=0, n=0;
int mod=1;
set<int> cur;
int l=0, r=0, ans=0;

for(auto x: s)
{
    int i=x, j=freq[x];
    if(j==0) continue;
    cur.insert(i);
    k+=j;
    n+=(i*j);

}
for(auto x: cur)
{

    int i=x, j=freq[x];
    if(j==0) continue;

    int addleft=(j+mod)/2;
    int addright=j-addleft;

    ans+=val(l, i, addleft);
    ans+=val(n-l-i, -i, addleft);

    ans+=val(r, i, addright);
    ans+=val(n-r-i, -i, addright);

    l+=addleft*i;
    r+=addright*i;
    mod=(j+mod)%2;
}
s=cur;
return (k*n*(n+1)-n*(k-1)-ans)/2;
}



int32_t main()
{
ios_base::sync_with_stdio(false); cin.tie(0);

int n, q, b=550, cnt=0; cin>>n>>q;

vector<int> a(n), ans(q);
vector<array<int, 3>> query[n/b+2];


for(int i=0; i<n; i++) cin>>a[i];

while(q--)
{
    int l, r; cin>>l>>r;
    l--; r--;

    query[l/b].push_back({r, l, ++cnt});
}


int l=0, r=-1;

vector<int> count(3000005);


for(int i=0; i<n/b+1; i++)
{
    sort(query[i].begin(), query[i].end());
    for(auto x: query[i])
    {
        swap(x[0], x[1]);
        while(x[0]>l)
        {
            count[a[l]]--;
            if(count[a[l]]!=0)
            freq[count[a[l]]]++;
            freq[count[a[l]]+1]--;
            if(freq[count[a[l]]]==1&&count[a[l]]!=0) s.insert(count[a[l]]);
            l++;
        }
        while(x[0]<l)
        {
            l--;
            count[a[l]]++;
            freq[count[a[l]]]++;
            if(freq[count[a[l]]-1]>0)
            freq[count[a[l]]-1]--;
            if(freq[count[a[l]]]==1&&count[a[l]]!=0) s.insert(count[a[l]]);

        }
        while(x[1]<r)
        {
            if(count[a[r]]!=0)
            freq[count[a[r]]]--;
            count[a[r]]--;
            freq[count[a[r]]]++;
            if(freq[count[a[r]]]==1&&count[a[r]]!=0) s.insert(count[a[r]]);
            r--;
        }

        while(x[1]>r)
        {
            r++;
            if(count[a[r]]!=0)
            freq[count[a[r]]]--;
            count[a[r]]++;
            freq[count[a[r]]]++;
            if(freq[count[a[r]]]==1&&count[a[r]]!=0) s.insert(count[a[r]]);

        }


        ans[x[2]-1]=get();
    }
}



for(int i=0; i<ans.size(); i++) cout<<ans[i]<<"\n";

}

Compilation message

diversity.cpp: In function 'int32_t main()':
diversity.cpp:133:15: 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]
  133 | for(int i=0; i<ans.size(); i++) cout<<ans[i]<<"\n";
      |              ~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 10 ms 26156 KB Output is correct
2 Correct 12 ms 26076 KB Output is correct
3 Correct 10 ms 26068 KB Output is correct
4 Correct 10 ms 26068 KB Output is correct
5 Correct 10 ms 26128 KB Output is correct
6 Correct 11 ms 26160 KB Output is correct
7 Correct 12 ms 26068 KB Output is correct
8 Correct 13 ms 26056 KB Output is correct
9 Correct 12 ms 26068 KB Output is correct
10 Correct 11 ms 26068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 26068 KB Output is correct
2 Correct 11 ms 26120 KB Output is correct
3 Correct 13 ms 26240 KB Output is correct
4 Correct 26 ms 28152 KB Output is correct
5 Correct 45 ms 31240 KB Output is correct
6 Correct 61 ms 31168 KB Output is correct
7 Correct 76 ms 36044 KB Output is correct
8 Correct 60 ms 30888 KB Output is correct
9 Correct 61 ms 31020 KB Output is correct
10 Correct 71 ms 33100 KB Output is correct
11 Correct 61 ms 31780 KB Output is correct
12 Correct 63 ms 30976 KB Output is correct
13 Correct 72 ms 30824 KB Output is correct
14 Correct 66 ms 32020 KB Output is correct
15 Correct 62 ms 31680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 26068 KB Output is correct
2 Correct 11 ms 26120 KB Output is correct
3 Correct 13 ms 26240 KB Output is correct
4 Correct 26 ms 28152 KB Output is correct
5 Correct 45 ms 31240 KB Output is correct
6 Correct 61 ms 31168 KB Output is correct
7 Correct 76 ms 36044 KB Output is correct
8 Correct 60 ms 30888 KB Output is correct
9 Correct 61 ms 31020 KB Output is correct
10 Correct 71 ms 33100 KB Output is correct
11 Correct 61 ms 31780 KB Output is correct
12 Correct 63 ms 30976 KB Output is correct
13 Correct 72 ms 30824 KB Output is correct
14 Correct 66 ms 32020 KB Output is correct
15 Correct 62 ms 31680 KB Output is correct
16 Correct 11 ms 26072 KB Output is correct
17 Correct 11 ms 26056 KB Output is correct
18 Correct 12 ms 26196 KB Output is correct
19 Correct 28 ms 27760 KB Output is correct
20 Correct 41 ms 29108 KB Output is correct
21 Correct 62 ms 31176 KB Output is correct
22 Correct 59 ms 30252 KB Output is correct
23 Correct 61 ms 30884 KB Output is correct
24 Correct 59 ms 30136 KB Output is correct
25 Correct 56 ms 30412 KB Output is correct
26 Correct 63 ms 30300 KB Output is correct
27 Correct 59 ms 30564 KB Output is correct
28 Correct 66 ms 32168 KB Output is correct
29 Correct 70 ms 30392 KB Output is correct
30 Correct 56 ms 30516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 26068 KB Output is correct
2 Correct 11 ms 26120 KB Output is correct
3 Correct 13 ms 26240 KB Output is correct
4 Correct 26 ms 28152 KB Output is correct
5 Correct 45 ms 31240 KB Output is correct
6 Correct 61 ms 31168 KB Output is correct
7 Correct 76 ms 36044 KB Output is correct
8 Correct 60 ms 30888 KB Output is correct
9 Correct 61 ms 31020 KB Output is correct
10 Correct 71 ms 33100 KB Output is correct
11 Correct 61 ms 31780 KB Output is correct
12 Correct 63 ms 30976 KB Output is correct
13 Correct 72 ms 30824 KB Output is correct
14 Correct 66 ms 32020 KB Output is correct
15 Correct 62 ms 31680 KB Output is correct
16 Correct 11 ms 26072 KB Output is correct
17 Correct 11 ms 26056 KB Output is correct
18 Correct 12 ms 26196 KB Output is correct
19 Correct 28 ms 27760 KB Output is correct
20 Correct 41 ms 29108 KB Output is correct
21 Correct 62 ms 31176 KB Output is correct
22 Correct 59 ms 30252 KB Output is correct
23 Correct 61 ms 30884 KB Output is correct
24 Correct 59 ms 30136 KB Output is correct
25 Correct 56 ms 30412 KB Output is correct
26 Correct 63 ms 30300 KB Output is correct
27 Correct 59 ms 30564 KB Output is correct
28 Correct 66 ms 32168 KB Output is correct
29 Correct 70 ms 30392 KB Output is correct
30 Correct 56 ms 30516 KB Output is correct
31 Correct 10 ms 26068 KB Output is correct
32 Correct 11 ms 26068 KB Output is correct
33 Correct 11 ms 26056 KB Output is correct
34 Correct 15 ms 26196 KB Output is correct
35 Correct 12 ms 26196 KB Output is correct
36 Correct 13 ms 26224 KB Output is correct
37 Correct 16 ms 26580 KB Output is correct
38 Correct 15 ms 26580 KB Output is correct
39 Correct 18 ms 26964 KB Output is correct
40 Correct 29 ms 27776 KB Output is correct
41 Correct 37 ms 28588 KB Output is correct
42 Correct 38 ms 28564 KB Output is correct
43 Correct 38 ms 28624 KB Output is correct
44 Correct 39 ms 28584 KB Output is correct
45 Correct 41 ms 28572 KB Output is correct
46 Correct 45 ms 28580 KB Output is correct
47 Correct 38 ms 28576 KB Output is correct
48 Correct 43 ms 28580 KB Output is correct
49 Correct 42 ms 28568 KB Output is correct
50 Correct 39 ms 28580 KB Output is correct
51 Correct 38 ms 28628 KB Output is correct
52 Correct 37 ms 28584 KB Output is correct
53 Correct 37 ms 28620 KB Output is correct
54 Correct 38 ms 28608 KB Output is correct
55 Correct 37 ms 28524 KB Output is correct
56 Correct 40 ms 28620 KB Output is correct
57 Correct 36 ms 28580 KB Output is correct
58 Correct 45 ms 28492 KB Output is correct
59 Correct 48 ms 28576 KB Output is correct
60 Correct 40 ms 28584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 26156 KB Output is correct
2 Correct 12 ms 26076 KB Output is correct
3 Correct 10 ms 26068 KB Output is correct
4 Correct 10 ms 26068 KB Output is correct
5 Correct 10 ms 26128 KB Output is correct
6 Correct 11 ms 26160 KB Output is correct
7 Correct 12 ms 26068 KB Output is correct
8 Correct 13 ms 26056 KB Output is correct
9 Correct 12 ms 26068 KB Output is correct
10 Correct 11 ms 26068 KB Output is correct
11 Correct 11 ms 26068 KB Output is correct
12 Correct 11 ms 26120 KB Output is correct
13 Correct 13 ms 26240 KB Output is correct
14 Correct 26 ms 28152 KB Output is correct
15 Correct 45 ms 31240 KB Output is correct
16 Correct 61 ms 31168 KB Output is correct
17 Correct 76 ms 36044 KB Output is correct
18 Correct 60 ms 30888 KB Output is correct
19 Correct 61 ms 31020 KB Output is correct
20 Correct 71 ms 33100 KB Output is correct
21 Correct 61 ms 31780 KB Output is correct
22 Correct 63 ms 30976 KB Output is correct
23 Correct 72 ms 30824 KB Output is correct
24 Correct 66 ms 32020 KB Output is correct
25 Correct 62 ms 31680 KB Output is correct
26 Correct 11 ms 26072 KB Output is correct
27 Correct 11 ms 26056 KB Output is correct
28 Correct 12 ms 26196 KB Output is correct
29 Correct 28 ms 27760 KB Output is correct
30 Correct 41 ms 29108 KB Output is correct
31 Correct 62 ms 31176 KB Output is correct
32 Correct 59 ms 30252 KB Output is correct
33 Correct 61 ms 30884 KB Output is correct
34 Correct 59 ms 30136 KB Output is correct
35 Correct 56 ms 30412 KB Output is correct
36 Correct 63 ms 30300 KB Output is correct
37 Correct 59 ms 30564 KB Output is correct
38 Correct 66 ms 32168 KB Output is correct
39 Correct 70 ms 30392 KB Output is correct
40 Correct 56 ms 30516 KB Output is correct
41 Correct 10 ms 26068 KB Output is correct
42 Correct 11 ms 26068 KB Output is correct
43 Correct 11 ms 26056 KB Output is correct
44 Correct 15 ms 26196 KB Output is correct
45 Correct 12 ms 26196 KB Output is correct
46 Correct 13 ms 26224 KB Output is correct
47 Correct 16 ms 26580 KB Output is correct
48 Correct 15 ms 26580 KB Output is correct
49 Correct 18 ms 26964 KB Output is correct
50 Correct 29 ms 27776 KB Output is correct
51 Correct 37 ms 28588 KB Output is correct
52 Correct 38 ms 28564 KB Output is correct
53 Correct 38 ms 28624 KB Output is correct
54 Correct 39 ms 28584 KB Output is correct
55 Correct 41 ms 28572 KB Output is correct
56 Correct 45 ms 28580 KB Output is correct
57 Correct 38 ms 28576 KB Output is correct
58 Correct 43 ms 28580 KB Output is correct
59 Correct 42 ms 28568 KB Output is correct
60 Correct 39 ms 28580 KB Output is correct
61 Correct 38 ms 28628 KB Output is correct
62 Correct 37 ms 28584 KB Output is correct
63 Correct 37 ms 28620 KB Output is correct
64 Correct 38 ms 28608 KB Output is correct
65 Correct 37 ms 28524 KB Output is correct
66 Correct 40 ms 28620 KB Output is correct
67 Correct 36 ms 28580 KB Output is correct
68 Correct 45 ms 28492 KB Output is correct
69 Correct 48 ms 28576 KB Output is correct
70 Correct 40 ms 28584 KB Output is correct
71 Correct 14 ms 26496 KB Output is correct
72 Correct 15 ms 26452 KB Output is correct
73 Correct 14 ms 26492 KB Output is correct
74 Correct 14 ms 26536 KB Output is correct
75 Correct 14 ms 26452 KB Output is correct
76 Correct 19 ms 26888 KB Output is correct
77 Correct 19 ms 26836 KB Output is correct
78 Correct 18 ms 26936 KB Output is correct
79 Correct 18 ms 26852 KB Output is correct
80 Correct 18 ms 26888 KB Output is correct
81 Correct 26 ms 27664 KB Output is correct
82 Correct 28 ms 27732 KB Output is correct
83 Correct 26 ms 27680 KB Output is correct
84 Correct 26 ms 27680 KB Output is correct
85 Correct 27 ms 27608 KB Output is correct
86 Correct 28 ms 27668 KB Output is correct
87 Correct 32 ms 27724 KB Output is correct
88 Correct 30 ms 27732 KB Output is correct
89 Correct 33 ms 27672 KB Output is correct
90 Correct 33 ms 27664 KB Output is correct
91 Correct 38 ms 28492 KB Output is correct
92 Correct 37 ms 28452 KB Output is correct
93 Correct 40 ms 28440 KB Output is correct
94 Correct 38 ms 28452 KB Output is correct
95 Correct 37 ms 28404 KB Output is correct
96 Correct 41 ms 28496 KB Output is correct
97 Correct 46 ms 28392 KB Output is correct
98 Correct 42 ms 28412 KB Output is correct
99 Correct 41 ms 28492 KB Output is correct
100 Correct 43 ms 28452 KB Output is correct
101 Correct 49 ms 28444 KB Output is correct
102 Correct 43 ms 28500 KB Output is correct
103 Correct 52 ms 28456 KB Output is correct
104 Correct 49 ms 28464 KB Output is correct
105 Correct 43 ms 28452 KB Output is correct
106 Correct 43 ms 28412 KB Output is correct
107 Correct 42 ms 28492 KB Output is correct
108 Correct 43 ms 28448 KB Output is correct
109 Correct 43 ms 28508 KB Output is correct
110 Correct 44 ms 28500 KB Output is correct
111 Correct 43 ms 28508 KB Output is correct
112 Correct 45 ms 28500 KB Output is correct
113 Correct 41 ms 28444 KB Output is correct
114 Correct 43 ms 28452 KB Output is correct
115 Correct 44 ms 28492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 26156 KB Output is correct
2 Correct 12 ms 26076 KB Output is correct
3 Correct 10 ms 26068 KB Output is correct
4 Correct 10 ms 26068 KB Output is correct
5 Correct 10 ms 26128 KB Output is correct
6 Correct 11 ms 26160 KB Output is correct
7 Correct 12 ms 26068 KB Output is correct
8 Correct 13 ms 26056 KB Output is correct
9 Correct 12 ms 26068 KB Output is correct
10 Correct 11 ms 26068 KB Output is correct
11 Correct 11 ms 26068 KB Output is correct
12 Correct 11 ms 26120 KB Output is correct
13 Correct 13 ms 26240 KB Output is correct
14 Correct 26 ms 28152 KB Output is correct
15 Correct 45 ms 31240 KB Output is correct
16 Correct 61 ms 31168 KB Output is correct
17 Correct 76 ms 36044 KB Output is correct
18 Correct 60 ms 30888 KB Output is correct
19 Correct 61 ms 31020 KB Output is correct
20 Correct 71 ms 33100 KB Output is correct
21 Correct 61 ms 31780 KB Output is correct
22 Correct 63 ms 30976 KB Output is correct
23 Correct 72 ms 30824 KB Output is correct
24 Correct 66 ms 32020 KB Output is correct
25 Correct 62 ms 31680 KB Output is correct
26 Correct 11 ms 26072 KB Output is correct
27 Correct 11 ms 26056 KB Output is correct
28 Correct 12 ms 26196 KB Output is correct
29 Correct 28 ms 27760 KB Output is correct
30 Correct 41 ms 29108 KB Output is correct
31 Correct 62 ms 31176 KB Output is correct
32 Correct 59 ms 30252 KB Output is correct
33 Correct 61 ms 30884 KB Output is correct
34 Correct 59 ms 30136 KB Output is correct
35 Correct 56 ms 30412 KB Output is correct
36 Correct 63 ms 30300 KB Output is correct
37 Correct 59 ms 30564 KB Output is correct
38 Correct 66 ms 32168 KB Output is correct
39 Correct 70 ms 30392 KB Output is correct
40 Correct 56 ms 30516 KB Output is correct
41 Correct 10 ms 26068 KB Output is correct
42 Correct 11 ms 26068 KB Output is correct
43 Correct 11 ms 26056 KB Output is correct
44 Correct 15 ms 26196 KB Output is correct
45 Correct 12 ms 26196 KB Output is correct
46 Correct 13 ms 26224 KB Output is correct
47 Correct 16 ms 26580 KB Output is correct
48 Correct 15 ms 26580 KB Output is correct
49 Correct 18 ms 26964 KB Output is correct
50 Correct 29 ms 27776 KB Output is correct
51 Correct 37 ms 28588 KB Output is correct
52 Correct 38 ms 28564 KB Output is correct
53 Correct 38 ms 28624 KB Output is correct
54 Correct 39 ms 28584 KB Output is correct
55 Correct 41 ms 28572 KB Output is correct
56 Correct 45 ms 28580 KB Output is correct
57 Correct 38 ms 28576 KB Output is correct
58 Correct 43 ms 28580 KB Output is correct
59 Correct 42 ms 28568 KB Output is correct
60 Correct 39 ms 28580 KB Output is correct
61 Correct 38 ms 28628 KB Output is correct
62 Correct 37 ms 28584 KB Output is correct
63 Correct 37 ms 28620 KB Output is correct
64 Correct 38 ms 28608 KB Output is correct
65 Correct 37 ms 28524 KB Output is correct
66 Correct 40 ms 28620 KB Output is correct
67 Correct 36 ms 28580 KB Output is correct
68 Correct 45 ms 28492 KB Output is correct
69 Correct 48 ms 28576 KB Output is correct
70 Correct 40 ms 28584 KB Output is correct
71 Correct 14 ms 26496 KB Output is correct
72 Correct 15 ms 26452 KB Output is correct
73 Correct 14 ms 26492 KB Output is correct
74 Correct 14 ms 26536 KB Output is correct
75 Correct 14 ms 26452 KB Output is correct
76 Correct 19 ms 26888 KB Output is correct
77 Correct 19 ms 26836 KB Output is correct
78 Correct 18 ms 26936 KB Output is correct
79 Correct 18 ms 26852 KB Output is correct
80 Correct 18 ms 26888 KB Output is correct
81 Correct 26 ms 27664 KB Output is correct
82 Correct 28 ms 27732 KB Output is correct
83 Correct 26 ms 27680 KB Output is correct
84 Correct 26 ms 27680 KB Output is correct
85 Correct 27 ms 27608 KB Output is correct
86 Correct 28 ms 27668 KB Output is correct
87 Correct 32 ms 27724 KB Output is correct
88 Correct 30 ms 27732 KB Output is correct
89 Correct 33 ms 27672 KB Output is correct
90 Correct 33 ms 27664 KB Output is correct
91 Correct 38 ms 28492 KB Output is correct
92 Correct 37 ms 28452 KB Output is correct
93 Correct 40 ms 28440 KB Output is correct
94 Correct 38 ms 28452 KB Output is correct
95 Correct 37 ms 28404 KB Output is correct
96 Correct 41 ms 28496 KB Output is correct
97 Correct 46 ms 28392 KB Output is correct
98 Correct 42 ms 28412 KB Output is correct
99 Correct 41 ms 28492 KB Output is correct
100 Correct 43 ms 28452 KB Output is correct
101 Correct 49 ms 28444 KB Output is correct
102 Correct 43 ms 28500 KB Output is correct
103 Correct 52 ms 28456 KB Output is correct
104 Correct 49 ms 28464 KB Output is correct
105 Correct 43 ms 28452 KB Output is correct
106 Correct 43 ms 28412 KB Output is correct
107 Correct 42 ms 28492 KB Output is correct
108 Correct 43 ms 28448 KB Output is correct
109 Correct 43 ms 28508 KB Output is correct
110 Correct 44 ms 28500 KB Output is correct
111 Correct 43 ms 28508 KB Output is correct
112 Correct 45 ms 28500 KB Output is correct
113 Correct 41 ms 28444 KB Output is correct
114 Correct 43 ms 28452 KB Output is correct
115 Correct 44 ms 28492 KB Output is correct
116 Correct 913 ms 28724 KB Output is correct
117 Correct 725 ms 28748 KB Output is correct
118 Correct 1554 ms 29136 KB Output is correct
119 Correct 942 ms 29192 KB Output is correct
120 Correct 643 ms 29060 KB Output is correct
121 Correct 1370 ms 29684 KB Output is correct
122 Correct 941 ms 29616 KB Output is correct
123 Correct 3793 ms 30612 KB Output is correct
124 Correct 1780 ms 30644 KB Output is correct
125 Correct 1503 ms 30592 KB Output is correct
126 Execution timed out 7063 ms 30988 KB Time limit exceeded
127 Halted 0 ms 0 KB -