답안 #1084177

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1084177 2024-09-05T14:19:38 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=800;
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';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 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 0 ms 348 KB Output is correct
9 Correct 0 ms 448 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 396 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 12 ms 1140 KB Output is correct
5 Correct 19 ms 2136 KB Output is correct
6 Correct 29 ms 2640 KB Output is correct
7 Correct 32 ms 3412 KB Output is correct
8 Correct 33 ms 2388 KB Output is correct
9 Correct 32 ms 2644 KB Output is correct
10 Correct 31 ms 2904 KB Output is correct
11 Correct 32 ms 2800 KB Output is correct
12 Correct 29 ms 2640 KB Output is correct
13 Correct 29 ms 2640 KB Output is correct
14 Correct 29 ms 2808 KB Output is correct
15 Correct 30 ms 2780 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 396 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 12 ms 1140 KB Output is correct
5 Correct 19 ms 2136 KB Output is correct
6 Correct 29 ms 2640 KB Output is correct
7 Correct 32 ms 3412 KB Output is correct
8 Correct 33 ms 2388 KB Output is correct
9 Correct 32 ms 2644 KB Output is correct
10 Correct 31 ms 2904 KB Output is correct
11 Correct 32 ms 2800 KB Output is correct
12 Correct 29 ms 2640 KB Output is correct
13 Correct 29 ms 2640 KB Output is correct
14 Correct 29 ms 2808 KB Output is correct
15 Correct 30 ms 2780 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 11 ms 1120 KB Output is correct
20 Correct 22 ms 1880 KB Output is correct
21 Correct 32 ms 2644 KB Output is correct
22 Correct 32 ms 2652 KB Output is correct
23 Correct 33 ms 2640 KB Output is correct
24 Correct 31 ms 2652 KB Output is correct
25 Correct 35 ms 2652 KB Output is correct
26 Correct 35 ms 2476 KB Output is correct
27 Correct 35 ms 2708 KB Output is correct
28 Correct 31 ms 2908 KB Output is correct
29 Correct 31 ms 2472 KB Output is correct
30 Correct 32 ms 2748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 396 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 12 ms 1140 KB Output is correct
5 Correct 19 ms 2136 KB Output is correct
6 Correct 29 ms 2640 KB Output is correct
7 Correct 32 ms 3412 KB Output is correct
8 Correct 33 ms 2388 KB Output is correct
9 Correct 32 ms 2644 KB Output is correct
10 Correct 31 ms 2904 KB Output is correct
11 Correct 32 ms 2800 KB Output is correct
12 Correct 29 ms 2640 KB Output is correct
13 Correct 29 ms 2640 KB Output is correct
14 Correct 29 ms 2808 KB Output is correct
15 Correct 30 ms 2780 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 11 ms 1120 KB Output is correct
20 Correct 22 ms 1880 KB Output is correct
21 Correct 32 ms 2644 KB Output is correct
22 Correct 32 ms 2652 KB Output is correct
23 Correct 33 ms 2640 KB Output is correct
24 Correct 31 ms 2652 KB Output is correct
25 Correct 35 ms 2652 KB Output is correct
26 Correct 35 ms 2476 KB Output is correct
27 Correct 35 ms 2708 KB Output is correct
28 Correct 31 ms 2908 KB Output is correct
29 Correct 31 ms 2472 KB Output is correct
30 Correct 32 ms 2748 KB Output is correct
31 Correct 1 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 344 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 7 ms 604 KB Output is correct
39 Correct 15 ms 1116 KB Output is correct
40 Correct 26 ms 1872 KB Output is correct
41 Correct 36 ms 2552 KB Output is correct
42 Correct 37 ms 2640 KB Output is correct
43 Correct 36 ms 2640 KB Output is correct
44 Correct 38 ms 2644 KB Output is correct
45 Correct 38 ms 2764 KB Output is correct
46 Correct 43 ms 2720 KB Output is correct
47 Correct 39 ms 2752 KB Output is correct
48 Correct 39 ms 2532 KB Output is correct
49 Correct 37 ms 2640 KB Output is correct
50 Correct 42 ms 2676 KB Output is correct
51 Correct 41 ms 2612 KB Output is correct
52 Correct 38 ms 2644 KB Output is correct
53 Correct 40 ms 2640 KB Output is correct
54 Correct 37 ms 2540 KB Output is correct
55 Correct 41 ms 2588 KB Output is correct
56 Correct 37 ms 2548 KB Output is correct
57 Correct 36 ms 2560 KB Output is correct
58 Correct 37 ms 2716 KB Output is correct
59 Correct 36 ms 2652 KB Output is correct
60 Correct 37 ms 2640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 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 0 ms 348 KB Output is correct
9 Correct 0 ms 448 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 396 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 12 ms 1140 KB Output is correct
15 Correct 19 ms 2136 KB Output is correct
16 Correct 29 ms 2640 KB Output is correct
17 Correct 32 ms 3412 KB Output is correct
18 Correct 33 ms 2388 KB Output is correct
19 Correct 32 ms 2644 KB Output is correct
20 Correct 31 ms 2904 KB Output is correct
21 Correct 32 ms 2800 KB Output is correct
22 Correct 29 ms 2640 KB Output is correct
23 Correct 29 ms 2640 KB Output is correct
24 Correct 29 ms 2808 KB Output is correct
25 Correct 30 ms 2780 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 11 ms 1120 KB Output is correct
30 Correct 22 ms 1880 KB Output is correct
31 Correct 32 ms 2644 KB Output is correct
32 Correct 32 ms 2652 KB Output is correct
33 Correct 33 ms 2640 KB Output is correct
34 Correct 31 ms 2652 KB Output is correct
35 Correct 35 ms 2652 KB Output is correct
36 Correct 35 ms 2476 KB Output is correct
37 Correct 35 ms 2708 KB Output is correct
38 Correct 31 ms 2908 KB Output is correct
39 Correct 31 ms 2472 KB Output is correct
40 Correct 32 ms 2748 KB Output is correct
41 Correct 1 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 344 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 7 ms 604 KB Output is correct
49 Correct 15 ms 1116 KB Output is correct
50 Correct 26 ms 1872 KB Output is correct
51 Correct 36 ms 2552 KB Output is correct
52 Correct 37 ms 2640 KB Output is correct
53 Correct 36 ms 2640 KB Output is correct
54 Correct 38 ms 2644 KB Output is correct
55 Correct 38 ms 2764 KB Output is correct
56 Correct 43 ms 2720 KB Output is correct
57 Correct 39 ms 2752 KB Output is correct
58 Correct 39 ms 2532 KB Output is correct
59 Correct 37 ms 2640 KB Output is correct
60 Correct 42 ms 2676 KB Output is correct
61 Correct 41 ms 2612 KB Output is correct
62 Correct 38 ms 2644 KB Output is correct
63 Correct 40 ms 2640 KB Output is correct
64 Correct 37 ms 2540 KB Output is correct
65 Correct 41 ms 2588 KB Output is correct
66 Correct 37 ms 2548 KB Output is correct
67 Correct 36 ms 2560 KB Output is correct
68 Correct 37 ms 2716 KB Output is correct
69 Correct 36 ms 2652 KB Output is correct
70 Correct 37 ms 2640 KB Output is correct
71 Correct 8 ms 860 KB Output is correct
72 Correct 7 ms 760 KB Output is correct
73 Correct 7 ms 860 KB Output is correct
74 Correct 7 ms 868 KB Output is correct
75 Correct 7 ms 772 KB Output is correct
76 Correct 14 ms 1112 KB Output is correct
77 Correct 14 ms 1220 KB Output is correct
78 Correct 15 ms 1180 KB Output is correct
79 Correct 14 ms 1116 KB Output is correct
80 Correct 15 ms 1200 KB Output is correct
81 Correct 28 ms 2140 KB Output is correct
82 Correct 29 ms 2140 KB Output is correct
83 Correct 32 ms 2136 KB Output is correct
84 Correct 31 ms 2132 KB Output is correct
85 Correct 28 ms 2140 KB Output is correct
86 Correct 30 ms 2408 KB Output is correct
87 Correct 33 ms 2384 KB Output is correct
88 Correct 33 ms 2260 KB Output is correct
89 Correct 31 ms 2396 KB Output is correct
90 Correct 32 ms 2388 KB Output is correct
91 Correct 49 ms 3924 KB Output is correct
92 Correct 49 ms 3924 KB Output is correct
93 Correct 49 ms 3924 KB Output is correct
94 Correct 48 ms 3920 KB Output is correct
95 Correct 47 ms 3924 KB Output is correct
96 Correct 52 ms 4948 KB Output is correct
97 Correct 56 ms 4944 KB Output is correct
98 Correct 54 ms 4944 KB Output is correct
99 Correct 52 ms 4948 KB Output is correct
100 Correct 55 ms 4896 KB Output is correct
101 Correct 54 ms 5040 KB Output is correct
102 Correct 55 ms 4944 KB Output is correct
103 Correct 57 ms 4996 KB Output is correct
104 Correct 56 ms 4948 KB Output is correct
105 Correct 57 ms 4944 KB Output is correct
106 Correct 55 ms 5460 KB Output is correct
107 Correct 54 ms 5452 KB Output is correct
108 Correct 56 ms 5296 KB Output is correct
109 Correct 63 ms 5476 KB Output is correct
110 Correct 53 ms 5292 KB Output is correct
111 Correct 54 ms 5456 KB Output is correct
112 Correct 54 ms 5240 KB Output is correct
113 Correct 56 ms 5456 KB Output is correct
114 Correct 54 ms 5448 KB Output is correct
115 Correct 52 ms 5460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 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 0 ms 348 KB Output is correct
9 Correct 0 ms 448 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 396 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 12 ms 1140 KB Output is correct
15 Correct 19 ms 2136 KB Output is correct
16 Correct 29 ms 2640 KB Output is correct
17 Correct 32 ms 3412 KB Output is correct
18 Correct 33 ms 2388 KB Output is correct
19 Correct 32 ms 2644 KB Output is correct
20 Correct 31 ms 2904 KB Output is correct
21 Correct 32 ms 2800 KB Output is correct
22 Correct 29 ms 2640 KB Output is correct
23 Correct 29 ms 2640 KB Output is correct
24 Correct 29 ms 2808 KB Output is correct
25 Correct 30 ms 2780 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 11 ms 1120 KB Output is correct
30 Correct 22 ms 1880 KB Output is correct
31 Correct 32 ms 2644 KB Output is correct
32 Correct 32 ms 2652 KB Output is correct
33 Correct 33 ms 2640 KB Output is correct
34 Correct 31 ms 2652 KB Output is correct
35 Correct 35 ms 2652 KB Output is correct
36 Correct 35 ms 2476 KB Output is correct
37 Correct 35 ms 2708 KB Output is correct
38 Correct 31 ms 2908 KB Output is correct
39 Correct 31 ms 2472 KB Output is correct
40 Correct 32 ms 2748 KB Output is correct
41 Correct 1 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 344 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 7 ms 604 KB Output is correct
49 Correct 15 ms 1116 KB Output is correct
50 Correct 26 ms 1872 KB Output is correct
51 Correct 36 ms 2552 KB Output is correct
52 Correct 37 ms 2640 KB Output is correct
53 Correct 36 ms 2640 KB Output is correct
54 Correct 38 ms 2644 KB Output is correct
55 Correct 38 ms 2764 KB Output is correct
56 Correct 43 ms 2720 KB Output is correct
57 Correct 39 ms 2752 KB Output is correct
58 Correct 39 ms 2532 KB Output is correct
59 Correct 37 ms 2640 KB Output is correct
60 Correct 42 ms 2676 KB Output is correct
61 Correct 41 ms 2612 KB Output is correct
62 Correct 38 ms 2644 KB Output is correct
63 Correct 40 ms 2640 KB Output is correct
64 Correct 37 ms 2540 KB Output is correct
65 Correct 41 ms 2588 KB Output is correct
66 Correct 37 ms 2548 KB Output is correct
67 Correct 36 ms 2560 KB Output is correct
68 Correct 37 ms 2716 KB Output is correct
69 Correct 36 ms 2652 KB Output is correct
70 Correct 37 ms 2640 KB Output is correct
71 Correct 8 ms 860 KB Output is correct
72 Correct 7 ms 760 KB Output is correct
73 Correct 7 ms 860 KB Output is correct
74 Correct 7 ms 868 KB Output is correct
75 Correct 7 ms 772 KB Output is correct
76 Correct 14 ms 1112 KB Output is correct
77 Correct 14 ms 1220 KB Output is correct
78 Correct 15 ms 1180 KB Output is correct
79 Correct 14 ms 1116 KB Output is correct
80 Correct 15 ms 1200 KB Output is correct
81 Correct 28 ms 2140 KB Output is correct
82 Correct 29 ms 2140 KB Output is correct
83 Correct 32 ms 2136 KB Output is correct
84 Correct 31 ms 2132 KB Output is correct
85 Correct 28 ms 2140 KB Output is correct
86 Correct 30 ms 2408 KB Output is correct
87 Correct 33 ms 2384 KB Output is correct
88 Correct 33 ms 2260 KB Output is correct
89 Correct 31 ms 2396 KB Output is correct
90 Correct 32 ms 2388 KB Output is correct
91 Correct 49 ms 3924 KB Output is correct
92 Correct 49 ms 3924 KB Output is correct
93 Correct 49 ms 3924 KB Output is correct
94 Correct 48 ms 3920 KB Output is correct
95 Correct 47 ms 3924 KB Output is correct
96 Correct 52 ms 4948 KB Output is correct
97 Correct 56 ms 4944 KB Output is correct
98 Correct 54 ms 4944 KB Output is correct
99 Correct 52 ms 4948 KB Output is correct
100 Correct 55 ms 4896 KB Output is correct
101 Correct 54 ms 5040 KB Output is correct
102 Correct 55 ms 4944 KB Output is correct
103 Correct 57 ms 4996 KB Output is correct
104 Correct 56 ms 4948 KB Output is correct
105 Correct 57 ms 4944 KB Output is correct
106 Correct 55 ms 5460 KB Output is correct
107 Correct 54 ms 5452 KB Output is correct
108 Correct 56 ms 5296 KB Output is correct
109 Correct 63 ms 5476 KB Output is correct
110 Correct 53 ms 5292 KB Output is correct
111 Correct 54 ms 5456 KB Output is correct
112 Correct 54 ms 5240 KB Output is correct
113 Correct 56 ms 5456 KB Output is correct
114 Correct 54 ms 5448 KB Output is correct
115 Correct 52 ms 5460 KB Output is correct
116 Correct 961 ms 2212 KB Output is correct
117 Correct 682 ms 2384 KB Output is correct
118 Correct 2469 ms 2852 KB Output is correct
119 Correct 766 ms 2900 KB Output is correct
120 Correct 680 ms 2896 KB Output is correct
121 Correct 947 ms 3288 KB Output is correct
122 Correct 764 ms 3664 KB Output is correct
123 Correct 1782 ms 4196 KB Output is correct
124 Correct 785 ms 4304 KB Output is correct
125 Correct 534 ms 4432 KB Output is correct
126 Execution timed out 7041 ms 4116 KB Time limit exceeded
127 Halted 0 ms 0 KB -