Submission #626000

# Submission time Handle Problem Language Result Execution time Memory
626000 2022-08-11T06:08:22 Z berr Diversity (CEOI21_diversity) C++17
64 / 100
7000 ms 36260 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
map<int, int> freq;

int val(int a, int b, int c)
{
   return a*c*(a+(c-1)*b)+b*b*((((c-1)*c*(2*c-1))/6LL));
}


int get()
{
    int n=0, k=0;
    vector<array<int, 2>>s;
    for(auto [i, l]: freq)
    {
        if(l<=0) continue;
        n+=i*l;
        k+=l;
        s.push_back({i, l});
    }

    int mod=1;

    int l=0, r=0, ans=0;

    for(auto x: s)
    {
        int i=x[0], j=x[1];

        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;
    }
    return (k*n*(n+1)-n*(k-1)-ans)/2LL;
}


int32_t main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    
    int n, q, b=250, 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({l, r, ++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());
        freq.clear();
        l=0, r=-1;
        for(auto x: query[i])
        {
            while(x[0]>l)
            {
                count[a[l]]--;

                freq[count[a[l]]]++;
                freq[count[a[l]]+1]--;
                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]--;
            }
            while(x[1]<r)
            {
                if(count[a[r]]!=0)
               freq[count[a[r]]]--;
               count[a[r]]--;

               freq[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]]]++;
            }


            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:124: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]
  124 |     for(int i=0; i<ans.size(); i++) cout<<ans[i]<<"\n";
      |                  ~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 9 ms 23764 KB Output is correct
