Submission #920285

# Submission time Handle Problem Language Result Execution time Memory
920285 2024-02-02T11:54:34 Z vjudge1 Diversity (CEOI21_diversity) C++17
64 / 100
7000 ms 20428 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")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
 
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 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 3 ms 600 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 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 3796 KB Output is correct
8 Correct 26 ms 3796 KB Output is correct
9 Correct 26 ms 3796 KB Output is correct
10 Correct 25 ms 3796 KB Output is correct
11 Correct 33 ms 4108 KB Output is correct
12 Correct 27 ms 3796 KB Output is correct
13 Correct 27 ms 3800 KB Output is correct
14 Correct 26 ms 4076 KB Output is correct
15 Correct 28 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 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 3796 KB Output is correct
8 Correct 26 ms 3796 KB Output is correct
9 Correct 26 ms 3796 KB Output is correct
10 Correct 25 ms 3796 KB Output is correct
11 Correct 33 ms 4108 KB Output is correct
12 Correct 27 ms 3796 KB Output is correct
13 Correct 27 ms 3800 KB Output is correct
14 Correct 26 ms 4076 KB Output is correct
15 Correct 28 ms 3796 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 1 ms 544 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 10 ms 1500 KB Output is correct
20 Correct 20 ms 2264 KB Output is correct
21 Correct 29 ms 3796 KB Output is correct
22 Correct 31 ms 3800 KB Output is correct
23 Correct 29 ms 3796 KB Output is correct
24 Correct 30 ms 3796 KB Output is correct
25 Correct 30 ms 3800 KB Output is correct
26 Correct 31 ms 3796 KB Output is correct
27 Correct 35 ms 3796 KB Output is correct
28 Correct 30 ms 3800 KB Output is correct
29 Correct 30 ms 3800 KB Output is correct
30 Correct 33 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 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 3796 KB Output is correct
8 Correct 26 ms 3796 KB Output is correct
9 Correct 26 ms 3796 KB Output is correct
10 Correct 25 ms 3796 KB Output is correct
11 Correct 33 ms 4108 KB Output is correct
12 Correct 27 ms 3796 KB Output is correct
13 Correct 27 ms 3800 KB Output is correct
14 Correct 26 ms 4076 KB Output is correct
15 Correct 28 ms 3796 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 1 ms 544 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 10 ms 1500 KB Output is correct
20 Correct 20 ms 2264 KB Output is correct
21 Correct 29 ms 3796 KB Output is correct
22 Correct 31 ms 3800 KB Output is correct
23 Correct 29 ms 3796 KB Output is correct
24 Correct 30 ms 3796 KB Output is correct
25 Correct 30 ms 3800 KB Output is correct
26 Correct 31 ms 3796 KB Output is correct
27 Correct 35 ms 3796 KB Output is correct
28 Correct 30 ms 3800 KB Output is correct
29 Correct 30 ms 3800 KB Output is correct
30 Correct 33 ms 3796 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 1 ms 344 KB Output is correct
34 Correct 2 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 7 ms 1000 KB Output is correct
38 Correct 8 ms 988 KB Output is correct
39 Correct 16 ms 1500 KB Output is correct
40 Correct 32 ms 2264 KB Output is correct
41 Correct 48 ms 3800 KB Output is correct
42 Correct 48 ms 3796 KB Output is correct
43 Correct 48 ms 3796 KB Output is correct
44 Correct 48 ms 3796 KB Output is correct
45 Correct 47 ms 3796 KB Output is correct
46 Correct 50 ms 3796 KB Output is correct
47 Correct 47 ms 3720 KB Output is correct
48 Correct 48 ms 3796 KB Output is correct
49 Correct 47 ms 3796 KB Output is correct
50 Correct 48 ms 3796 KB Output is correct
51 Correct 46 ms 3796 KB Output is correct
52 Correct 52 ms 3788 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 47 ms 3800 KB Output is correct
57 Correct 47 ms 3796 KB Output is correct
58 Correct 47 ms 3796 KB Output is correct
59 Correct 47 ms 3796 KB Output is correct
60 Correct 48 ms 3800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 3 ms 600 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 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 3796 KB Output is correct
18 Correct 26 ms 3796 KB Output is correct
19 Correct 26 ms 3796 KB Output is correct
20 Correct 25 ms 3796 KB Output is correct
21 Correct 33 ms 4108 KB Output is correct
22 Correct 27 ms 3796 KB Output is correct
23 Correct 27 ms 3800 KB Output is correct
24 Correct 26 ms 4076 KB Output is correct
25 Correct 28 ms 3796 KB Output is correct
26 Correct 0 ms 344 KB Output is correct
27 Correct 1 ms 544 KB Output is correct
28 Correct 1 ms 604 KB Output is correct
29 Correct 10 ms 1500 KB Output is correct
30 Correct 20 ms 2264 KB Output is correct
31 Correct 29 ms 3796 KB Output is correct
32 Correct 31 ms 3800 KB Output is correct
33 Correct 29 ms 3796 KB Output is correct
34 Correct 30 ms 3796 KB Output is correct
35 Correct 30 ms 3800 KB Output is correct
36 Correct 31 ms 3796 KB Output is correct
37 Correct 35 ms 3796 KB Output is correct
38 Correct 30 ms 3800 KB Output is correct
39 Correct 30 ms 3800 KB Output is correct
40 Correct 33 ms 3796 KB Output is correct
41 Correct 1 ms 348 KB Output is correct
42 Correct 1 ms 344 KB Output is correct
43 Correct 1 ms 344 KB Output is correct
44 Correct 2 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 7 ms 1000 KB Output is correct
48 Correct 8 ms 988 KB Output is correct
49 Correct 16 ms 1500 KB Output is correct
50 Correct 32 ms 2264 KB Output is correct
51 Correct 48 ms 3800 KB Output is correct
52 Correct 48 ms 3796 KB Output is correct
53 Correct 48 ms 3796 KB Output is correct
54 Correct 48 ms 3796 KB Output is correct
55 Correct 47 ms 3796 KB Output is correct
56 Correct 50 ms 3796 KB Output is correct
57 Correct 47 ms 3720 KB Output is correct
58 Correct 48 ms 3796 KB Output is correct
59 Correct 47 ms 3796 KB Output is correct
60 Correct 48 ms 3796 KB Output is correct
61 Correct 46 ms 3796 KB Output is correct
62 Correct 52 ms 3788 KB Output is correct
63 Correct 47 ms 3796 KB Output is correct
64 Correct 47 ms 3796 KB Output is correct
65 Correct 47 ms 3796 KB Output is correct
66 Correct 47 ms 3800 KB Output is correct
67 Correct 47 ms 3796 KB Output is correct
68 Correct 47 ms 3796 KB Output is correct
69 Correct 47 ms 3796 KB Output is correct
70 Correct 48 ms 3800 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 992 KB Output is correct
74 Correct 9 ms 992 KB Output is correct
75 Correct 10 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 22 ms 1500 KB Output is correct
79 Correct 21 ms 1764 KB Output is correct
80 Correct 21 ms 1500 KB Output is correct
81 Correct 50 ms 2496 KB Output is correct
82 Correct 49 ms 2508 KB Output is correct
83 Correct 51 ms 2512 KB Output is correct
84 Correct 49 ms 2520 KB Output is correct
85 Correct 50 ms 2552 KB Output is correct
86 Correct 60 ms 3276 KB Output is correct
87 Correct 60 ms 3280 KB Output is correct
88 Correct 60 ms 3276 KB Output is correct
89 Correct 67 ms 3440 KB Output is correct
90 Correct 62 ms 3276 KB Output is correct
91 Correct 141 ms 11092 KB Output is correct
92 Correct 144 ms 11204 KB Output is correct
93 Correct 134 ms 11208 KB Output is correct
94 Correct 136 ms 11036 KB Output is correct
95 Correct 136 ms 11124 KB Output is correct
96 Correct 178 ms 17352 KB Output is correct
97 Correct 182 ms 17312 KB Output is correct
98 Correct 180 ms 17200 KB Output is correct
99 Correct 186 ms 17388 KB Output is correct
100 Correct 173 ms 17352 KB Output is correct
101 Correct 173 ms 17356 KB Output is correct
102 Correct 177 ms 17352 KB Output is correct
103 Correct 184 ms 17356 KB Output is correct
104 Correct 195 ms 17320 KB Output is correct
105 Correct 175 ms 17276 KB Output is correct
106 Correct 213 ms 20076 KB Output is correct
107 Correct 181 ms 20184 KB Output is correct
108 Correct 214 ms 20428 KB Output is correct
109 Correct 211 ms 20168 KB Output is correct
110 Correct 187 ms 20176 KB Output is correct
111 Correct 215 ms 20088 KB Output is correct
112 Correct 197 ms 20420 KB Output is correct
113 Correct 217 ms 20168 KB Output is correct
114 Correct 191 ms 20092 KB Output is correct
115 Correct 227 ms 20168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 3 ms 600 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 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 3796 KB Output is correct
18 Correct 26 ms 3796 KB Output is correct
19 Correct 26 ms 3796 KB Output is correct
20 Correct 25 ms 3796 KB Output is correct
21 Correct 33 ms 4108 KB Output is correct
22 Correct 27 ms 3796 KB Output is correct
23 Correct 27 ms 3800 KB Output is correct
24 Correct 26 ms 4076 KB Output is correct
25 Correct 28 ms 3796 KB Output is correct
26 Correct 0 ms 344 KB Output is correct
27 Correct 1 ms 544 KB Output is correct
28 Correct 1 ms 604 KB Output is correct
29 Correct 10 ms 1500 KB Output is correct
30 Correct 20 ms 2264 KB Output is correct
31 Correct 29 ms 3796 KB Output is correct
32 Correct 31 ms 3800 KB Output is correct
33 Correct 29 ms 3796 KB Output is correct
34 Correct 30 ms 3796 KB Output is correct
35 Correct 30 ms 3800 KB Output is correct
36 Correct 31 ms 3796 KB Output is correct
37 Correct 35 ms 3796 KB Output is correct
38 Correct 30 ms 3800 KB Output is correct
39 Correct 30 ms 3800 KB Output is correct
40 Correct 33 ms 3796 KB Output is correct
41 Correct 1 ms 348 KB Output is correct
42 Correct 1 ms 344 KB Output is correct
43 Correct 1 ms 344 KB Output is correct
44 Correct 2 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 7 ms 1000 KB Output is correct
48 Correct 8 ms 988 KB Output is correct
49 Correct 16 ms 1500 KB Output is correct
50 Correct 32 ms 2264 KB Output is correct
51 Correct 48 ms 3800 KB Output is correct
52 Correct 48 ms 3796 KB Output is correct
53 Correct 48 ms 3796 KB Output is correct
54 Correct 48 ms 3796 KB Output is correct
55 Correct 47 ms 3796 KB Output is correct
56 Correct 50 ms 3796 KB Output is correct
57 Correct 47 ms 3720 KB Output is correct
58 Correct 48 ms 3796 KB Output is correct
59 Correct 47 ms 3796 KB Output is correct
60 Correct 48 ms 3796 KB Output is correct
61 Correct 46 ms 3796 KB Output is correct
62 Correct 52 ms 3788 KB Output is correct
63 Correct 47 ms 3796 KB Output is correct
64 Correct 47 ms 3796 KB Output is correct
65 Correct 47 ms 3796 KB Output is correct
66 Correct 47 ms 3800 KB Output is correct
67 Correct 47 ms 3796 KB Output is correct
68 Correct 47 ms 3796 KB Output is correct
69 Correct 47 ms 3796 KB Output is correct
70 Correct 48 ms 3800 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 992 KB Output is correct
74 Correct 9 ms 992 KB Output is correct
75 Correct 10 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 22 ms 1500 KB Output is correct
79 Correct 21 ms 1764 KB Output is correct
80 Correct 21 ms 1500 KB Output is correct
81 Correct 50 ms 2496 KB Output is correct
82 Correct 49 ms 2508 KB Output is correct
83 Correct 51 ms 2512 KB Output is correct
84 Correct 49 ms 2520 KB Output is correct
85 Correct 50 ms 2552 KB Output is correct
86 Correct 60 ms 3276 KB Output is correct
87 Correct 60 ms 3280 KB Output is correct
88 Correct 60 ms 3276 KB Output is correct
89 Correct 67 ms 3440 KB Output is correct
90 Correct 62 ms 3276 KB Output is correct
91 Correct 141 ms 11092 KB Output is correct
92 Correct 144 ms 11204 KB Output is correct
93 Correct 134 ms 11208 KB Output is correct
94 Correct 136 ms 11036 KB Output is correct
95 Correct 136 ms 11124 KB Output is correct
96 Correct 178 ms 17352 KB Output is correct
97 Correct 182 ms 17312 KB Output is correct
98 Correct 180 ms 17200 KB Output is correct
99 Correct 186 ms 17388 KB Output is correct
100 Correct 173 ms 17352 KB Output is correct
101 Correct 173 ms 17356 KB Output is correct
102 Correct 177 ms 17352 KB Output is correct
103 Correct 184 ms 17356 KB Output is correct
104 Correct 195 ms 17320 KB Output is correct
105 Correct 175 ms 17276 KB Output is correct
106 Correct 213 ms 20076 KB Output is correct
107 Correct 181 ms 20184 KB Output is correct
108 Correct 214 ms 20428 KB Output is correct
109 Correct 211 ms 20168 KB Output is correct
110 Correct 187 ms 20176 KB Output is correct
111 Correct 215 ms 20088 KB Output is correct
112 Correct 197 ms 20420 KB Output is correct
113 Correct 217 ms 20168 KB Output is correct
114 Correct 191 ms 20092 KB Output is correct
115 Correct 227 ms 20168 KB Output is correct
116 Correct 243 ms 1196 KB Output is correct
117 Correct 327 ms 848 KB Output is correct
118 Correct 926 ms 1748 KB Output is correct
119 Correct 1593 ms 1500 KB Output is correct
120 Correct 2289 ms 1728 KB Output is correct
121 Correct 3227 ms 1892 KB Output is correct
122 Correct 4521 ms 1788 KB Output is correct
123 Correct 4960 ms 3100 KB Output is correct
124 Execution timed out 7012 ms 3144 KB Time limit exceeded
125 Halted 0 ms 0 KB -