답안 #626029

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
626029 2022-08-11T06:41:45 Z berr Diversity (CEOI21_diversity) C++17
64 / 100
7000 ms 15332 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 n=0, k=0;
    for(auto [i, l]: freq)
    {
        n+=i*l;
        k+=l;
    }
 
    int mod=1;
 
    int l=0, r=0, ans=0;
 
    for(auto [i, j]: freq)
    {
        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;
    }
    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=200, cnt=0; cin>>n>>q;
 
    vector<int> a(n), ans(q);
    vector<array<int, 3>> query[n/b+1];
 
 
    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(300005);
 
 
    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]--;
                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:121: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]
  121 |     for(int i=0; i<ans.size(); i++) cout<<ans[i]<<"\n";
      |                  ~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 2 ms 2620 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 2 ms 2624 KB Output is correct
7 Correct 2 ms 2624 KB Output is correct
8 Correct 1 ms 2644 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 1 ms 2644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 3 ms 2900 KB Output is correct
4 Correct 28 ms 5272 KB Output is correct
5 Correct 62 ms 9128 KB Output is correct
6 Correct 89 ms 8812 KB Output is correct
7 Correct 105 ms 15332 KB Output is correct
8 Correct 84 ms 8416 KB Output is correct
9 Correct 89 ms 8576 KB Output is correct
10 Correct 103 ms 11508 KB Output is correct
11 Correct 87 ms 9692 KB Output is correct
12 Correct 84 ms 8520 KB Output is correct
13 Correct 82 ms 8268 KB Output is correct
14 Correct 88 ms 9996 KB Output is correct
15 Correct 94 ms 9456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 3 ms 2900 KB Output is correct
4 Correct 28 ms 5272 KB Output is correct
5 Correct 62 ms 9128 KB Output is correct
6 Correct 89 ms 8812 KB Output is correct
7 Correct 105 ms 15332 KB Output is correct
8 Correct 84 ms 8416 KB Output is correct
9 Correct 89 ms 8576 KB Output is correct
10 Correct 103 ms 11508 KB Output is correct
11 Correct 87 ms 9692 KB Output is correct
12 Correct 84 ms 8520 KB Output is correct
13 Correct 82 ms 8268 KB Output is correct
14 Correct 88 ms 9996 KB Output is correct
15 Correct 94 ms 9456 KB Output is correct
16 Correct 1 ms 2644 KB Output is correct
17 Correct 2 ms 2644 KB Output is correct
18 Correct 3 ms 2760 KB Output is correct
19 Correct 26 ms 4724 KB Output is correct
20 Correct 53 ms 6272 KB Output is correct
21 Correct 86 ms 8900 KB Output is correct
22 Correct 87 ms 7636 KB Output is correct
23 Correct 85 ms 8396 KB Output is correct
24 Correct 86 ms 7368 KB Output is correct
25 Correct 95 ms 7888 KB Output is correct
26 Correct 87 ms 7688 KB Output is correct
27 Correct 86 ms 8140 KB Output is correct
28 Correct 101 ms 10124 KB Output is correct
29 Correct 90 ms 7808 KB Output is correct
30 Correct 83 ms 7964 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 3 ms 2900 KB Output is correct
4 Correct 28 ms 5272 KB Output is correct
5 Correct 62 ms 9128 KB Output is correct
6 Correct 89 ms 8812 KB Output is correct
7 Correct 105 ms 15332 KB Output is correct
8 Correct 84 ms 8416 KB Output is correct
9 Correct 89 ms 8576 KB Output is correct
10 Correct 103 ms 11508 KB Output is correct
11 Correct 87 ms 9692 KB Output is correct
12 Correct 84 ms 8520 KB Output is correct
13 Correct 82 ms 8268 KB Output is correct
14 Correct 88 ms 9996 KB Output is correct
15 Correct 94 ms 9456 KB Output is correct
16 Correct 1 ms 2644 KB Output is correct
17 Correct 2 ms 2644 KB Output is correct
18 Correct 3 ms 2760 KB Output is correct
19 Correct 26 ms 4724 KB Output is correct
20 Correct 53 ms 6272 KB Output is correct
21 Correct 86 ms 8900 KB Output is correct
22 Correct 87 ms 7636 KB Output is correct
23 Correct 85 ms 8396 KB Output is correct
24 Correct 86 ms 7368 KB Output is correct
25 Correct 95 ms 7888 KB Output is correct
26 Correct 87 ms 7688 KB Output is correct
27 Correct 86 ms 8140 KB Output is correct
28 Correct 101 ms 10124 KB Output is correct
29 Correct 90 ms 7808 KB Output is correct
30 Correct 83 ms 7964 KB Output is correct
31 Correct 2 ms 2644 KB Output is correct
32 Correct 2 ms 2644 KB Output is correct
33 Correct 2 ms 2644 KB Output is correct
34 Correct 3 ms 2772 KB Output is correct
35 Correct 3 ms 2772 KB Output is correct
36 Correct 3 ms 2764 KB Output is correct
37 Correct 8 ms 3284 KB Output is correct
38 Correct 8 ms 3284 KB Output is correct
39 Correct 15 ms 3696 KB Output is correct
40 Correct 31 ms 4540 KB Output is correct
41 Correct 46 ms 5340 KB Output is correct
42 Correct 46 ms 5324 KB Output is correct
43 Correct 50 ms 5336 KB Output is correct
44 Correct 48 ms 5336 KB Output is correct
45 Correct 47 ms 5320 KB Output is correct
46 Correct 50 ms 5276 KB Output is correct
47 Correct 50 ms 5324 KB Output is correct
48 Correct 52 ms 5296 KB Output is correct
49 Correct 49 ms 5292 KB Output is correct
50 Correct 48 ms 5260 KB Output is correct
51 Correct 49 ms 5312 KB Output is correct
52 Correct 50 ms 5320 KB Output is correct
53 Correct 62 ms 5448 KB Output is correct
54 Correct 49 ms 5336 KB Output is correct
55 Correct 47 ms 5312 KB Output is correct
56 Correct 47 ms 5356 KB Output is correct
57 Correct 46 ms 5324 KB Output is correct
58 Correct 49 ms 5356 KB Output is correct
59 Correct 49 ms 5320 KB Output is correct
60 Correct 48 ms 5324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 2 ms 2620 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 2 ms 2624 KB Output is correct
7 Correct 2 ms 2624 KB Output is correct
8 Correct 1 ms 2644 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 1 ms 2644 KB Output is correct
11 Correct 2 ms 2644 KB Output is correct
12 Correct 2 ms 2644 KB Output is correct
13 Correct 3 ms 2900 KB Output is correct
14 Correct 28 ms 5272 KB Output is correct
15 Correct 62 ms 9128 KB Output is correct
16 Correct 89 ms 8812 KB Output is correct
17 Correct 105 ms 15332 KB Output is correct
18 Correct 84 ms 8416 KB Output is correct
19 Correct 89 ms 8576 KB Output is correct
20 Correct 103 ms 11508 KB Output is correct
21 Correct 87 ms 9692 KB Output is correct
22 Correct 84 ms 8520 KB Output is correct
23 Correct 82 ms 8268 KB Output is correct
24 Correct 88 ms 9996 KB Output is correct
25 Correct 94 ms 9456 KB Output is correct
26 Correct 1 ms 2644 KB Output is correct
27 Correct 2 ms 2644 KB Output is correct
28 Correct 3 ms 2760 KB Output is correct
29 Correct 26 ms 4724 KB Output is correct
30 Correct 53 ms 6272 KB Output is correct
31 Correct 86 ms 8900 KB Output is correct
32 Correct 87 ms 7636 KB Output is correct
33 Correct 85 ms 8396 KB Output is correct
34 Correct 86 ms 7368 KB Output is correct
35 Correct 95 ms 7888 KB Output is correct
36 Correct 87 ms 7688 KB Output is correct
37 Correct 86 ms 8140 KB Output is correct
38 Correct 101 ms 10124 KB Output is correct
39 Correct 90 ms 7808 KB Output is correct
40 Correct 83 ms 7964 KB Output is correct
41 Correct 2 ms 2644 KB Output is correct
42 Correct 2 ms 2644 KB Output is correct
43 Correct 2 ms 2644 KB Output is correct
44 Correct 3 ms 2772 KB Output is correct
45 Correct 3 ms 2772 KB Output is correct
46 Correct 3 ms 2764 KB Output is correct
47 Correct 8 ms 3284 KB Output is correct
48 Correct 8 ms 3284 KB Output is correct
49 Correct 15 ms 3696 KB Output is correct
50 Correct 31 ms 4540 KB Output is correct
51 Correct 46 ms 5340 KB Output is correct
52 Correct 46 ms 5324 KB Output is correct
53 Correct 50 ms 5336 KB Output is correct
54 Correct 48 ms 5336 KB Output is correct
55 Correct 47 ms 5320 KB Output is correct
56 Correct 50 ms 5276 KB Output is correct
57 Correct 50 ms 5324 KB Output is correct
58 Correct 52 ms 5296 KB Output is correct
59 Correct 49 ms 5292 KB Output is correct
60 Correct 48 ms 5260 KB Output is correct
61 Correct 49 ms 5312 KB Output is correct
62 Correct 50 ms 5320 KB Output is correct
63 Correct 62 ms 5448 KB Output is correct
64 Correct 49 ms 5336 KB Output is correct
65 Correct 47 ms 5312 KB Output is correct
66 Correct 47 ms 5356 KB Output is correct
67 Correct 46 ms 5324 KB Output is correct
68 Correct 49 ms 5356 KB Output is correct
69 Correct 49 ms 5320 KB Output is correct
70 Correct 48 ms 5324 KB Output is correct
71 Correct 8 ms 3272 KB Output is correct
72 Correct 8 ms 3284 KB Output is correct
73 Correct 8 ms 3284 KB Output is correct
74 Correct 8 ms 3284 KB Output is correct
75 Correct 9 ms 3228 KB Output is correct
76 Correct 14 ms 3664 KB Output is correct
77 Correct 14 ms 3672 KB Output is correct
78 Correct 14 ms 3668 KB Output is correct
79 Correct 14 ms 3668 KB Output is correct
80 Correct 16 ms 3664 KB Output is correct
81 Correct 28 ms 4436 KB Output is correct
82 Correct 24 ms 4436 KB Output is correct
83 Correct 24 ms 4416 KB Output is correct
84 Correct 26 ms 4416 KB Output is correct
85 Correct 23 ms 4476 KB Output is correct
86 Correct 24 ms 4424 KB Output is correct
87 Correct 23 ms 4468 KB Output is correct
88 Correct 24 ms 4424 KB Output is correct
89 Correct 24 ms 4420 KB Output is correct
90 Correct 23 ms 4420 KB Output is correct
91 Correct 32 ms 5204 KB Output is correct
92 Correct 30 ms 5204 KB Output is correct
93 Correct 30 ms 5232 KB Output is correct
94 Correct 30 ms 5204 KB Output is correct
95 Correct 31 ms 5332 KB Output is correct
96 Correct 33 ms 5192 KB Output is correct
97 Correct 33 ms 5208 KB Output is correct
98 Correct 31 ms 5192 KB Output is correct
99 Correct 36 ms 5240 KB Output is correct
100 Correct 37 ms 5196 KB Output is correct
101 Correct 33 ms 5196 KB Output is correct
102 Correct 31 ms 5240 KB Output is correct
103 Correct 32 ms 5248 KB Output is correct
104 Correct 32 ms 5208 KB Output is correct
105 Correct 32 ms 5256 KB Output is correct
106 Correct 31 ms 5208 KB Output is correct
107 Correct 31 ms 5332 KB Output is correct
108 Correct 32 ms 5204 KB Output is correct
109 Correct 37 ms 5248 KB Output is correct
110 Correct 29 ms 5208 KB Output is correct
111 Correct 30 ms 5216 KB Output is correct
112 Correct 29 ms 5220 KB Output is correct
113 Correct 35 ms 5208 KB Output is correct
114 Correct 29 ms 5204 KB Output is correct
115 Correct 28 ms 5196 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 2 ms 2620 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 2 ms 2624 KB Output is correct
7 Correct 2 ms 2624 KB Output is correct
8 Correct 1 ms 2644 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 1 ms 2644 KB Output is correct
11 Correct 2 ms 2644 KB Output is correct
12 Correct 2 ms 2644 KB Output is correct
13 Correct 3 ms 2900 KB Output is correct
14 Correct 28 ms 5272 KB Output is correct
15 Correct 62 ms 9128 KB Output is correct
16 Correct 89 ms 8812 KB Output is correct
17 Correct 105 ms 15332 KB Output is correct
18 Correct 84 ms 8416 KB Output is correct
19 Correct 89 ms 8576 KB Output is correct
20 Correct 103 ms 11508 KB Output is correct
21 Correct 87 ms 9692 KB Output is correct
22 Correct 84 ms 8520 KB Output is correct
23 Correct 82 ms 8268 KB Output is correct
24 Correct 88 ms 9996 KB Output is correct
25 Correct 94 ms 9456 KB Output is correct
26 Correct 1 ms 2644 KB Output is correct
27 Correct 2 ms 2644 KB Output is correct
28 Correct 3 ms 2760 KB Output is correct
29 Correct 26 ms 4724 KB Output is correct
30 Correct 53 ms 6272 KB Output is correct
31 Correct 86 ms 8900 KB Output is correct
32 Correct 87 ms 7636 KB Output is correct
33 Correct 85 ms 8396 KB Output is correct
34 Correct 86 ms 7368 KB Output is correct
35 Correct 95 ms 7888 KB Output is correct
36 Correct 87 ms 7688 KB Output is correct
37 Correct 86 ms 8140 KB Output is correct
38 Correct 101 ms 10124 KB Output is correct
39 Correct 90 ms 7808 KB Output is correct
40 Correct 83 ms 7964 KB Output is correct
41 Correct 2 ms 2644 KB Output is correct
42 Correct 2 ms 2644 KB Output is correct
43 Correct 2 ms 2644 KB Output is correct
44 Correct 3 ms 2772 KB Output is correct
45 Correct 3 ms 2772 KB Output is correct
46 Correct 3 ms 2764 KB Output is correct
47 Correct 8 ms 3284 KB Output is correct
48 Correct 8 ms 3284 KB Output is correct
49 Correct 15 ms 3696 KB Output is correct
50 Correct 31 ms 4540 KB Output is correct
51 Correct 46 ms 5340 KB Output is correct
52 Correct 46 ms 5324 KB Output is correct
53 Correct 50 ms 5336 KB Output is correct
54 Correct 48 ms 5336 KB Output is correct
55 Correct 47 ms 5320 KB Output is correct
56 Correct 50 ms 5276 KB Output is correct
57 Correct 50 ms 5324 KB Output is correct
58 Correct 52 ms 5296 KB Output is correct
59 Correct 49 ms 5292 KB Output is correct
60 Correct 48 ms 5260 KB Output is correct
61 Correct 49 ms 5312 KB Output is correct
62 Correct 50 ms 5320 KB Output is correct
63 Correct 62 ms 5448 KB Output is correct
64 Correct 49 ms 5336 KB Output is correct
65 Correct 47 ms 5312 KB Output is correct
66 Correct 47 ms 5356 KB Output is correct
67 Correct 46 ms 5324 KB Output is correct
68 Correct 49 ms 5356 KB Output is correct
69 Correct 49 ms 5320 KB Output is correct
70 Correct 48 ms 5324 KB Output is correct
71 Correct 8 ms 3272 KB Output is correct
72 Correct 8 ms 3284 KB Output is correct
73 Correct 8 ms 3284 KB Output is correct
74 Correct 8 ms 3284 KB Output is correct
75 Correct 9 ms 3228 KB Output is correct
76 Correct 14 ms 3664 KB Output is correct
77 Correct 14 ms 3672 KB Output is correct
78 Correct 14 ms 3668 KB Output is correct
79 Correct 14 ms 3668 KB Output is correct
80 Correct 16 ms 3664 KB Output is correct
81 Correct 28 ms 4436 KB Output is correct
82 Correct 24 ms 4436 KB Output is correct
83 Correct 24 ms 4416 KB Output is correct
84 Correct 26 ms 4416 KB Output is correct
85 Correct 23 ms 4476 KB Output is correct
86 Correct 24 ms 4424 KB Output is correct
87 Correct 23 ms 4468 KB Output is correct
88 Correct 24 ms 4424 KB Output is correct
89 Correct 24 ms 4420 KB Output is correct
90 Correct 23 ms 4420 KB Output is correct
91 Correct 32 ms 5204 KB Output is correct
92 Correct 30 ms 5204 KB Output is correct
93 Correct 30 ms 5232 KB Output is correct
94 Correct 30 ms 5204 KB Output is correct
95 Correct 31 ms 5332 KB Output is correct
96 Correct 33 ms 5192 KB Output is correct
97 Correct 33 ms 5208 KB Output is correct
98 Correct 31 ms 5192 KB Output is correct
99 Correct 36 ms 5240 KB Output is correct
100 Correct 37 ms 5196 KB Output is correct
101 Correct 33 ms 5196 KB Output is correct
102 Correct 31 ms 5240 KB Output is correct
103 Correct 32 ms 5248 KB Output is correct
104 Correct 32 ms 5208 KB Output is correct
105 Correct 32 ms 5256 KB Output is correct
106 Correct 31 ms 5208 KB Output is correct
107 Correct 31 ms 5332 KB Output is correct
108 Correct 32 ms 5204 KB Output is correct
109 Correct 37 ms 5248 KB Output is correct
110 Correct 29 ms 5208 KB Output is correct
111 Correct 30 ms 5216 KB Output is correct
112 Correct 29 ms 5220 KB Output is correct
113 Correct 35 ms 5208 KB Output is correct
114 Correct 29 ms 5204 KB Output is correct
115 Correct 28 ms 5196 KB Output is correct
116 Correct 863 ms 5284 KB Output is correct
117 Correct 569 ms 5568 KB Output is correct
118 Correct 3032 ms 6536 KB Output is correct
119 Correct 1456 ms 6616 KB Output is correct
120 Correct 1173 ms 6700 KB Output is correct
121 Correct 3733 ms 7376 KB Output is correct
122 Correct 3095 ms 7384 KB Output is correct
123 Execution timed out 7028 ms 8136 KB Time limit exceeded
124 Halted 0 ms 0 KB -