Submission #1084175

# Submission time Handle Problem Language Result Execution time Memory
1084175 2024-09-05T14:17:52 Z onlk97 Diversity (CEOI21_diversity) C++14
64 / 100
7000 ms 5476 KB
#include <bits/stdc++.h>
using namespace std;
int L,R;
int a[300010];
long long freq[300010],freq2[300010];
bitset <300010> have;
long long calcans(){
    long long ans=0,lps=0,rps=0,s=R-L+1;
    for (int i=have._Find_first(); i<300010; i=have._Find_next(i)){
        long long cntl,cntr;
        int f;
        if (lps<=rps){
            f=min(freq2[i],(rps-lps)/i+1);
            cntl=f+(freq2[i]-f)/2,cntr=(freq2[i]-f+1)/2;
        } else {
            f=min(freq2[i],(lps-rps)/i+1);
            cntl=(freq2[i]-f+1)/2,cntr=f+(freq2[i]-f)/2;
        }
        ans+=cntl*lps*lps+cntl*(cntl+1)*lps*i+cntl*(cntl+1)/2*(2*cntl+1)/3*i*i;
        ans-=s*(lps+i+lps+i*cntl)*cntl/2;
        lps+=cntl*i;
        long long t=s-rps;
        ans+=cntr*t*t-cntr*(cntr-1)*t*i+(cntr)*(cntr-1)/2*(2*cntr-1)/3*i*i;
        ans-=s*(t+t-(cntr-1)*i)*cntr/2;
        rps+=cntr*i;
    }
    return s*(s+1)/2-ans;
}
const int BLOCK=600;
bool cmp(pair <pair <int,int>,int> a,pair <pair <int,int>,int> b){
    int ax=a.first.first/BLOCK,bx=b.first.first/BLOCK;
    if (ax!=bx) return ax<bx;
    return a.first.second<b.first.second;
}
int main(){
    int n,q;
    cin>>n>>q;
    for (int i=1; i<=n; i++) cin>>a[i];
    pair <pair <int,int>,int> qu[q+1];
    for (int i=1; i<=q; i++){
        cin>>qu[i].first.first>>qu[i].first.second;
        qu[i].second=i;
    }
    sort(qu+1,qu+q+1,cmp);
    L=1; R=0;
    long long op[q+1];
    for (int i=1; i<=q; i++){
        while (R<qu[i].first.second){
            R++;
            if (freq[a[R]]) freq2[freq[a[R]]]--;
            freq[a[R]]++;
            if (!freq2[freq[a[R]]]) have[freq[a[R]]]=1;
            freq2[freq[a[R]]]++;
        }
        while (L>qu[i].first.first){
            L--;
            if (freq[a[L]]) freq2[freq[a[L]]]--;
            freq[a[L]]++;
            if (!freq2[freq[a[L]]]) have[freq[a[L]]]=1;
            freq2[freq[a[L]]]++;
        }
        while (R>qu[i].first.second){
            freq2[freq[a[R]]]--;
            freq[a[R]]--;
            if (freq[a[R]]&&!freq2[freq[a[R]]]) have[freq[a[R]]]=1;
            freq2[freq[a[R]]]++;
            R--;
        }
        while (L<qu[i].first.first){
            freq2[freq[a[L]]]--;
            freq[a[L]]--;
            if (freq[a[L]]&&!freq2[freq[a[L]]]) have[freq[a[L]]]=1;
            freq2[freq[a[L]]]++;
            L++;
        }
        op[qu[i].second]=calcans();
    }
    for (int i=1; i<=q; i++) cout<<op[i]<<'\n';
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 10 ms 1112 KB Output is correct
5 Correct 19 ms 2128 KB Output is correct
6 Correct 30 ms 2576 KB Output is correct
7 Correct 31 ms 3428 KB Output is correct
8 Correct 30 ms 2420 KB Output is correct
9 Correct 28 ms 2440 KB Output is correct
10 Correct 30 ms 2888 KB Output is correct
11 Correct 30 ms 2680 KB Output is correct
12 Correct 32 ms 2484 KB Output is correct
13 Correct 29 ms 2652 KB Output is correct
14 Correct 31 ms 2652 KB Output is correct
15 Correct 28 ms 2652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 10 ms 1112 KB Output is correct
5 Correct 19 ms 2128 KB Output is correct
6 Correct 30 ms 2576 KB Output is correct
7 Correct 31 ms 3428 KB Output is correct
8 Correct 30 ms 2420 KB Output is correct
9 Correct 28 ms 2440 KB Output is correct
10 Correct 30 ms 2888 KB Output is correct
11 Correct 30 ms 2680 KB Output is correct
12 Correct 32 ms 2484 KB Output is correct
13 Correct 29 ms 2652 KB Output is correct
14 Correct 31 ms 2652 KB Output is correct
15 Correct 28 ms 2652 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 2 ms 348 KB Output is correct
19 Correct 12 ms 1220 KB Output is correct
20 Correct 21 ms 1884 KB Output is correct
21 Correct 36 ms 2672 KB Output is correct
22 Correct 32 ms 2652 KB Output is correct
23 Correct 32 ms 2764 KB Output is correct
24 Correct 31 ms 2552 KB Output is correct
25 Correct 35 ms 2660 KB Output is correct
26 Correct 31 ms 2644 KB Output is correct
27 Correct 32 ms 2648 KB Output is correct
28 Correct 33 ms 2760 KB Output is correct
29 Correct 36 ms 2648 KB Output is correct
30 Correct 34 ms 2640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 10 ms 1112 KB Output is correct
5 Correct 19 ms 2128 KB Output is correct
6 Correct 30 ms 2576 KB Output is correct
7 Correct 31 ms 3428 KB Output is correct
8 Correct 30 ms 2420 KB Output is correct
9 Correct 28 ms 2440 KB Output is correct
10 Correct 30 ms 2888 KB Output is correct
11 Correct 30 ms 2680 KB Output is correct
12 Correct 32 ms 2484 KB Output is correct
13 Correct 29 ms 2652 KB Output is correct
14 Correct 31 ms 2652 KB Output is correct
15 Correct 28 ms 2652 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 2 ms 348 KB Output is correct
19 Correct 12 ms 1220 KB Output is correct
20 Correct 21 ms 1884 KB Output is correct
21 Correct 36 ms 2672 KB Output is correct
22 Correct 32 ms 2652 KB Output is correct
23 Correct 32 ms 2764 KB Output is correct
24 Correct 31 ms 2552 KB Output is correct
25 Correct 35 ms 2660 KB Output is correct
26 Correct 31 ms 2644 KB Output is correct
27 Correct 32 ms 2648 KB Output is correct
28 Correct 33 ms 2760 KB Output is correct
29 Correct 36 ms 2648 KB Output is correct
30 Correct 34 ms 2640 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 2 ms 348 KB Output is correct
35 Correct 2 ms 348 KB Output is correct
36 Correct 2 ms 348 KB Output is correct
37 Correct 6 ms 604 KB Output is correct
38 Correct 6 ms 860 KB Output is correct
39 Correct 12 ms 1116 KB Output is correct
40 Correct 26 ms 2012 KB Output is correct
41 Correct 43 ms 2640 KB Output is correct
42 Correct 37 ms 2624 KB Output is correct
43 Correct 36 ms 2540 KB Output is correct
44 Correct 38 ms 2580 KB Output is correct
45 Correct 36 ms 2644 KB Output is correct
46 Correct 37 ms 2644 KB Output is correct
47 Correct 38 ms 2644 KB Output is correct
48 Correct 36 ms 2760 KB Output is correct
49 Correct 36 ms 2644 KB Output is correct
50 Correct 41 ms 2644 KB Output is correct
51 Correct 39 ms 2640 KB Output is correct
52 Correct 37 ms 2720 KB Output is correct
53 Correct 38 ms 2644 KB Output is correct
54 Correct 36 ms 2772 KB Output is correct
55 Correct 38 ms 2852 KB Output is correct
56 Correct 38 ms 2644 KB Output is correct
57 Correct 38 ms 2560 KB Output is correct
58 Correct 41 ms 2644 KB Output is correct
59 Correct 39 ms 2564 KB Output is correct
60 Correct 40 ms 2728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 10 ms 1112 KB Output is correct
15 Correct 19 ms 2128 KB Output is correct
16 Correct 30 ms 2576 KB Output is correct
17 Correct 31 ms 3428 KB Output is correct
18 Correct 30 ms 2420 KB Output is correct
19 Correct 28 ms 2440 KB Output is correct
20 Correct 30 ms 2888 KB Output is correct
21 Correct 30 ms 2680 KB Output is correct
22 Correct 32 ms 2484 KB Output is correct
23 Correct 29 ms 2652 KB Output is correct
24 Correct 31 ms 2652 KB Output is correct
25 Correct 28 ms 2652 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 2 ms 348 KB Output is correct
29 Correct 12 ms 1220 KB Output is correct
30 Correct 21 ms 1884 KB Output is correct
31 Correct 36 ms 2672 KB Output is correct
32 Correct 32 ms 2652 KB Output is correct
33 Correct 32 ms 2764 KB Output is correct
34 Correct 31 ms 2552 KB Output is correct
35 Correct 35 ms 2660 KB Output is correct
36 Correct 31 ms 2644 KB Output is correct
37 Correct 32 ms 2648 KB Output is correct
38 Correct 33 ms 2760 KB Output is correct
39 Correct 36 ms 2648 KB Output is correct
40 Correct 34 ms 2640 KB Output is correct
41 Correct 1 ms 348 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 2 ms 348 KB Output is correct
45 Correct 2 ms 348 KB Output is correct
46 Correct 2 ms 348 KB Output is correct
47 Correct 6 ms 604 KB Output is correct
48 Correct 6 ms 860 KB Output is correct
49 Correct 12 ms 1116 KB Output is correct
50 Correct 26 ms 2012 KB Output is correct
51 Correct 43 ms 2640 KB Output is correct
52 Correct 37 ms 2624 KB Output is correct
53 Correct 36 ms 2540 KB Output is correct
54 Correct 38 ms 2580 KB Output is correct
55 Correct 36 ms 2644 KB Output is correct
56 Correct 37 ms 2644 KB Output is correct
57 Correct 38 ms 2644 KB Output is correct
58 Correct 36 ms 2760 KB Output is correct
59 Correct 36 ms 2644 KB Output is correct
60 Correct 41 ms 2644 KB Output is correct
61 Correct 39 ms 2640 KB Output is correct
62 Correct 37 ms 2720 KB Output is correct
63 Correct 38 ms 2644 KB Output is correct
64 Correct 36 ms 2772 KB Output is correct
65 Correct 38 ms 2852 KB Output is correct
66 Correct 38 ms 2644 KB Output is correct
67 Correct 38 ms 2560 KB Output is correct
68 Correct 41 ms 2644 KB Output is correct
69 Correct 39 ms 2564 KB Output is correct
70 Correct 40 ms 2728 KB Output is correct
71 Correct 8 ms 860 KB Output is correct
72 Correct 8 ms 856 KB Output is correct
73 Correct 9 ms 860 KB Output is correct
74 Correct 8 ms 860 KB Output is correct
75 Correct 7 ms 832 KB Output is correct
76 Correct 15 ms 1116 KB Output is correct
77 Correct 15 ms 1144 KB Output is correct
78 Correct 14 ms 1348 KB Output is correct
79 Correct 14 ms 1116 KB Output is correct
80 Correct 14 ms 1216 KB Output is correct
81 Correct 31 ms 2136 KB Output is correct
82 Correct 27 ms 2128 KB Output is correct
83 Correct 30 ms 2128 KB Output is correct
84 Correct 31 ms 2128 KB Output is correct
85 Correct 30 ms 2388 KB Output is correct
86 Correct 31 ms 2384 KB Output is correct
87 Correct 30 ms 2320 KB Output is correct
88 Correct 31 ms 2384 KB Output is correct
89 Correct 31 ms 2384 KB Output is correct
90 Correct 31 ms 2432 KB Output is correct
91 Correct 54 ms 3996 KB Output is correct
92 Correct 47 ms 3920 KB Output is correct
93 Correct 48 ms 3920 KB Output is correct
94 Correct 56 ms 3920 KB Output is correct
95 Correct 48 ms 3924 KB Output is correct
96 Correct 56 ms 4844 KB Output is correct
97 Correct 52 ms 4860 KB Output is correct
98 Correct 53 ms 5016 KB Output is correct
99 Correct 52 ms 4944 KB Output is correct
100 Correct 55 ms 4884 KB Output is correct
101 Correct 55 ms 4948 KB Output is correct
102 Correct 54 ms 4944 KB Output is correct
103 Correct 54 ms 4944 KB Output is correct
104 Correct 53 ms 4944 KB Output is correct
105 Correct 55 ms 5004 KB Output is correct
106 Correct 54 ms 5236 KB Output is correct
107 Correct 52 ms 5324 KB Output is correct
108 Correct 61 ms 5400 KB Output is correct
109 Correct 56 ms 5476 KB Output is correct
110 Correct 54 ms 5308 KB Output is correct
111 Correct 60 ms 5460 KB Output is correct
112 Correct 53 ms 5460 KB Output is correct
113 Correct 54 ms 5328 KB Output is correct
114 Correct 52 ms 5460 KB Output is correct
115 Correct 55 ms 5460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 10 ms 1112 KB Output is correct
15 Correct 19 ms 2128 KB Output is correct
16 Correct 30 ms 2576 KB Output is correct
17 Correct 31 ms 3428 KB Output is correct
18 Correct 30 ms 2420 KB Output is correct
19 Correct 28 ms 2440 KB Output is correct
20 Correct 30 ms 2888 KB Output is correct
21 Correct 30 ms 2680 KB Output is correct
22 Correct 32 ms 2484 KB Output is correct
23 Correct 29 ms 2652 KB Output is correct
24 Correct 31 ms 2652 KB Output is correct
25 Correct 28 ms 2652 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 2 ms 348 KB Output is correct
29 Correct 12 ms 1220 KB Output is correct
30 Correct 21 ms 1884 KB Output is correct
31 Correct 36 ms 2672 KB Output is correct
32 Correct 32 ms 2652 KB Output is correct
33 Correct 32 ms 2764 KB Output is correct
34 Correct 31 ms 2552 KB Output is correct
35 Correct 35 ms 2660 KB Output is correct
36 Correct 31 ms 2644 KB Output is correct
37 Correct 32 ms 2648 KB Output is correct
38 Correct 33 ms 2760 KB Output is correct
39 Correct 36 ms 2648 KB Output is correct
40 Correct 34 ms 2640 KB Output is correct
41 Correct 1 ms 348 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 2 ms 348 KB Output is correct
45 Correct 2 ms 348 KB Output is correct
46 Correct 2 ms 348 KB Output is correct
47 Correct 6 ms 604 KB Output is correct
48 Correct 6 ms 860 KB Output is correct
49 Correct 12 ms 1116 KB Output is correct
50 Correct 26 ms 2012 KB Output is correct
51 Correct 43 ms 2640 KB Output is correct
52 Correct 37 ms 2624 KB Output is correct
53 Correct 36 ms 2540 KB Output is correct
54 Correct 38 ms 2580 KB Output is correct
55 Correct 36 ms 2644 KB Output is correct
56 Correct 37 ms 2644 KB Output is correct
57 Correct 38 ms 2644 KB Output is correct
58 Correct 36 ms 2760 KB Output is correct
59 Correct 36 ms 2644 KB Output is correct
60 Correct 41 ms 2644 KB Output is correct
61 Correct 39 ms 2640 KB Output is correct
62 Correct 37 ms 2720 KB Output is correct
63 Correct 38 ms 2644 KB Output is correct
64 Correct 36 ms 2772 KB Output is correct
65 Correct 38 ms 2852 KB Output is correct
66 Correct 38 ms 2644 KB Output is correct
67 Correct 38 ms 2560 KB Output is correct
68 Correct 41 ms 2644 KB Output is correct
69 Correct 39 ms 2564 KB Output is correct
70 Correct 40 ms 2728 KB Output is correct
71 Correct 8 ms 860 KB Output is correct
72 Correct 8 ms 856 KB Output is correct
73 Correct 9 ms 860 KB Output is correct
74 Correct 8 ms 860 KB Output is correct
75 Correct 7 ms 832 KB Output is correct
76 Correct 15 ms 1116 KB Output is correct
77 Correct 15 ms 1144 KB Output is correct
78 Correct 14 ms 1348 KB Output is correct
79 Correct 14 ms 1116 KB Output is correct
80 Correct 14 ms 1216 KB Output is correct
81 Correct 31 ms 2136 KB Output is correct
82 Correct 27 ms 2128 KB Output is correct
83 Correct 30 ms 2128 KB Output is correct
84 Correct 31 ms 2128 KB Output is correct
85 Correct 30 ms 2388 KB Output is correct
86 Correct 31 ms 2384 KB Output is correct
87 Correct 30 ms 2320 KB Output is correct
88 Correct 31 ms 2384 KB Output is correct
89 Correct 31 ms 2384 KB Output is correct
90 Correct 31 ms 2432 KB Output is correct
91 Correct 54 ms 3996 KB Output is correct
92 Correct 47 ms 3920 KB Output is correct
93 Correct 48 ms 3920 KB Output is correct
94 Correct 56 ms 3920 KB Output is correct
95 Correct 48 ms 3924 KB Output is correct
96 Correct 56 ms 4844 KB Output is correct
97 Correct 52 ms 4860 KB Output is correct
98 Correct 53 ms 5016 KB Output is correct
99 Correct 52 ms 4944 KB Output is correct
100 Correct 55 ms 4884 KB Output is correct
101 Correct 55 ms 4948 KB Output is correct
102 Correct 54 ms 4944 KB Output is correct
103 Correct 54 ms 4944 KB Output is correct
104 Correct 53 ms 4944 KB Output is correct
105 Correct 55 ms 5004 KB Output is correct
106 Correct 54 ms 5236 KB Output is correct
107 Correct 52 ms 5324 KB Output is correct
108 Correct 61 ms 5400 KB Output is correct
109 Correct 56 ms 5476 KB Output is correct
110 Correct 54 ms 5308 KB Output is correct
111 Correct 60 ms 5460 KB Output is correct
112 Correct 53 ms 5460 KB Output is correct
113 Correct 54 ms 5328 KB Output is correct
114 Correct 52 ms 5460 KB Output is correct
115 Correct 55 ms 5460 KB Output is correct
116 Correct 997 ms 2196 KB Output is correct
117 Correct 665 ms 2384 KB Output is correct
118 Correct 2458 ms 2644 KB Output is correct
119 Correct 765 ms 2880 KB Output is correct
120 Correct 673 ms 2888 KB Output is correct
121 Correct 946 ms 3368 KB Output is correct
122 Correct 755 ms 3412 KB Output is correct
123 Correct 1820 ms 4204 KB Output is correct
124 Correct 816 ms 4308 KB Output is correct
125 Correct 548 ms 4436 KB Output is correct
126 Execution timed out 7062 ms 4180 KB Time limit exceeded
127 Halted 0 ms 0 KB -