Submission #920282

# Submission time Handle Problem Language Result Execution time Memory
920282 2024-02-02T11:50:42 Z vjudge1 Diversity (CEOI21_diversity) C++17
64 / 100
7000 ms 20348 KB
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#pragma GCC optimize("Ofast")
 
using namespace std;
template<typename T1, typename T2> inline void chkmin(T1 &a, T2 b) {if (a > b) a = b;}
template<typename T1, typename T2> inline void chkmax(T1 &a, T2 b) {if (a < b) a = b;}
#define files(FILENAME) read(FILENAME); write(FILENAME)
#define read(FILENAME) freopen((FILENAME + ".in").c_str(), "r", stdin)
#define write(FILENAME) freopen((FILENAME + ".out").c_str(), "w", stdout)
#define all(c) (c).begin(), (c).end()
#define sz(c) (int)(c).size()
#define left left228
#define right right228
#define y1 y1228
#define mp make_pair
#define pb push_back
#define y2 y2228
#define rank rank228
using ll = long long;
using ld = long double; 
const string FILENAME = "input";
const int MAXN = 300228;

int n, q;
int cnt[MAXN], f[MAXN];


ll func(ll n) {
	return n * (n + 1) / 2;
}

ll calc(vector<int> a) {
	int n = 0;
	for (auto i: a) {
		n += i;
	}
	ll res = 0;
	ll x = 0;
	for (auto i: a) {
		res += func(x) + func(n - x - i);
		x += i; 
	}
	res = func(n) * sz(a) - res;
	return res;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	//read(FILENAME);
	cin >> n >> q;
	vector<int> a(n + 1), v;
	int mx = 0;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		v.pb(a[i]);
	}
	sort(all(v));
	map<int, int> mp;
	int id = 0;
	for (int i = 0; i < sz(v); i++) {
		if (mp[v[i]] == 0) {
			mp[v[i]] = ++id;
		}
	}
	for (int i = 1; i <= n; i++) {
		a[i] = mp[a[i]];
		chkmax(mx, a[i]);
	}
	for (int i = 1; i <= q; i++) {
		int l, r;
		cin >> l >> r;
		for (int j = l; j <= r; j++) {
			f[a[j]]++;
		}
		vector<int> v;
		for (int i = 1; i <= mx; i++) {
			if (f[i] != 0) {
				v.pb(f[i]);
			}
		}
		sort(all(v));
		vector<int> optim;
		for (int i = 0; i < sz(v); i += 2) {
			optim.pb(v[i]);
		}
		vector<int> aux;
		for (int i = 1; i < sz(v); i += 2) {
			aux.pb(v[i]);
		}
		reverse(all(aux));
		for (auto i: aux) {
			optim.pb(i);
		}
		cout << calc(optim) << '\n';
		for (int j = l; j <= r; j++) {
			f[a[j]] = 0;
		}
	}
	return 0;				
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 600 KB Output is correct
4 Correct 9 ms 1500 KB Output is correct
5 Correct 17 ms 2264 KB Output is correct
6 Correct 27 ms 3796 KB Output is correct
7 Correct 24 ms 4052 KB Output is correct
8 Correct 26 ms 3796 KB Output is correct
9 Correct 25 ms 3808 KB Output is correct
10 Correct 26 ms 3796 KB Output is correct
11 Correct 30 ms 3796 KB Output is correct
12 Correct 27 ms 3800 KB Output is correct
13 Correct 27 ms 3796 KB Output is correct
14 Correct 27 ms 3796 KB Output is correct
15 Correct 26 ms 3956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 600 KB Output is correct
4 Correct 9 ms 1500 KB Output is correct
5 Correct 17 ms 2264 KB Output is correct
6 Correct 27 ms 3796 KB Output is correct
7 Correct 24 ms 4052 KB Output is correct
8 Correct 26 ms 3796 KB Output is correct
9 Correct 25 ms 3808 KB Output is correct
10 Correct 26 ms 3796 KB Output is correct
11 Correct 30 ms 3796 KB Output is correct
12 Correct 27 ms 3800 KB Output is correct
13 Correct 27 ms 3796 KB Output is correct
14 Correct 27 ms 3796 KB Output is correct
15 Correct 26 ms 3956 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 600 KB Output is correct
19 Correct 10 ms 1500 KB Output is correct
20 Correct 19 ms 2268 KB Output is correct
21 Correct 29 ms 3608 KB Output is correct
22 Correct 30 ms 3796 KB Output is correct
23 Correct 30 ms 3796 KB Output is correct
24 Correct 30 ms 3796 KB Output is correct
25 Correct 29 ms 3796 KB Output is correct
26 Correct 31 ms 3796 KB Output is correct
27 Correct 36 ms 3796 KB Output is correct
28 Correct 29 ms 3796 KB Output is correct
29 Correct 30 ms 3796 KB Output is correct
30 Correct 30 ms 3796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 600 KB Output is correct
4 Correct 9 ms 1500 KB Output is correct
5 Correct 17 ms 2264 KB Output is correct
6 Correct 27 ms 3796 KB Output is correct
7 Correct 24 ms 4052 KB Output is correct
8 Correct 26 ms 3796 KB Output is correct
9 Correct 25 ms 3808 KB Output is correct
10 Correct 26 ms 3796 KB Output is correct
11 Correct 30 ms 3796 KB Output is correct
12 Correct 27 ms 3800 KB Output is correct
13 Correct 27 ms 3796 KB Output is correct
14 Correct 27 ms 3796 KB Output is correct
15 Correct 26 ms 3956 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 600 KB Output is correct
19 Correct 10 ms 1500 KB Output is correct
20 Correct 19 ms 2268 KB Output is correct
21 Correct 29 ms 3608 KB Output is correct
22 Correct 30 ms 3796 KB Output is correct
23 Correct 30 ms 3796 KB Output is correct
24 Correct 30 ms 3796 KB Output is correct
25 Correct 29 ms 3796 KB Output is correct
26 Correct 31 ms 3796 KB Output is correct
27 Correct 36 ms 3796 KB Output is correct
28 Correct 29 ms 3796 KB Output is correct
29 Correct 30 ms 3796 KB Output is correct
30 Correct 30 ms 3796 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 0 ms 344 KB Output is correct
33 Correct 0 ms 344 KB Output is correct
34 Correct 1 ms 600 KB Output is correct
35 Correct 2 ms 600 KB Output is correct
36 Correct 3 ms 600 KB Output is correct
37 Correct 8 ms 988 KB Output is correct
38 Correct 9 ms 988 KB Output is correct
39 Correct 16 ms 1500 KB Output is correct
40 Correct 31 ms 2264 KB Output is correct
41 Correct 46 ms 3796 KB Output is correct
42 Correct 47 ms 3796 KB Output is correct
43 Correct 47 ms 3796 KB Output is correct
44 Correct 47 ms 3796 KB Output is correct
45 Correct 47 ms 3796 KB Output is correct
46 Correct 48 ms 3796 KB Output is correct
47 Correct 47 ms 3796 KB Output is correct
48 Correct 47 ms 3776 KB Output is correct
49 Correct 48 ms 3796 KB Output is correct
50 Correct 49 ms 3796 KB Output is correct
51 Correct 52 ms 3796 KB Output is correct
52 Correct 47 ms 3796 KB Output is correct
53 Correct 48 ms 3996 KB Output is correct
54 Correct 48 ms 3796 KB Output is correct
55 Correct 50 ms 3796 KB Output is correct
56 Correct 47 ms 3804 KB Output is correct
57 Correct 51 ms 3688 KB Output is correct
58 Correct 49 ms 3796 KB Output is correct
59 Correct 48 ms 3796 KB Output is correct
60 Correct 50 ms 3796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 600 KB Output is correct
14 Correct 9 ms 1500 KB Output is correct
15 Correct 17 ms 2264 KB Output is correct
16 Correct 27 ms 3796 KB Output is correct
17 Correct 24 ms 4052 KB Output is correct
18 Correct 26 ms 3796 KB Output is correct
19 Correct 25 ms 3808 KB Output is correct
20 Correct 26 ms 3796 KB Output is correct
21 Correct 30 ms 3796 KB Output is correct
22 Correct 27 ms 3800 KB Output is correct
23 Correct 27 ms 3796 KB Output is correct
24 Correct 27 ms 3796 KB Output is correct
25 Correct 26 ms 3956 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 1 ms 600 KB Output is correct
29 Correct 10 ms 1500 KB Output is correct
30 Correct 19 ms 2268 KB Output is correct
31 Correct 29 ms 3608 KB Output is correct
32 Correct 30 ms 3796 KB Output is correct
33 Correct 30 ms 3796 KB Output is correct
34 Correct 30 ms 3796 KB Output is correct
35 Correct 29 ms 3796 KB Output is correct
36 Correct 31 ms 3796 KB Output is correct
37 Correct 36 ms 3796 KB Output is correct
38 Correct 29 ms 3796 KB Output is correct
39 Correct 30 ms 3796 KB Output is correct
40 Correct 30 ms 3796 KB Output is correct
41 Correct 1 ms 344 KB Output is correct
42 Correct 0 ms 344 KB Output is correct
43 Correct 0 ms 344 KB Output is correct
44 Correct 1 ms 600 KB Output is correct
45 Correct 2 ms 600 KB Output is correct
46 Correct 3 ms 600 KB Output is correct
47 Correct 8 ms 988 KB Output is correct
48 Correct 9 ms 988 KB Output is correct
49 Correct 16 ms 1500 KB Output is correct
50 Correct 31 ms 2264 KB Output is correct
51 Correct 46 ms 3796 KB Output is correct
52 Correct 47 ms 3796 KB Output is correct
53 Correct 47 ms 3796 KB Output is correct
54 Correct 47 ms 3796 KB Output is correct
55 Correct 47 ms 3796 KB Output is correct
56 Correct 48 ms 3796 KB Output is correct
57 Correct 47 ms 3796 KB Output is correct
58 Correct 47 ms 3776 KB Output is correct
59 Correct 48 ms 3796 KB Output is correct
60 Correct 49 ms 3796 KB Output is correct
61 Correct 52 ms 3796 KB Output is correct
62 Correct 47 ms 3796 KB Output is correct
63 Correct 48 ms 3996 KB Output is correct
64 Correct 48 ms 3796 KB Output is correct
65 Correct 50 ms 3796 KB Output is correct
66 Correct 47 ms 3804 KB Output is correct
67 Correct 51 ms 3688 KB Output is correct
68 Correct 49 ms 3796 KB Output is correct
69 Correct 48 ms 3796 KB Output is correct
70 Correct 50 ms 3796 KB Output is correct
71 Correct 10 ms 988 KB Output is correct
72 Correct 10 ms 988 KB Output is correct
73 Correct 9 ms 988 KB Output is correct
74 Correct 10 ms 988 KB Output is correct
75 Correct 12 ms 988 KB Output is correct
76 Correct 21 ms 1500 KB Output is correct
77 Correct 21 ms 1500 KB Output is correct
78 Correct 21 ms 1500 KB Output is correct
79 Correct 21 ms 1500 KB Output is correct
80 Correct 22 ms 1700 KB Output is correct
81 Correct 53 ms 2508 KB Output is correct
82 Correct 50 ms 2692 KB Output is correct
83 Correct 51 ms 2508 KB Output is correct
84 Correct 50 ms 2508 KB Output is correct
85 Correct 55 ms 2520 KB Output is correct
86 Correct 60 ms 3276 KB Output is correct
87 Correct 59 ms 3276 KB Output is correct
88 Correct 61 ms 3228 KB Output is correct
89 Correct 61 ms 3276 KB Output is correct
90 Correct 61 ms 3204 KB Output is correct
91 Correct 136 ms 11208 KB Output is correct
92 Correct 138 ms 11092 KB Output is correct
93 Correct 137 ms 11208 KB Output is correct
94 Correct 133 ms 11208 KB Output is correct
95 Correct 142 ms 12232 KB Output is correct
96 Correct 181 ms 17352 KB Output is correct
97 Correct 198 ms 17352 KB Output is correct
98 Correct 169 ms 17352 KB Output is correct
99 Correct 193 ms 17328 KB Output is correct
100 Correct 180 ms 17352 KB Output is correct
101 Correct 208 ms 17352 KB Output is correct
102 Correct 180 ms 17352 KB Output is correct
103 Correct 187 ms 17636 KB Output is correct
104 Correct 174 ms 17352 KB Output is correct
105 Correct 184 ms 17340 KB Output is correct
106 Correct 185 ms 20168 KB Output is correct
107 Correct 200 ms 20348 KB Output is correct
108 Correct 198 ms 20164 KB Output is correct
109 Correct 207 ms 20228 KB Output is correct
110 Correct 196 ms 20168 KB Output is correct
111 Correct 191 ms 20168 KB Output is correct
112 Correct 215 ms 20168 KB Output is correct
113 Correct 229 ms 20168 KB Output is correct
114 Correct 201 ms 20168 KB Output is correct
115 Correct 223 ms 20180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 600 KB Output is correct
14 Correct 9 ms 1500 KB Output is correct
15 Correct 17 ms 2264 KB Output is correct
16 Correct 27 ms 3796 KB Output is correct
17 Correct 24 ms 4052 KB Output is correct
18 Correct 26 ms 3796 KB Output is correct
19 Correct 25 ms 3808 KB Output is correct
20 Correct 26 ms 3796 KB Output is correct
21 Correct 30 ms 3796 KB Output is correct
22 Correct 27 ms 3800 KB Output is correct
23 Correct 27 ms 3796 KB Output is correct
24 Correct 27 ms 3796 KB Output is correct
25 Correct 26 ms 3956 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 1 ms 600 KB Output is correct
29 Correct 10 ms 1500 KB Output is correct
30 Correct 19 ms 2268 KB Output is correct
31 Correct 29 ms 3608 KB Output is correct
32 Correct 30 ms 3796 KB Output is correct
33 Correct 30 ms 3796 KB Output is correct
34 Correct 30 ms 3796 KB Output is correct
35 Correct 29 ms 3796 KB Output is correct
36 Correct 31 ms 3796 KB Output is correct
37 Correct 36 ms 3796 KB Output is correct
38 Correct 29 ms 3796 KB Output is correct
39 Correct 30 ms 3796 KB Output is correct
40 Correct 30 ms 3796 KB Output is correct
41 Correct 1 ms 344 KB Output is correct
42 Correct 0 ms 344 KB Output is correct
43 Correct 0 ms 344 KB Output is correct
44 Correct 1 ms 600 KB Output is correct
45 Correct 2 ms 600 KB Output is correct
46 Correct 3 ms 600 KB Output is correct
47 Correct 8 ms 988 KB Output is correct
48 Correct 9 ms 988 KB Output is correct
49 Correct 16 ms 1500 KB Output is correct
50 Correct 31 ms 2264 KB Output is correct
51 Correct 46 ms 3796 KB Output is correct
52 Correct 47 ms 3796 KB Output is correct
53 Correct 47 ms 3796 KB Output is correct
54 Correct 47 ms 3796 KB Output is correct
55 Correct 47 ms 3796 KB Output is correct
56 Correct 48 ms 3796 KB Output is correct
57 Correct 47 ms 3796 KB Output is correct
58 Correct 47 ms 3776 KB Output is correct
59 Correct 48 ms 3796 KB Output is correct
60 Correct 49 ms 3796 KB Output is correct
61 Correct 52 ms 3796 KB Output is correct
62 Correct 47 ms 3796 KB Output is correct
63 Correct 48 ms 3996 KB Output is correct
64 Correct 48 ms 3796 KB Output is correct
65 Correct 50 ms 3796 KB Output is correct
66 Correct 47 ms 3804 KB Output is correct
67 Correct 51 ms 3688 KB Output is correct
68 Correct 49 ms 3796 KB Output is correct
69 Correct 48 ms 3796 KB Output is correct
70 Correct 50 ms 3796 KB Output is correct
71 Correct 10 ms 988 KB Output is correct
72 Correct 10 ms 988 KB Output is correct
73 Correct 9 ms 988 KB Output is correct
74 Correct 10 ms 988 KB Output is correct
75 Correct 12 ms 988 KB Output is correct
76 Correct 21 ms 1500 KB Output is correct
77 Correct 21 ms 1500 KB Output is correct
78 Correct 21 ms 1500 KB Output is correct
79 Correct 21 ms 1500 KB Output is correct
80 Correct 22 ms 1700 KB Output is correct
81 Correct 53 ms 2508 KB Output is correct
82 Correct 50 ms 2692 KB Output is correct
83 Correct 51 ms 2508 KB Output is correct
84 Correct 50 ms 2508 KB Output is correct
85 Correct 55 ms 2520 KB Output is correct
86 Correct 60 ms 3276 KB Output is correct
87 Correct 59 ms 3276 KB Output is correct
88 Correct 61 ms 3228 KB Output is correct
89 Correct 61 ms 3276 KB Output is correct
90 Correct 61 ms 3204 KB Output is correct
91 Correct 136 ms 11208 KB Output is correct
92 Correct 138 ms 11092 KB Output is correct
93 Correct 137 ms 11208 KB Output is correct
94 Correct 133 ms 11208 KB Output is correct
95 Correct 142 ms 12232 KB Output is correct
96 Correct 181 ms 17352 KB Output is correct
97 Correct 198 ms 17352 KB Output is correct
98 Correct 169 ms 17352 KB Output is correct
99 Correct 193 ms 17328 KB Output is correct
100 Correct 180 ms 17352 KB Output is correct
101 Correct 208 ms 17352 KB Output is correct
102 Correct 180 ms 17352 KB Output is correct
103 Correct 187 ms 17636 KB Output is correct
104 Correct 174 ms 17352 KB Output is correct
105 Correct 184 ms 17340 KB Output is correct
106 Correct 185 ms 20168 KB Output is correct
107 Correct 200 ms 20348 KB Output is correct
108 Correct 198 ms 20164 KB Output is correct
109 Correct 207 ms 20228 KB Output is correct
110 Correct 196 ms 20168 KB Output is correct
111 Correct 191 ms 20168 KB Output is correct
112 Correct 215 ms 20168 KB Output is correct
113 Correct 229 ms 20168 KB Output is correct
114 Correct 201 ms 20168 KB Output is correct
115 Correct 223 ms 20180 KB Output is correct
116 Correct 244 ms 848 KB Output is correct
117 Correct 320 ms 880 KB Output is correct
118 Correct 952 ms 1524 KB Output is correct
119 Correct 1613 ms 1920 KB Output is correct
120 Correct 2293 ms 1492 KB Output is correct
121 Correct 3234 ms 2000 KB Output is correct
122 Correct 4564 ms 2144 KB Output is correct
123 Correct 5007 ms 2832 KB Output is correct
124 Execution timed out 7052 ms 2880 KB Time limit exceeded
125 Halted 0 ms 0 KB -