Submission #519273

# Submission time Handle Problem Language Result Execution time Memory
519273 2022-01-26T07:03:11 Z Keshi Diversity (CEOI21_diversity) C++17
64 / 100
7000 ms 6580 KB
//In the name of God
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;

const ll maxn = 3e5 + 100;
const ll mod = 1e9 + 7;
const ll inf = 1e18;

#define fast_io ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io freopen("input.txt", "r+", stdin);freopen("output.txt", "w+", stdout);
#define pb push_back
#define Mp make_pair
#define F first
#define S second
#define Sz(x) ll((x).size())
#define all(x) (x).begin(), (x).end()

ll pw(ll a, ll b){
	ll c = 1;
	while(b){
		if(b & 1) c = c * a % mod;
		a = a * a % mod;
		b >>= 1;
	}
	return c;
}

int n, q, a[maxn], c[maxn], b[maxn];

int main(){
	fast_io;

	cin >> n >> q;
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	while(q--){
		int l, r;
		cin >> l >> r;
		l--;
		for(int i = l; i < r; i++){
			c[a[i]]++;
		}
		vector<int> vec;
		for(int i = l; i < r; i++){
			if(c[a[i]]){
				vec.pb(c[a[i]]);
				c[a[i]] = 0;
			}
		}
		sort(all(vec));
		l = 0, r = Sz(vec) - 1;
		ll s = 0;
		for(int i = 0; i < Sz(vec); i++){
			s += vec[i];
			if(i & 1){
				b[r--] = vec[i];
			}
			else{
				b[l++] = vec[i];
			}
		}
		ll x = 0, ans = 0;
		ll m = s;
		for(int i = 0; i < Sz(vec); i++){
			s -= b[i];
			ans += m * (m + 1) / 2 - x * (x + 1) / 2 - s * (s + 1) / 2;
			x += b[i];
		}
		cout << ans << "\n";
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 316 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 5 ms 844 KB Output is correct
5 Correct 10 ms 1508 KB Output is correct
6 Correct 17 ms 2112 KB Output is correct
7 Correct 15 ms 2008 KB Output is correct
8 Correct 16 ms 2124 KB Output is correct
9 Correct 16 ms 2100 KB Output is correct
10 Correct 16 ms 2024 KB Output is correct
11 Correct 17 ms 2244 KB Output is correct
12 Correct 16 ms 2148 KB Output is correct
13 Correct 16 ms 2120 KB Output is correct
14 Correct 15 ms 2124 KB Output is correct
15 Correct 24 ms 2064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 5 ms 844 KB Output is correct
5 Correct 10 ms 1508 KB Output is correct
6 Correct 17 ms 2112 KB Output is correct
7 Correct 15 ms 2008 KB Output is correct
8 Correct 16 ms 2124 KB Output is correct
9 Correct 16 ms 2100 KB Output is correct
10 Correct 16 ms 2024 KB Output is correct
11 Correct 17 ms 2244 KB Output is correct
12 Correct 16 ms 2148 KB Output is correct
13 Correct 16 ms 2120 KB Output is correct
14 Correct 15 ms 2124 KB Output is correct
15 Correct 24 ms 2064 KB Output is correct
16 Correct 1 ms 324 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 6 ms 976 KB Output is correct
20 Correct 12 ms 1612 KB Output is correct
21 Correct 17 ms 2252 KB Output is correct
22 Correct 17 ms 2252 KB Output is correct
23 Correct 17 ms 2252 KB Output is correct
24 Correct 21 ms 2140 KB Output is correct
25 Correct 19 ms 2252 KB Output is correct
26 Correct 24 ms 2200 KB Output is correct
27 Correct 17 ms 2252 KB Output is correct
28 Correct 17 ms 2124 KB Output is correct
29 Correct 20 ms 2208 KB Output is correct
30 Correct 17 ms 2240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 5 ms 844 KB Output is correct
5 Correct 10 ms 1508 KB Output is correct
6 Correct 17 ms 2112 KB Output is correct
7 Correct 15 ms 2008 KB Output is correct
8 Correct 16 ms 2124 KB Output is correct
9 Correct 16 ms 2100 KB Output is correct
10 Correct 16 ms 2024 KB Output is correct
11 Correct 17 ms 2244 KB Output is correct
12 Correct 16 ms 2148 KB Output is correct
13 Correct 16 ms 2120 KB Output is correct
14 Correct 15 ms 2124 KB Output is correct
15 Correct 24 ms 2064 KB Output is correct
16 Correct 1 ms 324 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 6 ms 976 KB Output is correct
20 Correct 12 ms 1612 KB Output is correct
21 Correct 17 ms 2252 KB Output is correct
22 Correct 17 ms 2252 KB Output is correct
23 Correct 17 ms 2252 KB Output is correct
24 Correct 21 ms 2140 KB Output is correct
25 Correct 19 ms 2252 KB Output is correct
26 Correct 24 ms 2200 KB Output is correct
27 Correct 17 ms 2252 KB Output is correct
28 Correct 17 ms 2124 KB Output is correct
29 Correct 20 ms 2208 KB Output is correct
30 Correct 17 ms 2240 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 2 ms 332 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 1 ms 332 KB Output is correct
37 Correct 4 ms 716 KB Output is correct
38 Correct 3 ms 712 KB Output is correct
39 Correct 10 ms 1104 KB Output is correct
40 Correct 14 ms 1868 KB Output is correct
41 Correct 18 ms 2604 KB Output is correct
42 Correct 19 ms 2588 KB Output is correct
43 Correct 20 ms 2628 KB Output is correct
44 Correct 18 ms 2616 KB Output is correct
45 Correct 21 ms 2580 KB Output is correct
46 Correct 24 ms 2612 KB Output is correct
47 Correct 20 ms 2604 KB Output is correct
48 Correct 19 ms 2588 KB Output is correct
49 Correct 20 ms 2600 KB Output is correct
50 Correct 18 ms 2588 KB Output is correct
51 Correct 19 ms 2656 KB Output is correct
52 Correct 20 ms 2536 KB Output is correct
53 Correct 22 ms 2608 KB Output is correct
54 Correct 25 ms 2632 KB Output is correct
55 Correct 22 ms 2596 KB Output is correct
56 Correct 23 ms 2596 KB Output is correct
57 Correct 26 ms 2628 KB Output is correct
58 Correct 20 ms 2608 KB Output is correct
59 Correct 19 ms 2540 KB Output is correct
60 Correct 24 ms 2596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 316 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 5 ms 844 KB Output is correct
15 Correct 10 ms 1508 KB Output is correct
16 Correct 17 ms 2112 KB Output is correct
17 Correct 15 ms 2008 KB Output is correct
18 Correct 16 ms 2124 KB Output is correct
19 Correct 16 ms 2100 KB Output is correct
20 Correct 16 ms 2024 KB Output is correct
21 Correct 17 ms 2244 KB Output is correct
22 Correct 16 ms 2148 KB Output is correct
23 Correct 16 ms 2120 KB Output is correct
24 Correct 15 ms 2124 KB Output is correct
25 Correct 24 ms 2064 KB Output is correct
26 Correct 1 ms 324 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 6 ms 976 KB Output is correct
30 Correct 12 ms 1612 KB Output is correct
31 Correct 17 ms 2252 KB Output is correct
32 Correct 17 ms 2252 KB Output is correct
33 Correct 17 ms 2252 KB Output is correct
34 Correct 21 ms 2140 KB Output is correct
35 Correct 19 ms 2252 KB Output is correct
36 Correct 24 ms 2200 KB Output is correct
37 Correct 17 ms 2252 KB Output is correct
38 Correct 17 ms 2124 KB Output is correct
39 Correct 20 ms 2208 KB Output is correct
40 Correct 17 ms 2240 KB Output is correct
41 Correct 1 ms 332 KB Output is correct
42 Correct 1 ms 332 KB Output is correct
43 Correct 1 ms 332 KB Output is correct
44 Correct 2 ms 332 KB Output is correct
45 Correct 1 ms 332 KB Output is correct
46 Correct 1 ms 332 KB Output is correct
47 Correct 4 ms 716 KB Output is correct
48 Correct 3 ms 712 KB Output is correct
49 Correct 10 ms 1104 KB Output is correct
50 Correct 14 ms 1868 KB Output is correct
51 Correct 18 ms 2604 KB Output is correct
52 Correct 19 ms 2588 KB Output is correct
53 Correct 20 ms 2628 KB Output is correct
54 Correct 18 ms 2616 KB Output is correct
55 Correct 21 ms 2580 KB Output is correct
56 Correct 24 ms 2612 KB Output is correct
57 Correct 20 ms 2604 KB Output is correct
58 Correct 19 ms 2588 KB Output is correct
59 Correct 20 ms 2600 KB Output is correct
60 Correct 18 ms 2588 KB Output is correct
61 Correct 19 ms 2656 KB Output is correct
62 Correct 20 ms 2536 KB Output is correct
63 Correct 22 ms 2608 KB Output is correct
64 Correct 25 ms 2632 KB Output is correct
65 Correct 22 ms 2596 KB Output is correct
66 Correct 23 ms 2596 KB Output is correct
67 Correct 26 ms 2628 KB Output is correct
68 Correct 20 ms 2608 KB Output is correct
69 Correct 19 ms 2540 KB Output is correct
70 Correct 24 ms 2596 KB Output is correct
71 Correct 6 ms 708 KB Output is correct
72 Correct 4 ms 716 KB Output is correct
73 Correct 4 ms 748 KB Output is correct
74 Correct 5 ms 712 KB Output is correct
75 Correct 6 ms 772 KB Output is correct
76 Correct 10 ms 1228 KB Output is correct
77 Correct 12 ms 1216 KB Output is correct
78 Correct 10 ms 1232 KB Output is correct
79 Correct 9 ms 1224 KB Output is correct
80 Correct 8 ms 1220 KB Output is correct
81 Correct 15 ms 2208 KB Output is correct
82 Correct 17 ms 2128 KB Output is correct
83 Correct 20 ms 2120 KB Output is correct
84 Correct 14 ms 2140 KB Output is correct
85 Correct 14 ms 2204 KB Output is correct
86 Correct 18 ms 2408 KB Output is correct
87 Correct 16 ms 2440 KB Output is correct
88 Correct 17 ms 2492 KB Output is correct
89 Correct 24 ms 2500 KB Output is correct
90 Correct 16 ms 2500 KB Output is correct
91 Correct 26 ms 4548 KB Output is correct
92 Correct 27 ms 4456 KB Output is correct
93 Correct 29 ms 4492 KB Output is correct
94 Correct 27 ms 4536 KB Output is correct
95 Correct 28 ms 4488 KB Output is correct
96 Correct 39 ms 5752 KB Output is correct
97 Correct 34 ms 5852 KB Output is correct
98 Correct 34 ms 5848 KB Output is correct
99 Correct 33 ms 5824 KB Output is correct
100 Correct 36 ms 5796 KB Output is correct
101 Correct 39 ms 5792 KB Output is correct
102 Correct 34 ms 5824 KB Output is correct
103 Correct 35 ms 5824 KB Output is correct
104 Correct 33 ms 5796 KB Output is correct
105 Correct 38 ms 5760 KB Output is correct
106 Correct 31 ms 6464 KB Output is correct
107 Correct 33 ms 6580 KB Output is correct
108 Correct 35 ms 6464 KB Output is correct
109 Correct 33 ms 6440 KB Output is correct
110 Correct 32 ms 6448 KB Output is correct
111 Correct 32 ms 6480 KB Output is correct
112 Correct 35 ms 6464 KB Output is correct
113 Correct 34 ms 6356 KB Output is correct
114 Correct 35 ms 6420 KB Output is correct
115 Correct 33 ms 6364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 316 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 5 ms 844 KB Output is correct
15 Correct 10 ms 1508 KB Output is correct
16 Correct 17 ms 2112 KB Output is correct
17 Correct 15 ms 2008 KB Output is correct
18 Correct 16 ms 2124 KB Output is correct
19 Correct 16 ms 2100 KB Output is correct
20 Correct 16 ms 2024 KB Output is correct
21 Correct 17 ms 2244 KB Output is correct
22 Correct 16 ms 2148 KB Output is correct
23 Correct 16 ms 2120 KB Output is correct
24 Correct 15 ms 2124 KB Output is correct
25 Correct 24 ms 2064 KB Output is correct
26 Correct 1 ms 324 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 6 ms 976 KB Output is correct
30 Correct 12 ms 1612 KB Output is correct
31 Correct 17 ms 2252 KB Output is correct
32 Correct 17 ms 2252 KB Output is correct
33 Correct 17 ms 2252 KB Output is correct
34 Correct 21 ms 2140 KB Output is correct
35 Correct 19 ms 2252 KB Output is correct
36 Correct 24 ms 2200 KB Output is correct
37 Correct 17 ms 2252 KB Output is correct
38 Correct 17 ms 2124 KB Output is correct
39 Correct 20 ms 2208 KB Output is correct
40 Correct 17 ms 2240 KB Output is correct
41 Correct 1 ms 332 KB Output is correct
42 Correct 1 ms 332 KB Output is correct
43 Correct 1 ms 332 KB Output is correct
44 Correct 2 ms 332 KB Output is correct
45 Correct 1 ms 332 KB Output is correct
46 Correct 1 ms 332 KB Output is correct
47 Correct 4 ms 716 KB Output is correct
48 Correct 3 ms 712 KB Output is correct
49 Correct 10 ms 1104 KB Output is correct
50 Correct 14 ms 1868 KB Output is correct
51 Correct 18 ms 2604 KB Output is correct
52 Correct 19 ms 2588 KB Output is correct
53 Correct 20 ms 2628 KB Output is correct
54 Correct 18 ms 2616 KB Output is correct
55 Correct 21 ms 2580 KB Output is correct
56 Correct 24 ms 2612 KB Output is correct
57 Correct 20 ms 2604 KB Output is correct
58 Correct 19 ms 2588 KB Output is correct
59 Correct 20 ms 2600 KB Output is correct
60 Correct 18 ms 2588 KB Output is correct
61 Correct 19 ms 2656 KB Output is correct
62 Correct 20 ms 2536 KB Output is correct
63 Correct 22 ms 2608 KB Output is correct
64 Correct 25 ms 2632 KB Output is correct
65 Correct 22 ms 2596 KB Output is correct
66 Correct 23 ms 2596 KB Output is correct
67 Correct 26 ms 2628 KB Output is correct
68 Correct 20 ms 2608 KB Output is correct
69 Correct 19 ms 2540 KB Output is correct
70 Correct 24 ms 2596 KB Output is correct
71 Correct 6 ms 708 KB Output is correct
72 Correct 4 ms 716 KB Output is correct
73 Correct 4 ms 748 KB Output is correct
74 Correct 5 ms 712 KB Output is correct
75 Correct 6 ms 772 KB Output is correct
76 Correct 10 ms 1228 KB Output is correct
77 Correct 12 ms 1216 KB Output is correct
78 Correct 10 ms 1232 KB Output is correct
79 Correct 9 ms 1224 KB Output is correct
80 Correct 8 ms 1220 KB Output is correct
81 Correct 15 ms 2208 KB Output is correct
82 Correct 17 ms 2128 KB Output is correct
83 Correct 20 ms 2120 KB Output is correct
84 Correct 14 ms 2140 KB Output is correct
85 Correct 14 ms 2204 KB Output is correct
86 Correct 18 ms 2408 KB Output is correct
87 Correct 16 ms 2440 KB Output is correct
88 Correct 17 ms 2492 KB Output is correct
89 Correct 24 ms 2500 KB Output is correct
90 Correct 16 ms 2500 KB Output is correct
91 Correct 26 ms 4548 KB Output is correct
92 Correct 27 ms 4456 KB Output is correct
93 Correct 29 ms 4492 KB Output is correct
94 Correct 27 ms 4536 KB Output is correct
95 Correct 28 ms 4488 KB Output is correct
96 Correct 39 ms 5752 KB Output is correct
97 Correct 34 ms 5852 KB Output is correct
98 Correct 34 ms 5848 KB Output is correct
99 Correct 33 ms 5824 KB Output is correct
100 Correct 36 ms 5796 KB Output is correct
101 Correct 39 ms 5792 KB Output is correct
102 Correct 34 ms 5824 KB Output is correct
103 Correct 35 ms 5824 KB Output is correct
104 Correct 33 ms 5796 KB Output is correct
105 Correct 38 ms 5760 KB Output is correct
106 Correct 31 ms 6464 KB Output is correct
107 Correct 33 ms 6580 KB Output is correct
108 Correct 35 ms 6464 KB Output is correct
109 Correct 33 ms 6440 KB Output is correct
110 Correct 32 ms 6448 KB Output is correct
111 Correct 32 ms 6480 KB Output is correct
112 Correct 35 ms 6464 KB Output is correct
113 Correct 34 ms 6356 KB Output is correct
114 Correct 35 ms 6420 KB Output is correct
115 Correct 33 ms 6364 KB Output is correct
116 Correct 647 ms 1220 KB Output is correct
117 Correct 792 ms 1320 KB Output is correct
118 Correct 2933 ms 1988 KB Output is correct
119 Correct 3795 ms 1940 KB Output is correct
120 Correct 4652 ms 1976 KB Output is correct
121 Execution timed out 7097 ms 2324 KB Time limit exceeded
122 Halted 0 ms 0 KB -