답안 #476419

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
476419 2021-09-26T14:19:55 Z neki Diversity (CEOI21_diversity) C++14
64 / 100
7000 ms 18540 KB
#include <bits/stdc++.h>
#define ll long long
#define loop(i, a, b) for(ll i=a;i<b;++i)
#define pool(i, a, b) for(ll i=a-1;i>=b;--i)
#define fore(i, a) for(auto&& i:a)
#define fi first
#define se second
#define ps(a) push_back(a)
#define pb(a) pop_back(a)
#define eb(...) emplace_back(__VA_ARGS__)
#define sc scanf
#define vc vector
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(), a.end()
#define llmax LLONG_MAX/2
#define llmin -LLONG_MAX/2
using namespace std;
#define mn 500100
#define par pair<ll, ll>
#define ld long double
#define mod 1000000007

ll cnt[300100];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n, q;cin >> n >> q;
    vc<ll> a(n);loop(i, 0, n) cin >> a[i];
    
    vc<array<ll, 3>> que(q);
    loop(i, 0, q){ cin >> que[i][0] >> que[i][1];--que[i][0], --que[i][1];}
    loop(i, 0, q) que[i][2]=i;
    
    const ll m=550;
    sort(all(que), [&](array<ll, 3> a, array<ll, 3> b){
        if(a[0]/m==b[0]/m) return a[1]<b[1];
        return a[0]<b[0];
    });
    
    set<ll> act;
    function<void (ll)> add=[&](ll i){
        if(cnt[a[i]]==0)act.insert(a[i]);
        ++cnt[a[i]];
    };
    function<void (ll)> rem=[&](ll i){
        --cnt[a[i]];
        if(cnt[a[i]]==0) act.erase(a[i]);
    };
    function<ll ()> getans=[&](){
        ll sum=0;
        vc<ll> cs; fore(v, act) sum+=cnt[v], cs.ps(cnt[v]);
        sort(all(cs));
        
        ll ret=0;
        vc<ll> pre(2, 0);
        loop(i, 0, cs.size()){
            ret+=pre[i%2] * (sum-cs[i]-pre[i%2]);
            pre[i%2]+=cs[i];
            
            ret+=cs[i] * (sum-cs[i]);
            ret+=(cs[i] * cs[i] + cs[i])/2;
        }
        return ret;
    };
    
    vc<ll> ans(q);
    ll l=0, r=-1;
    loop(i, 0, q){
        ll ql=que[i][0], qr=que[i][1];
        
        while(r<qr) add(++r);
        while(r>qr) rem(r--);
        
        while(l<ql) rem(l++);
        while(l>ql) add(--l);
        
        ans[que[i][2]]=getans();
    }
    
    loop(i, 0, q) cout << ans[i]<<endl;
}

Compilation message

diversity.cpp: In lambda function:
diversity.cpp:3:35: 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]
    3 | #define loop(i, a, b) for(ll i=a;i<b;++i)
