답안 #920280

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
920280 2024-02-02T11:46:52 Z vjudge1 Diversity (CEOI21_diversity) C++17
64 / 100
7000 ms 9216 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>
 
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);
	int mx = 0;
	for (int i = 1; i <= n; i++) {
		cin >> 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;				
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 5 ms 856 KB Output is correct
5 Correct 9 ms 1112 KB Output is correct
6 Correct 15 ms 1624 KB Output is correct
7 Correct 13 ms 1624 KB Output is correct
8 Correct 14 ms 1624 KB Output is correct
9 Correct 14 ms 1624 KB Output is correct
10 Correct 13 ms 1624 KB Output is correct
11 Correct 14 ms 1624 KB Output is correct
12 Correct 13 ms 1624 KB Output is correct
13 Correct 13 ms 1624 KB Output is correct
14 Correct 13 ms 1624 KB Output is correct
15 Correct 17 ms 1628 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 5 ms 856 KB Output is correct
5 Correct 9 ms 1112 KB Output is correct
6 Correct 15 ms 1624 KB Output is correct
7 Correct 13 ms 1624 KB Output is correct
8 Correct 14 ms 1624 KB Output is correct
9 Correct 14 ms 1624 KB Output is correct
10 Correct 13 ms 1624 KB Output is correct
11 Correct 14 ms 1624 KB Output is correct
12 Correct 13 ms 1624 KB Output is correct
13 Correct 13 ms 1624 KB Output is correct
14 Correct 13 ms 1624 KB Output is correct
15 Correct 17 ms 1628 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 5 ms 856 KB Output is correct
20 Correct 10 ms 1312 KB Output is correct
21 Correct 14 ms 1624 KB Output is correct
22 Correct 14 ms 1624 KB Output is correct
23 Correct 14 ms 1624 KB Output is correct
24 Correct 17 ms 2036 KB Output is correct
25 Correct 14 ms 1624 KB Output is correct
26 Correct 15 ms 1624 KB Output is correct
27 Correct 14 ms 1624 KB Output is correct
28 Correct 15 ms 1624 KB Output is correct
29 Correct 14 ms 1628 KB Output is correct
30 Correct 14 ms 1624 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 5 ms 856 KB Output is correct
5 Correct 9 ms 1112 KB Output is correct
6 Correct 15 ms 1624 KB Output is correct
7 Correct 13 ms 1624 KB Output is correct
8 Correct 14 ms 1624 KB Output is correct
9 Correct 14 ms 1624 KB Output is correct
10 Correct 13 ms 1624 KB Output is correct
11 Correct 14 ms 1624 KB Output is correct
12 Correct 13 ms 1624 KB Output is correct
13 Correct 13 ms 1624 KB Output is correct
14 Correct 13 ms 1624 KB Output is correct
15 Correct 17 ms 1628 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 5 ms 856 KB Output is correct
20 Correct 10 ms 1312 KB Output is correct
21 Correct 14 ms 1624 KB Output is correct
22 Correct 14 ms 1624 KB Output is correct
23 Correct 14 ms 1624 KB Output is correct
24 Correct 17 ms 2036 KB Output is correct
25 Correct 14 ms 1624 KB Output is correct
26 Correct 15 ms 1624 KB Output is correct
27 Correct 14 ms 1624 KB Output is correct
28 Correct 15 ms 1624 KB Output is correct
29 Correct 14 ms 1628 KB Output is correct
30 Correct 14 ms 1624 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 0 ms 344 KB Output is correct
34 Correct 1 ms 344 KB Output is correct
35 Correct 1 ms 344 KB Output is correct
36 Correct 1 ms 344 KB Output is correct
37 Correct 3 ms 600 KB Output is correct
38 Correct 3 ms 600 KB Output is correct
39 Correct 5 ms 856 KB Output is correct
40 Correct 10 ms 1112 KB Output is correct
41 Correct 16 ms 1624 KB Output is correct
42 Correct 15 ms 1628 KB Output is correct
43 Correct 15 ms 1624 KB Output is correct
44 Correct 16 ms 1628 KB Output is correct
45 Correct 17 ms 1624 KB Output is correct
46 Correct 15 ms 1624 KB Output is correct
47 Correct 16 ms 1624 KB Output is correct
48 Correct 15 ms 1628 KB Output is correct
49 Correct 15 ms 1624 KB Output is correct
50 Correct 15 ms 1624 KB Output is correct
51 Correct 15 ms 1624 KB Output is correct
52 Correct 15 ms 1656 KB Output is correct
53 Correct 15 ms 1624 KB Output is correct
54 Correct 17 ms 1628 KB Output is correct
55 Correct 15 ms 1624 KB Output is correct
56 Correct 15 ms 1624 KB Output is correct
57 Correct 15 ms 1624 KB Output is correct
58 Correct 15 ms 1624 KB Output is correct
59 Correct 15 ms 1624 KB Output is correct
60 Correct 15 ms 1624 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 5 ms 856 KB Output is correct
15 Correct 9 ms 1112 KB Output is correct
16 Correct 15 ms 1624 KB Output is correct
17 Correct 13 ms 1624 KB Output is correct
18 Correct 14 ms 1624 KB Output is correct
19 Correct 14 ms 1624 KB Output is correct
20 Correct 13 ms 1624 KB Output is correct
21 Correct 14 ms 1624 KB Output is correct
22 Correct 13 ms 1624 KB Output is correct
23 Correct 13 ms 1624 KB Output is correct
24 Correct 13 ms 1624 KB Output is correct
25 Correct 17 ms 1628 KB Output is correct
26 Correct 0 ms 344 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 5 ms 856 KB Output is correct
30 Correct 10 ms 1312 KB Output is correct
31 Correct 14 ms 1624 KB Output is correct
32 Correct 14 ms 1624 KB Output is correct
33 Correct 14 ms 1624 KB Output is correct
34 Correct 17 ms 2036 KB Output is correct
35 Correct 14 ms 1624 KB Output is correct
36 Correct 15 ms 1624 KB Output is correct
37 Correct 14 ms 1624 KB Output is correct
38 Correct 15 ms 1624 KB Output is correct
39 Correct 14 ms 1628 KB Output is correct
40 Correct 14 ms 1624 KB Output is correct
41 Correct 0 ms 344 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 0 ms 344 KB Output is correct
44 Correct 1 ms 344 KB Output is correct
45 Correct 1 ms 344 KB Output is correct
46 Correct 1 ms 344 KB Output is correct
47 Correct 3 ms 600 KB Output is correct
48 Correct 3 ms 600 KB Output is correct
49 Correct 5 ms 856 KB Output is correct
50 Correct 10 ms 1112 KB Output is correct
51 Correct 16 ms 1624 KB Output is correct
52 Correct 15 ms 1628 KB Output is correct
53 Correct 15 ms 1624 KB Output is correct
54 Correct 16 ms 1628 KB Output is correct
55 Correct 17 ms 1624 KB Output is correct
56 Correct 15 ms 1624 KB Output is correct
57 Correct 16 ms 1624 KB Output is correct
58 Correct 15 ms 1628 KB Output is correct
59 Correct 15 ms 1624 KB Output is correct
60 Correct 15 ms 1624 KB Output is correct
61 Correct 15 ms 1624 KB Output is correct
62 Correct 15 ms 1656 KB Output is correct
63 Correct 15 ms 1624 KB Output is correct
64 Correct 17 ms 1628 KB Output is correct
65 Correct 15 ms 1624 KB Output is correct
66 Correct 15 ms 1624 KB Output is correct
67 Correct 15 ms 1624 KB Output is correct
68 Correct 15 ms 1624 KB Output is correct
69 Correct 15 ms 1624 KB Output is correct
70 Correct 15 ms 1624 KB Output is correct
71 Correct 4 ms 600 KB Output is correct
72 Correct 3 ms 600 KB Output is correct
73 Correct 3 ms 604 KB Output is correct
74 Correct 3 ms 604 KB Output is correct
75 Correct 4 ms 600 KB Output is correct
76 Correct 6 ms 860 KB Output is correct
77 Correct 6 ms 856 KB Output is correct
78 Correct 6 ms 860 KB Output is correct
79 Correct 6 ms 856 KB Output is correct
80 Correct 6 ms 1056 KB Output is correct
81 Correct 11 ms 1372 KB Output is correct
82 Correct 11 ms 1368 KB Output is correct
83 Correct 12 ms 1368 KB Output is correct
84 Correct 12 ms 1368 KB Output is correct
85 Correct 12 ms 1368 KB Output is correct
86 Correct 13 ms 1624 KB Output is correct
87 Correct 13 ms 1624 KB Output is correct
88 Correct 14 ms 1880 KB Output is correct
89 Correct 14 ms 1880 KB Output is correct
90 Correct 14 ms 1624 KB Output is correct
91 Correct 22 ms 5172 KB Output is correct
92 Correct 23 ms 5340 KB Output is correct
93 Correct 22 ms 5340 KB Output is correct
94 Correct 22 ms 5328 KB Output is correct
95 Correct 25 ms 5328 KB Output is correct
96 Correct 29 ms 6840 KB Output is correct
97 Correct 29 ms 8652 KB Output is correct
98 Correct 28 ms 8660 KB Output is correct
99 Correct 28 ms 8652 KB Output is correct
100 Correct 28 ms 8584 KB Output is correct
101 Correct 27 ms 8652 KB Output is correct
102 Correct 28 ms 8540 KB Output is correct
103 Correct 28 ms 8660 KB Output is correct
104 Correct 27 ms 8544 KB Output is correct
105 Correct 27 ms 8652 KB Output is correct
106 Correct 28 ms 9056 KB Output is correct
107 Correct 29 ms 9216 KB Output is correct
108 Correct 28 ms 9164 KB Output is correct
109 Correct 28 ms 9164 KB Output is correct
110 Correct 29 ms 9184 KB Output is correct
111 Correct 28 ms 9184 KB Output is correct
112 Correct 27 ms 9164 KB Output is correct
113 Correct 28 ms 9172 KB Output is correct
114 Correct 27 ms 9164 KB Output is correct
115 Correct 27 ms 9164 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 5 ms 856 KB Output is correct
15 Correct 9 ms 1112 KB Output is correct
16 Correct 15 ms 1624 KB Output is correct
17 Correct 13 ms 1624 KB Output is correct
18 Correct 14 ms 1624 KB Output is correct
19 Correct 14 ms 1624 KB Output is correct
20 Correct 13 ms 1624 KB Output is correct
21 Correct 14 ms 1624 KB Output is correct
22 Correct 13 ms 1624 KB Output is correct
23 Correct 13 ms 1624 KB Output is correct
24 Correct 13 ms 1624 KB Output is correct
25 Correct 17 ms 1628 KB Output is correct
26 Correct 0 ms 344 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 5 ms 856 KB Output is correct
30 Correct 10 ms 1312 KB Output is correct
31 Correct 14 ms 1624 KB Output is correct
32 Correct 14 ms 1624 KB Output is correct
33 Correct 14 ms 1624 KB Output is correct
34 Correct 17 ms 2036 KB Output is correct
35 Correct 14 ms 1624 KB Output is correct
36 Correct 15 ms 1624 KB Output is correct
37 Correct 14 ms 1624 KB Output is correct
38 Correct 15 ms 1624 KB Output is correct
39 Correct 14 ms 1628 KB Output is correct
40 Correct 14 ms 1624 KB Output is correct
41 Correct 0 ms 344 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 0 ms 344 KB Output is correct
44 Correct 1 ms 344 KB Output is correct
45 Correct 1 ms 344 KB Output is correct
46 Correct 1 ms 344 KB Output is correct
47 Correct 3 ms 600 KB Output is correct
48 Correct 3 ms 600 KB Output is correct
49 Correct 5 ms 856 KB Output is correct
50 Correct 10 ms 1112 KB Output is correct
51 Correct 16 ms 1624 KB Output is correct
52 Correct 15 ms 1628 KB Output is correct
53 Correct 15 ms 1624 KB Output is correct
54 Correct 16 ms 1628 KB Output is correct
55 Correct 17 ms 1624 KB Output is correct
56 Correct 15 ms 1624 KB Output is correct
57 Correct 16 ms 1624 KB Output is correct
58 Correct 15 ms 1628 KB Output is correct
59 Correct 15 ms 1624 KB Output is correct
60 Correct 15 ms 1624 KB Output is correct
61 Correct 15 ms 1624 KB Output is correct
62 Correct 15 ms 1656 KB Output is correct
63 Correct 15 ms 1624 KB Output is correct
64 Correct 17 ms 1628 KB Output is correct
65 Correct 15 ms 1624 KB Output is correct
66 Correct 15 ms 1624 KB Output is correct
67 Correct 15 ms 1624 KB Output is correct
68 Correct 15 ms 1624 KB Output is correct
69 Correct 15 ms 1624 KB Output is correct
70 Correct 15 ms 1624 KB Output is correct
71 Correct 4 ms 600 KB Output is correct
72 Correct 3 ms 600 KB Output is correct
73 Correct 3 ms 604 KB Output is correct
74 Correct 3 ms 604 KB Output is correct
75 Correct 4 ms 600 KB Output is correct
76 Correct 6 ms 860 KB Output is correct
77 Correct 6 ms 856 KB Output is correct
78 Correct 6 ms 860 KB Output is correct
79 Correct 6 ms 856 KB Output is correct
80 Correct 6 ms 1056 KB Output is correct
81 Correct 11 ms 1372 KB Output is correct
82 Correct 11 ms 1368 KB Output is correct
83 Correct 12 ms 1368 KB Output is correct
84 Correct 12 ms 1368 KB Output is correct
85 Correct 12 ms 1368 KB Output is correct
86 Correct 13 ms 1624 KB Output is correct
87 Correct 13 ms 1624 KB Output is correct
88 Correct 14 ms 1880 KB Output is correct
89 Correct 14 ms 1880 KB Output is correct
90 Correct 14 ms 1624 KB Output is correct
91 Correct 22 ms 5172 KB Output is correct
92 Correct 23 ms 5340 KB Output is correct
93 Correct 22 ms 5340 KB Output is correct
94 Correct 22 ms 5328 KB Output is correct
95 Correct 25 ms 5328 KB Output is correct
96 Correct 29 ms 6840 KB Output is correct
97 Correct 29 ms 8652 KB Output is correct
98 Correct 28 ms 8660 KB Output is correct
99 Correct 28 ms 8652 KB Output is correct
100 Correct 28 ms 8584 KB Output is correct
101 Correct 27 ms 8652 KB Output is correct
102 Correct 28 ms 8540 KB Output is correct
103 Correct 28 ms 8660 KB Output is correct
104 Correct 27 ms 8544 KB Output is correct
105 Correct 27 ms 8652 KB Output is correct
106 Correct 28 ms 9056 KB Output is correct
107 Correct 29 ms 9216 KB Output is correct
108 Correct 28 ms 9164 KB Output is correct
109 Correct 28 ms 9164 KB Output is correct
110 Correct 29 ms 9184 KB Output is correct
111 Correct 28 ms 9184 KB Output is correct
112 Correct 27 ms 9164 KB Output is correct
113 Correct 28 ms 9172 KB Output is correct
114 Correct 27 ms 9164 KB Output is correct
115 Correct 27 ms 9164 KB Output is correct
116 Correct 264 ms 1296 KB Output is correct
117 Correct 352 ms 1360 KB Output is correct
118 Correct 1089 ms 2120 KB Output is correct
119 Correct 1758 ms 2352 KB Output is correct
120 Correct 2461 ms 1848 KB Output is correct
121 Correct 3574 ms 2436 KB Output is correct
122 Correct 4946 ms 2972 KB Output is correct
123 Correct 5595 ms 3436 KB Output is correct
124 Execution timed out 7025 ms 3328 KB Time limit exceeded
125 Halted 0 ms 0 KB -