2 Correct 10 ms 23764 KB Output is correct
3 Correct 9 ms 23764 KB Output is correct
4 Correct 10 ms 23764 KB Output is correct
5 Correct 9 ms 23764 KB Output is correct
6 Correct 9 ms 23764 KB Output is correct
7 Correct 10 ms 23764 KB Output is correct
8 Correct 9 ms 23692 KB Output is correct
9 Correct 10 ms 23720 KB Output is correct
10 Correct 9 ms 23816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 23780 KB Output is correct
2 Correct 10 ms 23764 KB Output is correct
3 Correct 11 ms 23928 KB Output is correct
4 Correct 35 ms 26204 KB Output is correct
5 Correct 64 ms 30064 KB Output is correct
6 Correct 91 ms 29836 KB Output is correct
7 Correct 111 ms 36260 KB Output is correct
8 Correct 88 ms 29300 KB Output is correct
9 Correct 85 ms 29612 KB Output is correct
10 Correct 92 ms 32428 KB Output is correct
11 Correct 98 ms 30660 KB Output is correct
12 Correct 90 ms 29492 KB Output is correct
13 Correct 92 ms 29184 KB Output is correct
14 Correct 89 ms 31048 KB Output is correct
15 Correct 90 ms 30460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 23780 KB Output is correct
2 Correct 10 ms 23764 KB Output is correct
3 Correct 11 ms 23928 KB Output is correct
4 Correct 35 ms 26204 KB Output is correct
5 Correct 64 ms 30064 KB Output is correct
6 Correct 91 ms 29836 KB Output is correct
7 Correct 111 ms 36260 KB Output is correct
8 Correct 88 ms 29300 KB Output is correct
9 Correct 85 ms 29612 KB Output is correct
10 Correct 92 ms 32428 KB Output is correct
11 Correct 98 ms 30660 KB Output is correct
12 Correct 90 ms 29492 KB Output is correct
13 Correct 92 ms 29184 KB Output is correct
14 Correct 89 ms 31048 KB Output is correct
15 Correct 90 ms 30460 KB Output is correct
16 Correct 11 ms 23716 KB Output is correct
17 Correct 11 ms 23780 KB Output is correct
18 Correct 16 ms 23944 KB Output is correct
19 Correct 34 ms 25600 KB Output is correct
20 Correct 68 ms 27232 KB Output is correct
21 Correct 99 ms 29748 KB Output is correct
22 Correct 92 ms 28592 KB Output is correct
23 Correct 103 ms 29368 KB Output is correct
24 Correct 93 ms 28300 KB Output is correct
25 Correct 86 ms 28772 KB Output is correct
26 Correct 91 ms 28628 KB Output is correct
27 Correct 92 ms 29000 KB Output is correct
28 Correct 99 ms 30980 KB Output is correct
29 Correct 98 ms 28800 KB Output is correct
30 Correct 90 ms 28928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 23780 KB Output is correct
2 Correct 10 ms 23764 KB Output is correct
3 Correct 11 ms 23928 KB Output is correct
4 Correct 35 ms 26204 KB Output is correct
5 Correct 64 ms 30064 KB Output is correct
6 Correct 91 ms 29836 KB Output is correct
7 Correct 111 ms 36260 KB Output is correct
8 Correct 88 ms 29300 KB Output is correct
9 Correct 85 ms 29612 KB Output is correct
10 Correct 92 ms 32428 KB Output is correct
11 Correct 98 ms 30660 KB Output is correct
12 Correct 90 ms 29492 KB Output is correct
13 Correct 92 ms 29184 KB Output is correct
14 Correct 89 ms 31048 KB Output is correct
15 Correct 90 ms 30460 KB Output is correct
16 Correct 11 ms 23716 KB Output is correct
17 Correct 11 ms 23780 KB Output is correct
18 Correct 16 ms 23944 KB Output is correct
19 Correct 34 ms 25600 KB Output is correct
20 Correct 68 ms 27232 KB Output is correct
21 Correct 99 ms 29748 KB Output is correct
22 Correct 92 ms 28592 KB Output is correct
23 Correct 103 ms 29368 KB Output is correct
24 Correct 93 ms 28300 KB Output is correct
25 Correct 86 ms 28772 KB Output is correct
26 Correct 91 ms 28628 KB Output is correct
27 Correct 92 ms 29000 KB Output is correct
28 Correct 99 ms 30980 KB Output is correct
29 Correct 98 ms 28800 KB Output is correct
30 Correct 90 ms 28928 KB Output is correct
31 Correct 9 ms 23704 KB Output is correct
32 Correct 9 ms 23764 KB Output is correct
33 Correct 10 ms 23764 KB Output is correct
34 Correct 11 ms 23892 KB Output is correct
35 Correct 11 ms 23856 KB Output is correct
36 Correct 12 ms 23892 KB Output is correct
37 Correct 17 ms 24228 KB Output is correct
38 Correct 14 ms 24160 KB Output is correct
39 Correct 24 ms 24660 KB Output is correct
40 Correct 39 ms 25460 KB Output is correct
41 Correct 56 ms 26228 KB Output is correct
42 Correct 58 ms 26288 KB Output is correct
43 Correct 57 ms 26264 KB Output is correct
44 Correct 55 ms 26244 KB Output is correct
45 Correct 53 ms 26312 KB Output is correct
46 Correct 55 ms 26316 KB Output is correct
47 Correct 60 ms 26188 KB Output is correct
48 Correct 57 ms 26252 KB Output is correct
49 Correct 54 ms 26244 KB Output is correct
50 Correct 56 ms 26256 KB Output is correct
51 Correct 59 ms 26340 KB Output is correct
52 Correct 53 ms 26324 KB Output is correct
53 Correct 58 ms 26228 KB Output is correct
54 Correct 58 ms 26248 KB Output is correct
55 Correct 53 ms 26244 KB Output is correct
56 Correct 54 ms 26316 KB Output is correct
57 Correct 55 ms 26264 KB Output is correct
58 Correct 54 ms 26292 KB Output is correct
59 Correct 55 ms 26352 KB Output is correct
60 Correct 56 ms 26316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 23764 KB Output is correct
2 Correct 10 ms 23764 KB Output is correct
3 Correct 9 ms 23764 KB Output is correct
4 Correct 10 ms 23764 KB Output is correct
5 Correct 9 ms 23764 KB Output is correct
6 Correct 9 ms 23764 KB Output is correct
7 Correct 10 ms 23764 KB Output is correct
8 Correct 9 ms 23692 KB Output is correct
9 Correct 10 ms 23720 KB Output is correct
10 Correct 9 ms 23816 KB Output is correct
11 Correct 11 ms 23780 KB Output is correct
12 Correct 10 ms 23764 KB Output is correct
13 Correct 11 ms 23928 KB Output is correct
14 Correct 35 ms 26204 KB Output is correct
15 Correct 64 ms 30064 KB Output is correct
16 Correct 91 ms 29836 KB Output is correct
17 Correct 111 ms 36260 KB Output is correct
18 Correct 88 ms 29300 KB Output is correct
19 Correct 85 ms 29612 KB Output is correct
20 Correct 92 ms 32428 KB Output is correct
21 Correct 98 ms 30660 KB Output is correct
22 Correct 90 ms 29492 KB Output is correct
23 Correct 92 ms 29184 KB Output is correct
24 Correct 89 ms 31048 KB Output is correct
25 Correct 90 ms 30460 KB Output is correct
26 Correct 11 ms 23716 KB Output is correct
27 Correct 11 ms 23780 KB Output is correct
28 Correct 16 ms 23944 KB Output is correct
29 Correct 34 ms 25600 KB Output is correct
30 Correct 68 ms 27232 KB Output is correct
31 Correct 99 ms 29748 KB Output is correct
32 Correct 92 ms 28592 KB Output is correct
33 Correct 103 ms 29368 KB Output is correct
34 Correct 93 ms 28300 KB Output is correct
35 Correct 86 ms 28772 KB Output is correct
36 Correct 91 ms 28628 KB Output is correct
37 Correct 92 ms 29000 KB Output is correct
38 Correct 99 ms 30980 KB Output is correct
39 Correct 98 ms 28800 KB Output is correct
40 Correct 90 ms 28928 KB Output is correct
41 Correct 9 ms 23704 KB Output is correct
42 Correct 9 ms 23764 KB Output is correct
43 Correct 10 ms 23764 KB Output is correct
44 Correct 11 ms 23892 KB Output is correct
45 Correct 11 ms 23856 KB Output is correct
46 Correct 12 ms 23892 KB Output is correct
47 Correct 17 ms 24228 KB Output is correct
48 Correct 14 ms 24160 KB Output is correct
49 Correct 24 ms 24660 KB Output is correct
50 Correct 39 ms 25460 KB Output is correct
51 Correct 56 ms 26228 KB Output is correct
52 Correct 58 ms 26288 KB Output is correct
53 Correct 57 ms 26264 KB Output is correct
54 Correct 55 ms 26244 KB Output is correct
55 Correct 53 ms 26312 KB Output is correct
56 Correct 55 ms 26316 KB Output is correct
57 Correct 60 ms 26188 KB Output is correct
58 Correct 57 ms 26252 KB Output is correct
59 Correct 54 ms 26244 KB Output is correct
60 Correct 56 ms 26256 KB Output is correct
61 Correct 59 ms 26340 KB Output is correct
62 Correct 53 ms 26324 KB Output is correct
63 Correct 58 ms 26228 KB Output is correct
64 Correct 58 ms 26248 KB Output is correct
65 Correct 53 ms 26244 KB Output is correct
66 Correct 54 ms 26316 KB Output is correct
67 Correct 55 ms 26264 KB Output is correct
68 Correct 54 ms 26292 KB Output is correct
69 Correct 55 ms 26352 KB Output is correct
70 Correct 56 ms 26316 KB Output is correct
71 Correct 15 ms 24220 KB Output is correct
72 Correct 14 ms 24104 KB Output is correct
73 Correct 15 ms 24224 KB Output is correct
74 Correct 15 ms 24216 KB Output is correct
75 Correct 15 ms 24148 KB Output is correct
76 Correct 20 ms 24612 KB Output is correct
77 Correct 23 ms 24532 KB Output is correct
78 Correct 19 ms 24612 KB Output is correct
79 Correct 20 ms 24532 KB Output is correct
80 Correct 20 ms 24520 KB Output is correct
81 Correct 31 ms 25392 KB Output is correct
82 Correct 32 ms 25388 KB Output is correct
83 Correct 38 ms 25300 KB Output is correct
84 Correct 30 ms 25392 KB Output is correct
85 Correct 30 ms 25400 KB Output is correct
86 Correct 30 ms 25332 KB Output is correct
87 Correct 29 ms 25292 KB Output is correct
88 Correct 30 ms 25292 KB Output is correct
89 Correct 33 ms 25360 KB Output is correct
90 Correct 30 ms 25300 KB Output is correct
91 Correct 47 ms 26060 KB Output is correct
92 Correct 40 ms 26068 KB Output is correct
93 Correct 44 ms 26124 KB Output is correct
94 Correct 37 ms 26128 KB Output is correct
95 Correct 38 ms 26060 KB Output is correct
96 Correct 39 ms 26104 KB Output is correct
97 Correct 38 ms 26080 KB Output is correct
98 Correct 38 ms 26068 KB Output is correct
99 Correct 42 ms 26168 KB Output is correct
100 Correct 47 ms 26116 KB Output is correct
101 Correct 39 ms 26092 KB Output is correct
102 Correct 37 ms 26060 KB Output is correct
103 Correct 38 ms 26120 KB Output is correct
104 Correct 38 ms 26164 KB Output is correct
105 Correct 39 ms 26068 KB Output is correct
106 Correct 37 ms 26144 KB Output is correct
107 Correct 41 ms 26120 KB Output is correct
108 Correct 43 ms 26124 KB Output is correct
109 Correct 43 ms 26112 KB Output is correct
110 Correct 39 ms 26068 KB Output is correct
111 Correct 38 ms 26120 KB Output is correct
112 Correct 38 ms 26128 KB Output is correct
113 Correct 37 ms 26120 KB Output is correct
114 Correct 37 ms 26128 KB Output is correct
115 Correct 42 ms 26160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 23764 KB Output is correct
2 Correct 10 ms 23764 KB Output is correct
3 Correct 9 ms 23764 KB Output is correct
4 Correct 10 ms 23764 KB Output is correct
5 Correct 9 ms 23764 KB Output is correct
6 Correct 9 ms 23764 KB Output is correct
7 Correct 10 ms 23764 KB Output is correct
8 Correct 9 ms 23692 KB Output is correct
9 Correct 10 ms 23720 KB Output is correct
10 Correct 9 ms 23816 KB Output is correct
11 Correct 11 ms 23780 KB Output is correct
12 Correct 10 ms 23764 KB Output is correct
13 Correct 11 ms 23928 KB Output is correct
14 Correct 35 ms 26204 KB Output is correct
15 Correct 64 ms 30064 KB Output is correct
16 Correct 91 ms 29836 KB Output is correct
17 Correct 111 ms 36260 KB Output is correct
18 Correct 88 ms 29300 KB Output is correct
19 Correct 85 ms 29612 KB Output is correct
20 Correct 92 ms 32428 KB Output is correct
21 Correct 98 ms 30660 KB Output is correct
22 Correct 90 ms 29492 KB Output is correct
23 Correct 92 ms 29184 KB Output is correct
24 Correct 89 ms 31048 KB Output is correct
25 Correct 90 ms 30460 KB Output is correct
26 Correct 11 ms 23716 KB Output is correct
27 Correct 11 ms 23780 KB Output is correct
28 Correct 16 ms 23944 KB Output is correct
29 Correct 34 ms 25600 KB Output is correct
30 Correct 68 ms 27232 KB Output is correct
31 Correct 99 ms 29748 KB Output is correct
32 Correct 92 ms 28592 KB Output is correct
33 Correct 103 ms 29368 KB Output is correct
34 Correct 93 ms 28300 KB Output is correct
35 Correct 86 ms 28772 KB Output is correct
36 Correct 91 ms 28628 KB Output is correct
37 Correct 92 ms 29000 KB Output is correct
38 Correct 99 ms 30980 KB Output is correct
39 Correct 98 ms 28800 KB Output is correct
40 Correct 90 ms 28928 KB Output is correct
41 Correct 9 ms 23704 KB Output is correct
42 Correct 9 ms 23764 KB Output is correct
43 Correct 10 ms 23764 KB Output is correct
44 Correct 11 ms 23892 KB Output is correct
45 Correct 11 ms 23856 KB Output is correct
46 Correct 12 ms 23892 KB Output is correct
47 Correct 17 ms 24228 KB Output is correct
48 Correct 14 ms 24160 KB Output is correct
49 Correct 24 ms 24660 KB Output is correct
50 Correct 39 ms 25460 KB Output is correct
51 Correct 56 ms 26228 KB Output is correct
52 Correct 58 ms 26288 KB Output is correct
53 Correct 57 ms 26264 KB Output is correct
54 Correct 55 ms 26244 KB Output is correct
55 Correct 53 ms 26312 KB Output is correct
56 Correct 55 ms 26316 KB Output is correct
57 Correct 60 ms 26188 KB Output is correct
58 Correct 57 ms 26252 KB Output is correct
59 Correct 54 ms 26244 KB Output is correct
60 Correct 56 ms 26256 KB Output is correct
61 Correct 59 ms 26340 KB Output is correct
62 Correct 53 ms 26324 KB Output is correct
63 Correct 58 ms 26228 KB Output is correct
64 Correct 58 ms 26248 KB Output is correct
65 Correct 53 ms 26244 KB Output is correct
66 Correct 54 ms 26316 KB Output is correct
67 Correct 55 ms 26264 KB Output is correct
68 Correct 54 ms 26292 KB Output is correct
69 Correct 55 ms 26352 KB Output is correct
70 Correct 56 ms 26316 KB Output is correct
71 Correct 15 ms 24220 KB Output is correct
72 Correct 14 ms 24104 KB Output is correct
73 Correct 15 ms 24224 KB Output is correct
74 Correct 15 ms 24216 KB Output is correct
75 Correct 15 ms 24148 KB Output is correct
76 Correct 20 ms 24612 KB Output is correct
77 Correct 23 ms 24532 KB Output is correct
78 Correct 19 ms 24612 KB Output is correct
79 Correct 20 ms 24532 KB Output is correct
80 Correct 20 ms 24520 KB Output is correct
81 Correct 31 ms 25392 KB Output is correct
82 Correct 32 ms 25388 KB Output is correct
83 Correct 38 ms 25300 KB Output is correct
84 Correct 30 ms 25392 KB Output is correct
85 Correct 30 ms 25400 KB Output is correct
86 Correct 30 ms 25332 KB Output is correct
87 Correct 29 ms 25292 KB Output is correct
88 Correct 30 ms 25292 KB Output is correct
89 Correct 33 ms 25360 KB Output is correct
90 Correct 30 ms 25300 KB Output is correct
91 Correct 47 ms 26060 KB Output is correct
92 Correct 40 ms 26068 KB Output is correct
93 Correct 44 ms 26124 KB Output is correct
94 Correct 37 ms 26128 KB Output is correct
95 Correct 38 ms 26060 KB Output is correct
96 Correct 39 ms 26104 KB Output is correct
97 Correct 38 ms 26080 KB Output is correct
98 Correct 38 ms 26068 KB Output is correct
99 Correct 42 ms 26168 KB Output is correct
100 Correct 47 ms 26116 KB Output is correct
101 Correct 39 ms 26092 KB Output is correct
102 Correct 37 ms 26060 KB Output is correct
103 Correct 38 ms 26120 KB Output is correct
104 Correct 38 ms 26164 KB Output is correct
105 Correct 39 ms 26068 KB Output is correct
106 Correct 37 ms 26144 KB Output is correct
107 Correct 41 ms 26120 KB Output is correct
108 Correct 43 ms 26124 KB Output is correct
109 Correct 43 ms 26112 KB Output is correct
110 Correct 39 ms 26068 KB Output is correct
111 Correct 38 ms 26120 KB Output is correct
112 Correct 38 ms 26128 KB Output is correct
113 Correct 37 ms 26120 KB Output is correct
114 Correct 37 ms 26128 KB Output is correct
115 Correct 42 ms 26160 KB Output is correct
116 Execution timed out 7096 ms 26064 KB Time limit exceeded
117 Halted 0 ms 0 KB -