......
   57 |         loop(i, 0, cs.size()){
      |              ~~~~~~~~~~~~~~~       
diversity.cpp:57:9: note: in expansion of macro 'loop'
   57 |         loop(i, 0, cs.size()){
      |         ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 6 ms 1116 KB Output is correct
5 Correct 13 ms 1888 KB Output is correct
6 Correct 29 ms 2672 KB Output is correct
7 Correct 18 ms 2680 KB Output is correct
8 Correct 19 ms 2684 KB Output is correct
9 Correct 19 ms 2684 KB Output is correct
10 Correct 22 ms 2680 KB Output is correct
11 Correct 22 ms 2636 KB Output is correct
12 Correct 23 ms 2680 KB Output is correct
13 Correct 21 ms 2684 KB Output is correct
14 Correct 21 ms 2680 KB Output is correct
15 Correct 21 ms 2680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 6 ms 1116 KB Output is correct
5 Correct 13 ms 1888 KB Output is correct
6 Correct 29 ms 2672 KB Output is correct
7 Correct 18 ms 2680 KB Output is correct
8 Correct 19 ms 2684 KB Output is correct
9 Correct 19 ms 2684 KB Output is correct
10 Correct 22 ms 2680 KB Output is correct
11 Correct 22 ms 2636 KB Output is correct
12 Correct 23 ms 2680 KB Output is correct
13 Correct 21 ms 2684 KB Output is correct
14 Correct 21 ms 2680 KB Output is correct
15 Correct 21 ms 2680 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 7 ms 1100 KB Output is correct
20 Correct 15 ms 1868 KB Output is correct
21 Correct 23 ms 2688 KB Output is correct
22 Correct 28 ms 2636 KB Output is correct
23 Correct 22 ms 2684 KB Output is correct
24 Correct 23 ms 2764 KB Output is correct
25 Correct 25 ms 2656 KB Output is correct
26 Correct 22 ms 2680 KB Output is correct
27 Correct 24 ms 2676 KB Output is correct
28 Correct 24 ms 2680 KB Output is correct
29 Correct 25 ms 2660 KB Output is correct
30 Correct 21 ms 2636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 6 ms 1116 KB Output is correct
5 Correct 13 ms 1888 KB Output is correct
6 Correct 29 ms 2672 KB Output is correct
7 Correct 18 ms 2680 KB Output is correct
8 Correct 19 ms 2684 KB Output is correct
9 Correct 19 ms 2684 KB Output is correct
10 Correct 22 ms 2680 KB Output is correct
11 Correct 22 ms 2636 KB Output is correct
12 Correct 23 ms 2680 KB Output is correct
13 Correct 21 ms 2684 KB Output is correct
14 Correct 21 ms 2680 KB Output is correct
15 Correct 21 ms 2680 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 7 ms 1100 KB Output is correct
20 Correct 15 ms 1868 KB Output is correct
21 Correct 23 ms 2688 KB Output is correct
22 Correct 28 ms 2636 KB Output is correct
23 Correct 22 ms 2684 KB Output is correct
24 Correct 23 ms 2764 KB Output is correct
25 Correct 25 ms 2656 KB Output is correct
26 Correct 22 ms 2680 KB Output is correct
27 Correct 24 ms 2676 KB Output is correct
28 Correct 24 ms 2680 KB Output is correct
29 Correct 25 ms 2660 KB Output is correct
30 Correct 21 ms 2636 KB Output is correct
31 Correct 0 ms 204 KB Output is correct
32 Correct 0 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 1 ms 460 KB Output is correct
37 Correct 7 ms 720 KB Output is correct
38 Correct 4 ms 716 KB Output is correct
39 Correct 9 ms 1116 KB Output is correct
40 Correct 20 ms 1892 KB Output is correct
41 Correct 23 ms 2680 KB Output is correct
42 Correct 25 ms 2720 KB Output is correct
43 Correct 25 ms 2716 KB Output is correct
44 Correct 28 ms 2636 KB Output is correct
45 Correct 23 ms 2680 KB Output is correct
46 Correct 28 ms 2676 KB Output is correct
47 Correct 24 ms 2636 KB Output is correct
48 Correct 25 ms 2688 KB Output is correct
49 Correct 30 ms 2688 KB Output is correct
50 Correct 25 ms 2688 KB Output is correct
51 Correct 25 ms 2636 KB Output is correct
52 Correct 23 ms 2684 KB Output is correct
53 Correct 34 ms 2668 KB Output is correct
54 Correct 23 ms 2676 KB Output is correct
55 Correct 29 ms 2680 KB Output is correct
56 Correct 31 ms 2676 KB Output is correct
57 Correct 22 ms 2684 KB Output is correct
58 Correct 23 ms 2680 KB Output is correct
59 Correct 22 ms 2676 KB Output is correct
60 Correct 27 ms 2636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 6 ms 1116 KB Output is correct
15 Correct 13 ms 1888 KB Output is correct
16 Correct 29 ms 2672 KB Output is correct
17 Correct 18 ms 2680 KB Output is correct
18 Correct 19 ms 2684 KB Output is correct
19 Correct 19 ms 2684 KB Output is correct
20 Correct 22 ms 2680 KB Output is correct
21 Correct 22 ms 2636 KB Output is correct
22 Correct 23 ms 2680 KB Output is correct
23 Correct 21 ms 2684 KB Output is correct
24 Correct 21 ms 2680 KB Output is correct
25 Correct 21 ms 2680 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 7 ms 1100 KB Output is correct
30 Correct 15 ms 1868 KB Output is correct
31 Correct 23 ms 2688 KB Output is correct
32 Correct 28 ms 2636 KB Output is correct
33 Correct 22 ms 2684 KB Output is correct
34 Correct 23 ms 2764 KB Output is correct
35 Correct 25 ms 2656 KB Output is correct
36 Correct 22 ms 2680 KB Output is correct
37 Correct 24 ms 2676 KB Output is correct
38 Correct 24 ms 2680 KB Output is correct
39 Correct 25 ms 2660 KB Output is correct
40 Correct 21 ms 2636 KB Output is correct
41 Correct 0 ms 204 KB Output is correct
42 Correct 0 ms 332 KB Output is correct
43 Correct 1 ms 332 KB Output is correct
44 Correct 1 ms 332 KB Output is correct
45 Correct 1 ms 332 KB Output is correct
46 Correct 1 ms 460 KB Output is correct
47 Correct 7 ms 720 KB Output is correct
48 Correct 4 ms 716 KB Output is correct
49 Correct 9 ms 1116 KB Output is correct
50 Correct 20 ms 1892 KB Output is correct
51 Correct 23 ms 2680 KB Output is correct
52 Correct 25 ms 2720 KB Output is correct
53 Correct 25 ms 2716 KB Output is correct
54 Correct 28 ms 2636 KB Output is correct
55 Correct 23 ms 2680 KB Output is correct
56 Correct 28 ms 2676 KB Output is correct
57 Correct 24 ms 2636 KB Output is correct
58 Correct 25 ms 2688 KB Output is correct
59 Correct 30 ms 2688 KB Output is correct
60 Correct 25 ms 2688 KB Output is correct
61 Correct 25 ms 2636 KB Output is correct
62 Correct 23 ms 2684 KB Output is correct
63 Correct 34 ms 2668 KB Output is correct
64 Correct 23 ms 2676 KB Output is correct
65 Correct 29 ms 2680 KB Output is correct
66 Correct 31 ms 2676 KB Output is correct
67 Correct 22 ms 2684 KB Output is correct
68 Correct 23 ms 2680 KB Output is correct
69 Correct 22 ms 2676 KB Output is correct
70 Correct 27 ms 2636 KB Output is correct
71 Correct 6 ms 844 KB Output is correct
72 Correct 6 ms 852 KB Output is correct
73 Correct 5 ms 844 KB Output is correct
74 Correct 5 ms 844 KB Output is correct
75 Correct 9 ms 844 KB Output is correct
76 Correct 10 ms 1484 KB Output is correct
77 Correct 10 ms 1368 KB Output is correct
78 Correct 11 ms 1376 KB Output is correct
79 Correct 12 ms 1400 KB Output is correct
80 Correct 10 ms 1372 KB Output is correct
81 Correct 22 ms 2540 KB Output is correct
82 Correct 24 ms 2640 KB Output is correct
83 Correct 23 ms 2528 KB Output is correct
84 Correct 21 ms 2556 KB Output is correct
85 Correct 20 ms 2604 KB Output is correct
86 Correct 26 ms 3300 KB Output is correct
87 Correct 28 ms 3280 KB Output is correct
88 Correct 25 ms 3360 KB Output is correct
89 Correct 28 ms 3352 KB Output is correct
90 Correct 29 ms 3296 KB Output is correct
91 Correct 83 ms 9228 KB Output is correct
92 Correct 94 ms 9188 KB Output is correct
93 Correct 88 ms 9192 KB Output is correct
94 Correct 75 ms 9184 KB Output is correct
95 Correct 82 ms 9192 KB Output is correct
96 Correct 175 ms 15804 KB Output is correct
97 Correct 193 ms 15776 KB Output is correct
98 Correct 186 ms 15804 KB Output is correct
99 Correct 177 ms 15720 KB Output is correct
100 Correct 150 ms 15720 KB Output is correct
101 Correct 177 ms 15692 KB Output is correct
102 Correct 168 ms 15700 KB Output is correct
103 Correct 148 ms 15756 KB Output is correct
104 Correct 181 ms 15676 KB Output is correct
105 Correct 189 ms 15788 KB Output is correct
106 Correct 229 ms 18536 KB Output is correct
107 Correct 235 ms 18524 KB Output is correct
108 Correct 230 ms 18464 KB Output is correct
109 Correct 238 ms 18540 KB Output is correct
110 Correct 203 ms 18520 KB Output is correct
111 Correct 208 ms 18496 KB Output is correct
112 Correct 218 ms 18436 KB Output is correct
113 Correct 230 ms 18428 KB Output is correct
114 Correct 221 ms 18536 KB Output is correct
115 Correct 229 ms 18540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 6 ms 1116 KB Output is correct
15 Correct 13 ms 1888 KB Output is correct
16 Correct 29 ms 2672 KB Output is correct
17 Correct 18 ms 2680 KB Output is correct
18 Correct 19 ms 2684 KB Output is correct
19 Correct 19 ms 2684 KB Output is correct
20 Correct 22 ms 2680 KB Output is correct
21 Correct 22 ms 2636 KB Output is correct
22 Correct 23 ms 2680 KB Output is correct
23 Correct 21 ms 2684 KB Output is correct
24 Correct 21 ms 2680 KB Output is correct
25 Correct 21 ms 2680 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 7 ms 1100 KB Output is correct
30 Correct 15 ms 1868 KB Output is correct
31 Correct 23 ms 2688 KB Output is correct
32 Correct 28 ms 2636 KB Output is correct
33 Correct 22 ms 2684 KB Output is correct
34 Correct 23 ms 2764 KB Output is correct
35 Correct 25 ms 2656 KB Output is correct
36 Correct 22 ms 2680 KB Output is correct
37 Correct 24 ms 2676 KB Output is correct
38 Correct 24 ms 2680 KB Output is correct
39 Correct 25 ms 2660 KB Output is correct
40 Correct 21 ms 2636 KB Output is correct
41 Correct 0 ms 204 KB Output is correct
42 Correct 0 ms 332 KB Output is correct
43 Correct 1 ms 332 KB Output is correct
44 Correct 1 ms 332 KB Output is correct
45 Correct 1 ms 332 KB Output is correct
46 Correct 1 ms 460 KB Output is correct
47 Correct 7 ms 720 KB Output is correct
48 Correct 4 ms 716 KB Output is correct
49 Correct 9 ms 1116 KB Output is correct
50 Correct 20 ms 1892 KB Output is correct
51 Correct 23 ms 2680 KB Output is correct
52 Correct 25 ms 2720 KB Output is correct
53 Correct 25 ms 2716 KB Output is correct
54 Correct 28 ms 2636 KB Output is correct
55 Correct 23 ms 2680 KB Output is correct
56 Correct 28 ms 2676 KB Output is correct
57 Correct 24 ms 2636 KB Output is correct
58 Correct 25 ms 2688 KB Output is correct
59 Correct 30 ms 2688 KB Output is correct
60 Correct 25 ms 2688 KB Output is correct
61 Correct 25 ms 2636 KB Output is correct
62 Correct 23 ms 2684 KB Output is correct
63 Correct 34 ms 2668 KB Output is correct
64 Correct 23 ms 2676 KB Output is correct
65 Correct 29 ms 2680 KB Output is correct
66 Correct 31 ms 2676 KB Output is correct
67 Correct 22 ms 2684 KB Output is correct
68 Correct 23 ms 2680 KB Output is correct
69 Correct 22 ms 2676 KB Output is correct
70 Correct 27 ms 2636 KB Output is correct
71 Correct 6 ms 844 KB Output is correct
72 Correct 6 ms 852 KB Output is correct
73 Correct 5 ms 844 KB Output is correct
74 Correct 5 ms 844 KB Output is correct
75 Correct 9 ms 844 KB Output is correct
76 Correct 10 ms 1484 KB Output is correct
77 Correct 10 ms 1368 KB Output is correct
78 Correct 11 ms 1376 KB Output is correct
79 Correct 12 ms 1400 KB Output is correct
80 Correct 10 ms 1372 KB Output is correct
81 Correct 22 ms 2540 KB Output is correct
82 Correct 24 ms 2640 KB Output is correct
83 Correct 23 ms 2528 KB Output is correct
84 Correct 21 ms 2556 KB Output is correct
85 Correct 20 ms 2604 KB Output is correct
86 Correct 26 ms 3300 KB Output is correct
87 Correct 28 ms 3280 KB Output is correct
88 Correct 25 ms 3360 KB Output is correct
89 Correct 28 ms 3352 KB Output is correct
90 Correct 29 ms 3296 KB Output is correct
91 Correct 83 ms 9228 KB Output is correct
92 Correct 94 ms 9188 KB Output is correct
93 Correct 88 ms 9192 KB Output is correct
94 Correct 75 ms 9184 KB Output is correct
95 Correct 82 ms 9192 KB Output is correct
96 Correct 175 ms 15804 KB Output is correct
97 Correct 193 ms 15776 KB Output is correct
98 Correct 186 ms 15804 KB Output is correct
99 Correct 177 ms 15720 KB Output is correct
100 Correct 150 ms 15720 KB Output is correct
101 Correct 177 ms 15692 KB Output is correct
102 Correct 168 ms 15700 KB Output is correct
103 Correct 148 ms 15756 KB Output is correct
104 Correct 181 ms 15676 KB Output is correct
105 Correct 189 ms 15788 KB Output is correct
106 Correct 229 ms 18536 KB Output is correct
107 Correct 235 ms 18524 KB Output is correct
108 Correct 230 ms 18464 KB Output is correct
109 Correct 238 ms 18540 KB Output is correct
110 Correct 203 ms 18520 KB Output is correct
111 Correct 208 ms 18496 KB Output is correct
112 Correct 218 ms 18436 KB Output is correct
113 Correct 230 ms 18428 KB Output is correct
114 Correct 221 ms 18536 KB Output is correct
115 Correct 229 ms 18540 KB Output is correct
116 Correct 233 ms 2352 KB Output is correct
117 Correct 337 ms 2344 KB Output is correct
118 Correct 358 ms 2804 KB Output is correct
119 Correct 1398 ms 2816 KB Output is correct
120 Correct 2494 ms 2856 KB Output is correct
121 Correct 2911 ms 3252 KB Output is correct
122 Correct 4896 ms 3316 KB Output is correct
123 Correct 3536 ms 4156 KB Output is correct
124 Execution timed out 7073 ms 3912 KB Time limit exceeded
125 Halted 0 ms 0 KB -