Submission #1084178

# Submission time Handle Problem Language Result Execution time Memory
1084178 2024-09-05T14:20:27 Z onlk97 Diversity (CEOI21_diversity) C++14
64 / 100
7000 ms 4876 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=850;
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(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    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 348 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 348 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 1 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 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 5 ms 1276 KB Output is correct
5 Correct 10 ms 2016 KB Output is correct
6 Correct 14 ms 2648 KB Output is correct
7 Correct 16 ms 3420 KB Output is correct
8 Correct 13 ms 2660 KB Output is correct
9 Correct 14 ms 2640 KB Output is correct
10 Correct 15 ms 2904 KB Output is correct
11 Correct 15 ms 2652 KB Output is correct
12 Correct 14 ms 2692 KB Output is correct
13 Correct 13 ms 2648 KB Output is correct
14 Correct 14 ms 2904 KB Output is correct
15 Correct 13 ms 2652 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 1 ms 348 KB Output is correct
4 Correct 5 ms 1276 KB Output is correct
5 Correct 10 ms 2016 KB Output is correct
6 Correct 14 ms 2648 KB Output is correct
7 Correct 16 ms 3420 KB Output is correct
8 Correct 13 ms 2660 KB Output is correct
9 Correct 14 ms 2640 KB Output is correct
10 Correct 15 ms 2904 KB Output is correct
11 Correct 15 ms 2652 KB Output is correct
12 Correct 14 ms 2692 KB Output is correct
13 Correct 13 ms 2648 KB Output is correct
14 Correct 14 ms 2904 KB Output is correct
15 Correct 13 ms 2652 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 5 ms 1224 KB Output is correct
20 Correct 9 ms 2036 KB Output is correct
21 Correct 14 ms 2904 KB Output is correct
22 Correct 14 ms 2660 KB Output is correct
23 Correct 15 ms 2672 KB Output is correct
24 Correct 17 ms 2684 KB Output is correct
25 Correct 14 ms 2660 KB Output is correct
26 Correct 16 ms 2652 KB Output is correct
27 Correct 15 ms 2808 KB Output is correct
28 Correct 15 ms 2780 KB Output is correct
29 Correct 15 ms 2652 KB Output is correct
30 Correct 15 ms 2652 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 1 ms 348 KB Output is correct
4 Correct 5 ms 1276 KB Output is correct
5 Correct 10 ms 2016 KB Output is correct
6 Correct 14 ms 2648 KB Output is correct
7 Correct 16 ms 3420 KB Output is correct
8 Correct 13 ms 2660 KB Output is correct
9 Correct 14 ms 2640 KB Output is correct
10 Correct 15 ms 2904 KB Output is correct
11 Correct 15 ms 2652 KB Output is correct
12 Correct 14 ms 2692 KB Output is correct
13 Correct 13 ms 2648 KB Output is correct
14 Correct 14 ms 2904 KB Output is correct
15 Correct 13 ms 2652 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 5 ms 1224 KB Output is correct
20 Correct 9 ms 2036 KB Output is correct
21 Correct 14 ms 2904 KB Output is correct
22 Correct 14 ms 2660 KB Output is correct
23 Correct 15 ms 2672 KB Output is correct
24 Correct 17 ms 2684 KB Output is correct
25 Correct 14 ms 2660 KB Output is correct
26 Correct 16 ms 2652 KB Output is correct
27 Correct 15 ms 2808 KB Output is correct
28 Correct 15 ms 2780 KB Output is correct
29 Correct 15 ms 2652 KB Output is correct
30 Correct 15 ms 2652 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 3 ms 860 KB Output is correct
38 Correct 3 ms 856 KB Output is correct
39 Correct 6 ms 1112 KB Output is correct
40 Correct 10 ms 2044 KB Output is correct
41 Correct 16 ms 2596 KB Output is correct
42 Correct 15 ms 2308 KB Output is correct
43 Correct 15 ms 2396 KB Output is correct
44 Correct 14 ms 2396 KB Output is correct
45 Correct 14 ms 2396 KB Output is correct
46 Correct 16 ms 2396 KB Output is correct
47 Correct 15 ms 2228 KB Output is correct
48 Correct 14 ms 2396 KB Output is correct
49 Correct 15 ms 2284 KB Output is correct
50 Correct 15 ms 2396 KB Output is correct
51 Correct 15 ms 2396 KB Output is correct
52 Correct 15 ms 2396 KB Output is correct
53 Correct 15 ms 2396 KB Output is correct
54 Correct 15 ms 2284 KB Output is correct
55 Correct 19 ms 2392 KB Output is correct
56 Correct 15 ms 2396 KB Output is correct
57 Correct 14 ms 2404 KB Output is correct
58 Correct 15 ms 2396 KB Output is correct
59 Correct 15 ms 2328 KB Output is correct
60 Correct 14 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 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 348 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 1 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 0 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 5 ms 1276 KB Output is correct
15 Correct 10 ms 2016 KB Output is correct
16 Correct 14 ms 2648 KB Output is correct
17 Correct 16 ms 3420 KB Output is correct
18 Correct 13 ms 2660 KB Output is correct
19 Correct 14 ms 2640 KB Output is correct
20 Correct 15 ms 2904 KB Output is correct
21 Correct 15 ms 2652 KB Output is correct
22 Correct 14 ms 2692 KB Output is correct
23 Correct 13 ms 2648 KB Output is correct
24 Correct 14 ms 2904 KB Output is correct
25 Correct 13 ms 2652 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 5 ms 1224 KB Output is correct
30 Correct 9 ms 2036 KB Output is correct
31 Correct 14 ms 2904 KB Output is correct
32 Correct 14 ms 2660 KB Output is correct
33 Correct 15 ms 2672 KB Output is correct
34 Correct 17 ms 2684 KB Output is correct
35 Correct 14 ms 2660 KB Output is correct
36 Correct 16 ms 2652 KB Output is correct
37 Correct 15 ms 2808 KB Output is correct
38 Correct 15 ms 2780 KB Output is correct
39 Correct 15 ms 2652 KB Output is correct
40 Correct 15 ms 2652 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 1 ms 348 KB Output is correct
45 Correct 1 ms 348 KB Output is correct
46 Correct 1 ms 348 KB Output is correct
47 Correct 3 ms 860 KB Output is correct
48 Correct 3 ms 856 KB Output is correct
49 Correct 6 ms 1112 KB Output is correct
50 Correct 10 ms 2044 KB Output is correct
51 Correct 16 ms 2596 KB Output is correct
52 Correct 15 ms 2308 KB Output is correct
53 Correct 15 ms 2396 KB Output is correct
54 Correct 14 ms 2396 KB Output is correct
55 Correct 14 ms 2396 KB Output is correct
56 Correct 16 ms 2396 KB Output is correct
57 Correct 15 ms 2228 KB Output is correct
58 Correct 14 ms 2396 KB Output is correct
59 Correct 15 ms 2284 KB Output is correct
60 Correct 15 ms 2396 KB Output is correct
61 Correct 15 ms 2396 KB Output is correct
62 Correct 15 ms 2396 KB Output is correct
63 Correct 15 ms 2396 KB Output is correct
64 Correct 15 ms 2284 KB Output is correct
65 Correct 19 ms 2392 KB Output is correct
66 Correct 15 ms 2396 KB Output is correct
67 Correct 14 ms 2404 KB Output is correct
68 Correct 15 ms 2396 KB Output is correct
69 Correct 15 ms 2328 KB Output is correct
70 Correct 14 ms 2396 KB Output is correct
71 Correct 3 ms 856 KB Output is correct
72 Correct 3 ms 860 KB Output is correct
73 Correct 3 ms 860 KB Output is correct
74 Correct 3 ms 812 KB Output is correct
75 Correct 3 ms 860 KB Output is correct
76 Correct 5 ms 1372 KB Output is correct
77 Correct 6 ms 1372 KB Output is correct
78 Correct 5 ms 1372 KB Output is correct
79 Correct 6 ms 1372 KB Output is correct
80 Correct 6 ms 1244 KB Output is correct
81 Correct 11 ms 1884 KB Output is correct
82 Correct 10 ms 1896 KB Output is correct
83 Correct 11 ms 1884 KB Output is correct
84 Correct 11 ms 1884 KB Output is correct
85 Correct 10 ms 1880 KB Output is correct
86 Correct 11 ms 2140 KB Output is correct
87 Correct 11 ms 2056 KB Output is correct
88 Correct 11 ms 2392 KB Output is correct
89 Correct 11 ms 2140 KB Output is correct
90 Correct 12 ms 1976 KB Output is correct
91 Correct 17 ms 3292 KB Output is correct
92 Correct 18 ms 3280 KB Output is correct
93 Correct 19 ms 3420 KB Output is correct
94 Correct 17 ms 3420 KB Output is correct
95 Correct 18 ms 3208 KB Output is correct
96 Correct 22 ms 4444 KB Output is correct
97 Correct 19 ms 4444 KB Output is correct
98 Correct 22 ms 4436 KB Output is correct
99 Correct 19 ms 4440 KB Output is correct
100 Correct 20 ms 4440 KB Output is correct
101 Correct 21 ms 4444 KB Output is correct
102 Correct 19 ms 4444 KB Output is correct
103 Correct 20 ms 4424 KB Output is correct
104 Correct 19 ms 4320 KB Output is correct
105 Correct 22 ms 4440 KB Output is correct
106 Correct 19 ms 4700 KB Output is correct
107 Correct 19 ms 4876 KB Output is correct
108 Correct 19 ms 4696 KB Output is correct
109 Correct 20 ms 4692 KB Output is correct
110 Correct 18 ms 4856 KB Output is correct
111 Correct 20 ms 4700 KB Output is correct
112 Correct 20 ms 4688 KB Output is correct
113 Correct 20 ms 4696 KB Output is correct
114 Correct 19 ms 4744 KB Output is correct
115 Correct 19 ms 4700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 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 348 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 1 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 0 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 5 ms 1276 KB Output is correct
15 Correct 10 ms 2016 KB Output is correct
16 Correct 14 ms 2648 KB Output is correct
17 Correct 16 ms 3420 KB Output is correct
18 Correct 13 ms 2660 KB Output is correct
19 Correct 14 ms 2640 KB Output is correct
20 Correct 15 ms 2904 KB Output is correct
21 Correct 15 ms 2652 KB Output is correct
22 Correct 14 ms 2692 KB Output is correct
23 Correct 13 ms 2648 KB Output is correct
24 Correct 14 ms 2904 KB Output is correct
25 Correct 13 ms 2652 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 5 ms 1224 KB Output is correct
30 Correct 9 ms 2036 KB Output is correct
31 Correct 14 ms 2904 KB Output is correct
32 Correct 14 ms 2660 KB Output is correct
33 Correct 15 ms 2672 KB Output is correct
34 Correct 17 ms 2684 KB Output is correct
35 Correct 14 ms 2660 KB Output is correct
36 Correct 16 ms 2652 KB Output is correct
37 Correct 15 ms 2808 KB Output is correct
38 Correct 15 ms 2780 KB Output is correct
39 Correct 15 ms 2652 KB Output is correct
40 Correct 15 ms 2652 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 1 ms 348 KB Output is correct
45 Correct 1 ms 348 KB Output is correct
46 Correct 1 ms 348 KB Output is correct
47 Correct 3 ms 860 KB Output is correct
48 Correct 3 ms 856 KB Output is correct
49 Correct 6 ms 1112 KB Output is correct
50 Correct 10 ms 2044 KB Output is correct
51 Correct 16 ms 2596 KB Output is correct
52 Correct 15 ms 2308 KB Output is correct
53 Correct 15 ms 2396 KB Output is correct
54 Correct 14 ms 2396 KB Output is correct
55 Correct 14 ms 2396 KB Output is correct
56 Correct 16 ms 2396 KB Output is correct
57 Correct 15 ms 2228 KB Output is correct
58 Correct 14 ms 2396 KB Output is correct
59 Correct 15 ms 2284 KB Output is correct
60 Correct 15 ms 2396 KB Output is correct
61 Correct 15 ms 2396 KB Output is correct
62 Correct 15 ms 2396 KB Output is correct
63 Correct 15 ms 2396 KB Output is correct
64 Correct 15 ms 2284 KB Output is correct
65 Correct 19 ms 2392 KB Output is correct
66 Correct 15 ms 2396 KB Output is correct
67 Correct 14 ms 2404 KB Output is correct
68 Correct 15 ms 2396 KB Output is correct
69 Correct 15 ms 2328 KB Output is correct
70 Correct 14 ms 2396 KB Output is correct
71 Correct 3 ms 856 KB Output is correct
72 Correct 3 ms 860 KB Output is correct
73 Correct 3 ms 860 KB Output is correct
74 Correct 3 ms 812 KB Output is correct
75 Correct 3 ms 860 KB Output is correct
76 Correct 5 ms 1372 KB Output is correct
77 Correct 6 ms 1372 KB Output is correct
78 Correct 5 ms 1372 KB Output is correct
79 Correct 6 ms 1372 KB Output is correct
80 Correct 6 ms 1244 KB Output is correct
81 Correct 11 ms 1884 KB Output is correct
82 Correct 10 ms 1896 KB Output is correct
83 Correct 11 ms 1884 KB Output is correct
84 Correct 11 ms 1884 KB Output is correct
85 Correct 10 ms 1880 KB Output is correct
86 Correct 11 ms 2140 KB Output is correct
87 Correct 11 ms 2056 KB Output is correct
88 Correct 11 ms 2392 KB Output is correct
89 Correct 11 ms 2140 KB Output is correct
90 Correct 12 ms 1976 KB Output is correct
91 Correct 17 ms 3292 KB Output is correct
92 Correct 18 ms 3280 KB Output is correct
93 Correct 19 ms 3420 KB Output is correct
94 Correct 17 ms 3420 KB Output is correct
95 Correct 18 ms 3208 KB Output is correct
96 Correct 22 ms 4444 KB Output is correct
97 Correct 19 ms 4444 KB Output is correct
98 Correct 22 ms 4436 KB Output is correct
99 Correct 19 ms 4440 KB Output is correct
100 Correct 20 ms 4440 KB Output is correct
101 Correct 21 ms 4444 KB Output is correct
102 Correct 19 ms 4444 KB Output is correct
103 Correct 20 ms 4424 KB Output is correct
104 Correct 19 ms 4320 KB Output is correct
105 Correct 22 ms 4440 KB Output is correct
106 Correct 19 ms 4700 KB Output is correct
107 Correct 19 ms 4876 KB Output is correct
108 Correct 19 ms 4696 KB Output is correct
109 Correct 20 ms 4692 KB Output is correct
110 Correct 18 ms 4856 KB Output is correct
111 Correct 20 ms 4700 KB Output is correct
112 Correct 20 ms 4688 KB Output is correct
113 Correct 20 ms 4696 KB Output is correct
114 Correct 19 ms 4744 KB Output is correct
115 Correct 19 ms 4700 KB Output is correct
116 Correct 910 ms 1872 KB Output is correct
117 Correct 603 ms 1744 KB Output is correct
118 Correct 2514 ms 2168 KB Output is correct
119 Correct 705 ms 2132 KB Output is correct
120 Correct 627 ms 2004 KB Output is correct
121 Correct 872 ms 2388 KB Output is correct
122 Correct 680 ms 2388 KB Output is correct
123 Correct 1712 ms 2644 KB Output is correct
124 Correct 693 ms 2852 KB Output is correct
125 Correct 418 ms 2900 KB Output is correct
126 Execution timed out 7028 ms 2640 KB Time limit exceeded
127 Halted 0 ms 0 KB -