Submission #626030

# Submission time Handle Problem Language Result Execution time Memory
626030 2022-08-11T06:46:55 Z berr Diversity (CEOI21_diversity) C++17
64 / 100
7000 ms 43824 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
map<int, int> freq;
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:19: 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 23764 KB Output is correct
2 Correct 10 ms 23808 KB Output is correct
3 Correct 11 ms 23764 KB Output is correct
4 Correct 10 ms 23764 KB Output is correct
5 Correct 10 ms 23792 KB Output is correct
6 Correct 11 ms 23764 KB Output is correct
7 Correct 10 ms 23724 KB Output is correct
8 Correct 10 ms 23748 KB Output is correct
9 Correct 10 ms 23736 KB Output is correct
10 Correct 10 ms 23764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 23764 KB Output is correct
2 Correct 11 ms 23764 KB Output is correct
3 Correct 13 ms 24148 KB Output is correct
4 Correct 56 ms 27460 KB Output is correct
5 Correct 102 ms 33584 KB Output is correct
6 Correct 140 ms 32600 KB Output is correct
7 Correct 193 ms 43824 KB Output is correct
8 Correct 145 ms 31664 KB Output is correct
9 Correct 140 ms 32296 KB Output is correct
10 Correct 154 ms 37136 KB Output is correct
11 Correct 143 ms 33996 KB Output is correct
12 Correct 137 ms 32000 KB Output is correct
13 Correct 137 ms 31528 KB Output is correct
14 Correct 139 ms 34588 KB Output is correct
15 Correct 134 ms 33728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 23764 KB Output is correct
2 Correct 11 ms 23764 KB Output is correct
3 Correct 13 ms 24148 KB Output is correct
4 Correct 56 ms 27460 KB Output is correct
5 Correct 102 ms 33584 KB Output is correct
6 Correct 140 ms 32600 KB Output is correct
7 Correct 193 ms 43824 KB Output is correct
8 Correct 145 ms 31664 KB Output is correct
9 Correct 140 ms 32296 KB Output is correct
10 Correct 154 ms 37136 KB Output is correct
11 Correct 143 ms 33996 KB Output is correct
12 Correct 137 ms 32000 KB Output is correct
13 Correct 137 ms 31528 KB Output is correct
14 Correct 139 ms 34588 KB Output is correct
15 Correct 134 ms 33728 KB Output is correct
16 Correct 10 ms 23736 KB Output is correct
17 Correct 10 ms 23764 KB Output is correct
18 Correct 12 ms 23936 KB Output is correct
19 Correct 45 ms 26444 KB Output is correct
20 Correct 83 ms 28660 KB Output is correct
21 Correct 134 ms 32608 KB Output is correct
22 Correct 126 ms 30448 KB Output is correct
23 Correct 139 ms 31664 KB Output is correct
24 Correct 150 ms 29984 KB Output is correct
25 Correct 120 ms 30844 KB Output is correct
26 Correct 120 ms 30412 KB Output is correct
27 Correct 136 ms 31188 KB Output is correct
28 Correct 142 ms 34672 KB Output is correct
29 Correct 128 ms 30732 KB Output is correct
30 Correct 120 ms 30956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 23764 KB Output is correct
2 Correct 11 ms 23764 KB Output is correct
3 Correct 13 ms 24148 KB Output is correct
4 Correct 56 ms 27460 KB Output is correct
5 Correct 102 ms 33584 KB Output is correct
6 Correct 140 ms 32600 KB Output is correct
7 Correct 193 ms 43824 KB Output is correct
8 Correct 145 ms 31664 KB Output is correct
9 Correct 140 ms 32296 KB Output is correct
10 Correct 154 ms 37136 KB Output is correct
11 Correct 143 ms 33996 KB Output is correct
12 Correct 137 ms 32000 KB Output is correct
13 Correct 137 ms 31528 KB Output is correct
14 Correct 139 ms 34588 KB Output is correct
15 Correct 134 ms 33728 KB Output is correct
16 Correct 10 ms 23736 KB Output is correct
17 Correct 10 ms 23764 KB Output is correct
18 Correct 12 ms 23936 KB Output is correct
19 Correct 45 ms 26444 KB Output is correct
20 Correct 83 ms 28660 KB Output is correct
21 Correct 134 ms 32608 KB Output is correct
22 Correct 126 ms 30448 KB Output is correct
23 Correct 139 ms 31664 KB Output is correct
24 Correct 150 ms 29984 KB Output is correct
25 Correct 120 ms 30844 KB Output is correct
26 Correct 120 ms 30412 KB Output is correct
27 Correct 136 ms 31188 KB Output is correct
28 Correct 142 ms 34672 KB Output is correct
29 Correct 128 ms 30732 KB Output is correct
30 Correct 120 ms 30956 KB Output is correct
31 Correct 10 ms 23764 KB Output is correct
32 Correct 10 ms 23764 KB Output is correct
33 Correct 10 ms 23824 KB Output is correct
34 Correct 15 ms 23892 KB Output is correct
35 Correct 12 ms 23892 KB Output is correct
36 Correct 12 ms 23892 KB Output is correct
37 Correct 18 ms 24260 KB Output is correct
38 Correct 21 ms 24240 KB Output is correct
39 Correct 30 ms 24608 KB Output is correct
40 Correct 52 ms 25508 KB Output is correct
41 Correct 68 ms 26284 KB Output is correct
42 Correct 67 ms 26356 KB Output is correct
43 Correct 67 ms 26404 KB Output is correct
44 Correct 68 ms 26360 KB Output is correct
45 Correct 74 ms 26332 KB Output is correct
46 Correct 68 ms 26316 KB Output is correct
47 Correct 67 ms 26364 KB Output is correct
48 Correct 66 ms 26360 KB Output is correct
49 Correct 67 ms 26328 KB Output is correct
50 Correct 68 ms 26352 KB Output is correct
51 Correct 83 ms 26456 KB Output is correct
52 Correct 75 ms 26412 KB Output is correct
53 Correct 68 ms 26300 KB Output is correct
54 Correct 68 ms 26328 KB Output is correct
55 Correct 68 ms 26348 KB Output is correct
56 Correct 67 ms 26360 KB Output is correct
57 Correct 67 ms 26368 KB Output is correct
58 Correct 68 ms 26324 KB Output is correct
59 Correct 71 ms 26384 KB Output is correct
60 Correct 70 ms 26364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 23764 KB Output is correct
2 Correct 10 ms 23808 KB Output is correct
3 Correct 11 ms 23764 KB Output is correct
4 Correct 10 ms 23764 KB Output is correct
5 Correct 10 ms 23792 KB Output is correct
6 Correct 11 ms 23764 KB Output is correct
7 Correct 10 ms 23724 KB Output is correct
8 Correct 10 ms 23748 KB Output is correct
9 Correct 10 ms 23736 KB Output is correct
10 Correct 10 ms 23764 KB Output is correct
11 Correct 10 ms 23764 KB Output is correct
12 Correct 11 ms 23764 KB Output is correct
13 Correct 13 ms 24148 KB Output is correct
14 Correct 56 ms 27460 KB Output is correct
15 Correct 102 ms 33584 KB Output is correct
16 Correct 140 ms 32600 KB Output is correct
17 Correct 193 ms 43824 KB Output is correct
18 Correct 145 ms 31664 KB Output is correct
19 Correct 140 ms 32296 KB Output is correct
20 Correct 154 ms 37136 KB Output is correct
21 Correct 143 ms 33996 KB Output is correct
22 Correct 137 ms 32000 KB Output is correct
23 Correct 137 ms 31528 KB Output is correct
24 Correct 139 ms 34588 KB Output is correct
25 Correct 134 ms 33728 KB Output is correct
26 Correct 10 ms 23736 KB Output is correct
27 Correct 10 ms 23764 KB Output is correct
28 Correct 12 ms 23936 KB Output is correct
29 Correct 45 ms 26444 KB Output is correct
30 Correct 83 ms 28660 KB Output is correct
31 Correct 134 ms 32608 KB Output is correct
32 Correct 126 ms 30448 KB Output is correct
33 Correct 139 ms 31664 KB Output is correct
34 Correct 150 ms 29984 KB Output is correct
35 Correct 120 ms 30844 KB Output is correct
36 Correct 120 ms 30412 KB Output is correct
37 Correct 136 ms 31188 KB Output is correct
38 Correct 142 ms 34672 KB Output is correct
39 Correct 128 ms 30732 KB Output is correct
40 Correct 120 ms 30956 KB Output is correct
41 Correct 10 ms 23764 KB Output is correct
42 Correct 10 ms 23764 KB Output is correct
43 Correct 10 ms 23824 KB Output is correct
44 Correct 15 ms 23892 KB Output is correct
45 Correct 12 ms 23892 KB Output is correct
46 Correct 12 ms 23892 KB Output is correct
47 Correct 18 ms 24260 KB Output is correct
48 Correct 21 ms 24240 KB Output is correct
49 Correct 30 ms 24608 KB Output is correct
50 Correct 52 ms 25508 KB Output is correct
51 Correct 68 ms 26284 KB Output is correct
52 Correct 67 ms 26356 KB Output is correct
53 Correct 67 ms 26404 KB Output is correct
54 Correct 68 ms 26360 KB Output is correct
55 Correct 74 ms 26332 KB Output is correct
56 Correct 68 ms 26316 KB Output is correct
57 Correct 67 ms 26364 KB Output is correct
58 Correct 66 ms 26360 KB Output is correct
59 Correct 67 ms 26328 KB Output is correct
60 Correct 68 ms 26352 KB Output is correct
61 Correct 83 ms 26456 KB Output is correct
62 Correct 75 ms 26412 KB Output is correct
63 Correct 68 ms 26300 KB Output is correct
64 Correct 68 ms 26328 KB Output is correct
65 Correct 68 ms 26348 KB Output is correct
66 Correct 67 ms 26360 KB Output is correct
67 Correct 67 ms 26368 KB Output is correct
68 Correct 68 ms 26324 KB Output is correct
69 Correct 71 ms 26384 KB Output is correct
70 Correct 70 ms 26364 KB Output is correct
71 Correct 16 ms 24156 KB Output is correct
72 Correct 16 ms 24148 KB Output is correct
73 Correct 16 ms 24188 KB Output is correct
74 Correct 16 ms 24116 KB Output is correct
75 Correct 16 ms 24208 KB Output is correct
76 Correct 22 ms 24540 KB Output is correct
77 Correct 22 ms 24528 KB Output is correct
78 Correct 22 ms 24704 KB Output is correct
79 Correct 21 ms 24604 KB Output is correct
80 Correct 22 ms 24532 KB Output is correct
81 Correct 38 ms 25380 KB Output is correct
82 Correct 39 ms 25320 KB Output is correct
83 Correct 32 ms 25300 KB Output is correct
84 Correct 32 ms 25396 KB Output is correct
85 Correct 34 ms 25456 KB Output is correct
86 Correct 32 ms 25300 KB Output is correct
87 Correct 31 ms 25300 KB Output is correct
88 Correct 31 ms 25372 KB Output is correct
89 Correct 32 ms 25372 KB Output is correct
90 Correct 31 ms 25292 KB Output is correct
91 Correct 43 ms 26040 KB Output is correct
92 Correct 48 ms 26116 KB Output is correct
93 Correct 39 ms 26112 KB Output is correct
94 Correct 40 ms 26144 KB Output is correct
95 Correct 38 ms 26068 KB Output is correct
96 Correct 39 ms 26148 KB Output is correct
97 Correct 40 ms 26156 KB Output is correct
98 Correct 38 ms 26136 KB Output is correct
99 Correct 41 ms 26108 KB Output is correct
100 Correct 40 ms 26060 KB Output is correct
101 Correct 39 ms 26064 KB Output is correct
102 Correct 42 ms 26104 KB Output is correct
103 Correct 39 ms 26060 KB Output is correct
104 Correct 39 ms 26068 KB Output is correct
105 Correct 38 ms 26112 KB Output is correct
106 Correct 37 ms 26112 KB Output is correct
107 Correct 37 ms 26068 KB Output is correct
108 Correct 37 ms 26060 KB Output is correct
109 Correct 37 ms 26108 KB Output is correct
110 Correct 38 ms 26092 KB Output is correct
111 Correct 39 ms 26112 KB Output is correct
112 Correct 38 ms 26120 KB Output is correct
113 Correct 37 ms 26228 KB Output is correct
114 Correct 37 ms 26060 KB Output is correct
115 Correct 37 ms 26116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 23764 KB Output is correct
2 Correct 10 ms 23808 KB Output is correct
3 Correct 11 ms 23764 KB Output is correct
4 Correct 10 ms 23764 KB Output is correct
5 Correct 10 ms 23792 KB Output is correct
6 Correct 11 ms 23764 KB Output is correct
7 Correct 10 ms 23724 KB Output is correct
8 Correct 10 ms 23748 KB Output is correct
9 Correct 10 ms 23736 KB Output is correct
10 Correct 10 ms 23764 KB Output is correct
11 Correct 10 ms 23764 KB Output is correct
12 Correct 11 ms 23764 KB Output is correct
13 Correct 13 ms 24148 KB Output is correct
14 Correct 56 ms 27460 KB Output is correct
15 Correct 102 ms 33584 KB Output is correct
16 Correct 140 ms 32600 KB Output is correct
17 Correct 193 ms 43824 KB Output is correct
18 Correct 145 ms 31664 KB Output is correct
19 Correct 140 ms 32296 KB Output is correct
20 Correct 154 ms 37136 KB Output is correct
21 Correct 143 ms 33996 KB Output is correct
22 Correct 137 ms 32000 KB Output is correct
23 Correct 137 ms 31528 KB Output is correct
24 Correct 139 ms 34588 KB Output is correct
25 Correct 134 ms 33728 KB Output is correct
26 Correct 10 ms 23736 KB Output is correct
27 Correct 10 ms 23764 KB Output is correct
28 Correct 12 ms 23936 KB Output is correct
29 Correct 45 ms 26444 KB Output is correct
30 Correct 83 ms 28660 KB Output is correct
31 Correct 134 ms 32608 KB Output is correct
32 Correct 126 ms 30448 KB Output is correct
33 Correct 139 ms 31664 KB Output is correct
34 Correct 150 ms 29984 KB Output is correct
35 Correct 120 ms 30844 KB Output is correct
36 Correct 120 ms 30412 KB Output is correct
37 Correct 136 ms 31188 KB Output is correct
38 Correct 142 ms 34672 KB Output is correct
39 Correct 128 ms 30732 KB Output is correct
40 Correct 120 ms 30956 KB Output is correct
41 Correct 10 ms 23764 KB Output is correct
42 Correct 10 ms 23764 KB Output is correct
43 Correct 10 ms 23824 KB Output is correct
44 Correct 15 ms 23892 KB Output is correct
45 Correct 12 ms 23892 KB Output is correct
46 Correct 12 ms 23892 KB Output is correct
47 Correct 18 ms 24260 KB Output is correct
48 Correct 21 ms 24240 KB Output is correct
49 Correct 30 ms 24608 KB Output is correct
50 Correct 52 ms 25508 KB Output is correct
51 Correct 68 ms 26284 KB Output is correct
52 Correct 67 ms 26356 KB Output is correct
53 Correct 67 ms 26404 KB Output is correct
54 Correct 68 ms 26360 KB Output is correct
55 Correct 74 ms 26332 KB Output is correct
56 Correct 68 ms 26316 KB Output is correct
57 Correct 67 ms 26364 KB Output is correct
58 Correct 66 ms 26360 KB Output is correct
59 Correct 67 ms 26328 KB Output is correct
60 Correct 68 ms 26352 KB Output is correct
61 Correct 83 ms 26456 KB Output is correct
62 Correct 75 ms 26412 KB Output is correct
63 Correct 68 ms 26300 KB Output is correct
64 Correct 68 ms 26328 KB Output is correct
65 Correct 68 ms 26348 KB Output is correct
66 Correct 67 ms 26360 KB Output is correct
67 Correct 67 ms 26368 KB Output is correct
68 Correct 68 ms 26324 KB Output is correct
69 Correct 71 ms 26384 KB Output is correct
70 Correct 70 ms 26364 KB Output is correct
71 Correct 16 ms 24156 KB Output is correct
72 Correct 16 ms 24148 KB Output is correct
73 Correct 16 ms 24188 KB Output is correct
74 Correct 16 ms 24116 KB Output is correct
75 Correct 16 ms 24208 KB Output is correct
76 Correct 22 ms 24540 KB Output is correct
77 Correct 22 ms 24528 KB Output is correct
78 Correct 22 ms 24704 KB Output is correct
79 Correct 21 ms 24604 KB Output is correct
80 Correct 22 ms 24532 KB Output is correct
81 Correct 38 ms 25380 KB Output is correct
82 Correct 39 ms 25320 KB Output is correct
83 Correct 32 ms 25300 KB Output is correct
84 Correct 32 ms 25396 KB Output is correct
85 Correct 34 ms 25456 KB Output is correct
86 Correct 32 ms 25300 KB Output is correct
87 Correct 31 ms 25300 KB Output is correct
88 Correct 31 ms 25372 KB Output is correct
89 Correct 32 ms 25372 KB Output is correct
90 Correct 31 ms 25292 KB Output is correct
91 Correct 43 ms 26040 KB Output is correct
92 Correct 48 ms 26116 KB Output is correct
93 Correct 39 ms 26112 KB Output is correct
94 Correct 40 ms 26144 KB Output is correct
95 Correct 38 ms 26068 KB Output is correct
96 Correct 39 ms 26148 KB Output is correct
97 Correct 40 ms 26156 KB Output is correct
98 Correct 38 ms 26136 KB Output is correct
99 Correct 41 ms 26108 KB Output is correct
100 Correct 40 ms 26060 KB Output is correct
101 Correct 39 ms 26064 KB Output is correct
102 Correct 42 ms 26104 KB Output is correct
103 Correct 39 ms 26060 KB Output is correct
104 Correct 39 ms 26068 KB Output is correct
105 Correct 38 ms 26112 KB Output is correct
106 Correct 37 ms 26112 KB Output is correct
107 Correct 37 ms 26068 KB Output is correct
108 Correct 37 ms 26060 KB Output is correct
109 Correct 37 ms 26108 KB Output is correct
110 Correct 38 ms 26092 KB Output is correct
111 Correct 39 ms 26112 KB Output is correct
112 Correct 38 ms 26120 KB Output is correct
113 Correct 37 ms 26228 KB Output is correct
114 Correct 37 ms 26060 KB Output is correct
115 Correct 37 ms 26116 KB Output is correct
116 Correct 2282 ms 26440 KB Output is correct
117 Correct 1848 ms 26432 KB Output is correct
118 Correct 4437 ms 26884 KB Output is correct
119 Correct 2685 ms 26740 KB Output is correct
120 Correct 1914 ms 26716 KB Output is correct
121 Correct 4260 ms 27340 KB Output is correct
122 Correct 2978 ms 27268 KB Output is correct
123 Execution timed out 7046 ms 27528 KB Time limit exceeded
124 Halted 0 ms 0 KB -