답안 #881899

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
881899 2023-12-02T08:24:19 Z TAhmed33 Diversity (CEOI21_diversity) C++
64 / 100
7000 ms 4128 KB
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize ("Ofast")
#pragma GCC target ("popcnt")
typedef long long ll;
const int BUF_SZ = 1 << 15;
inline namespace Input {
char buf[BUF_SZ];
ll pos;
ll len;
char next_char() {
	if (pos == len) {
		pos = 0;
		len = (ll)fread(buf, 1, BUF_SZ, stdin);
		if (!len) { return EOF; }
	}
	return buf[pos++];
}
ll read_int() {
	ll x;
	char ch;
	ll sgn = 1;
	while (!isdigit(ch = next_char())) {
		if (ch == '-') { sgn *= -1; }
	}
	x = ch - '0';
	while (isdigit(ch = next_char())) { x = x * 10 + (ch - '0'); }
	return x * sgn;
}
}  
inline namespace Output {
char buf[BUF_SZ];
ll pos;
void flush_out() {
	fwrite(buf, 1, pos, stdout);
	pos = 0;
}
void write_char(char c) {
	if (pos == BUF_SZ) { flush_out(); }
	buf[pos++] = c;
}
void write_int(ll x) {
	static char num_buf[100];
	if (x < 0) {
		write_char('-');
		x *= -1;
	}
	ll len = 0;
	for (; x >= 10; x /= 10) { num_buf[len++] = (char)('0' + (x % 10)); }
	write_char((char)('0' + x));
	while (len) { write_char(num_buf[--len]); }
	write_char('\n');
}
void init_output() { assert(atexit(flush_out) == 0); }
} 
const int MAXN = 3e5 + 25;
const int ORIGIN = 300000;
int n, a[MAXN], q, n1;
int freq[MAXN], freq2[MAXN];
inline ll sq (ll x) {
	return ((x * (x + 1)) >> 1ll);
}
int main () {
	init_output();
	n = read_int(), q = read_int();
	for (int i = 1; i <= n; i++) a[i] = read_int();
	while (q--) {
		memset(freq, 0, sizeof(freq));
		memset(freq2, 0, sizeof(freq2));
		int l = read_int(), r = read_int();
		ll o = r - l + 1;
		n1 = 0;
		for (int i = l; i <= r; i++) {
			if (freq[a[i]]) freq2[freq[a[i]]]--;
			else n1++;
			freq2[++freq[a[i]]]++;
		}
		int c = 0;
		ll ans = 0;
		ll p = 0, q = 0;
		for (int i = 1; i <= ORIGIN; i++) {
			ll j = freq2[i];
			for (int l = 1; l <= j; l++) {
				c ^= 1;
				if (c) {
					ans += sq(p) + sq(o - p - i); p += i;
				} else {
					ans += sq(q) + sq(o - q - i); q += i;
				}
			}
		}
		write_int(n1 * sq(o) - ans);
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2904 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 1 ms 2648 KB Output is correct
10 Correct 1 ms 2648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 2 ms 3164 KB Output is correct
5 Correct 3 ms 3420 KB Output is correct
6 Correct 5 ms 3932 KB Output is correct
7 Correct 4 ms 3932 KB Output is correct
8 Correct 4 ms 3932 KB Output is correct
9 Correct 4 ms 3932 KB Output is correct
10 Correct 4 ms 3932 KB Output is correct
11 Correct 5 ms 3932 KB Output is correct
12 Correct 4 ms 3932 KB Output is correct
13 Correct 4 ms 3932 KB Output is correct
14 Correct 4 ms 3932 KB Output is correct
15 Correct 5 ms 3932 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 2 ms 3164 KB Output is correct
5 Correct 3 ms 3420 KB Output is correct
6 Correct 5 ms 3932 KB Output is correct
7 Correct 4 ms 3932 KB Output is correct
8 Correct 4 ms 3932 KB Output is correct
9 Correct 4 ms 3932 KB Output is correct
10 Correct 4 ms 3932 KB Output is correct
11 Correct 5 ms 3932 KB Output is correct
12 Correct 4 ms 3932 KB Output is correct
13 Correct 4 ms 3932 KB Output is correct
14 Correct 4 ms 3932 KB Output is correct
15 Correct 5 ms 3932 KB Output is correct
16 Correct 1 ms 2652 KB Output is correct
17 Correct 1 ms 2652 KB Output is correct
18 Correct 1 ms 2652 KB Output is correct
19 Correct 3 ms 3164 KB Output is correct
20 Correct 4 ms 3420 KB Output is correct
21 Correct 5 ms 3932 KB Output is correct
22 Correct 5 ms 3932 KB Output is correct
23 Correct 5 ms 3932 KB Output is correct
24 Correct 5 ms 3992 KB Output is correct
25 Correct 5 ms 3928 KB Output is correct
26 Correct 6 ms 3848 KB Output is correct
27 Correct 5 ms 3932 KB Output is correct
28 Correct 5 ms 3932 KB Output is correct
29 Correct 5 ms 3904 KB Output is correct
30 Correct 5 ms 3932 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 2 ms 3164 KB Output is correct
5 Correct 3 ms 3420 KB Output is correct
6 Correct 5 ms 3932 KB Output is correct
7 Correct 4 ms 3932 KB Output is correct
8 Correct 4 ms 3932 KB Output is correct
9 Correct 4 ms 3932 KB Output is correct
10 Correct 4 ms 3932 KB Output is correct
11 Correct 5 ms 3932 KB Output is correct
12 Correct 4 ms 3932 KB Output is correct
13 Correct 4 ms 3932 KB Output is correct
14 Correct 4 ms 3932 KB Output is correct
15 Correct 5 ms 3932 KB Output is correct
16 Correct 1 ms 2652 KB Output is correct
17 Correct 1 ms 2652 KB Output is correct
18 Correct 1 ms 2652 KB Output is correct
19 Correct 3 ms 3164 KB Output is correct
20 Correct 4 ms 3420 KB Output is correct
21 Correct 5 ms 3932 KB Output is correct
22 Correct 5 ms 3932 KB Output is correct
23 Correct 5 ms 3932 KB Output is correct
24 Correct 5 ms 3992 KB Output is correct
25 Correct 5 ms 3928 KB Output is correct
26 Correct 6 ms 3848 KB Output is correct
27 Correct 5 ms 3932 KB Output is correct
28 Correct 5 ms 3932 KB Output is correct
29 Correct 5 ms 3904 KB Output is correct
30 Correct 5 ms 3932 KB Output is correct
31 Correct 1 ms 2652 KB Output is correct
32 Correct 1 ms 2652 KB Output is correct
33 Correct 1 ms 2652 KB Output is correct
34 Correct 1 ms 2652 KB Output is correct
35 Correct 1 ms 2652 KB Output is correct
36 Correct 1 ms 2652 KB Output is correct
37 Correct 2 ms 2908 KB Output is correct
38 Correct 2 ms 2908 KB Output is correct
39 Correct 2 ms 3164 KB Output is correct
40 Correct 5 ms 3420 KB Output is correct
41 Correct 5 ms 3932 KB Output is correct
42 Correct 5 ms 3932 KB Output is correct
43 Correct 5 ms 3988 KB Output is correct
44 Correct 5 ms 4128 KB Output is correct
45 Correct 6 ms 3932 KB Output is correct
46 Correct 7 ms 3932 KB Output is correct
47 Correct 5 ms 3932 KB Output is correct
48 Correct 5 ms 3932 KB Output is correct
49 Correct 5 ms 3932 KB Output is correct
50 Correct 5 ms 3932 KB Output is correct
51 Correct 5 ms 3868 KB Output is correct
52 Correct 6 ms 3932 KB Output is correct
53 Correct 5 ms 3932 KB Output is correct
54 Correct 6 ms 3968 KB Output is correct
55 Correct 5 ms 3928 KB Output is correct
56 Correct 5 ms 3996 KB Output is correct
57 Correct 5 ms 3932 KB Output is correct
58 Correct 5 ms 3776 KB Output is correct
59 Correct 5 ms 3932 KB Output is correct
60 Correct 5 ms 3932 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2904 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 1 ms 2648 KB Output is correct
10 Correct 1 ms 2648 KB Output is correct
11 Correct 1 ms 2652 KB Output is correct
12 Correct 1 ms 2652 KB Output is correct
13 Correct 1 ms 2652 KB Output is correct
14 Correct 2 ms 3164 KB Output is correct
15 Correct 3 ms 3420 KB Output is correct
16 Correct 5 ms 3932 KB Output is correct
17 Correct 4 ms 3932 KB Output is correct
18 Correct 4 ms 3932 KB Output is correct
19 Correct 4 ms 3932 KB Output is correct
20 Correct 4 ms 3932 KB Output is correct
21 Correct 5 ms 3932 KB Output is correct
22 Correct 4 ms 3932 KB Output is correct
23 Correct 4 ms 3932 KB Output is correct
24 Correct 4 ms 3932 KB Output is correct
25 Correct 5 ms 3932 KB Output is correct
26 Correct 1 ms 2652 KB Output is correct
27 Correct 1 ms 2652 KB Output is correct
28 Correct 1 ms 2652 KB Output is correct
29 Correct 3 ms 3164 KB Output is correct
30 Correct 4 ms 3420 KB Output is correct
31 Correct 5 ms 3932 KB Output is correct
32 Correct 5 ms 3932 KB Output is correct
33 Correct 5 ms 3932 KB Output is correct
34 Correct 5 ms 3992 KB Output is correct
35 Correct 5 ms 3928 KB Output is correct
36 Correct 6 ms 3848 KB Output is correct
37 Correct 5 ms 3932 KB Output is correct
38 Correct 5 ms 3932 KB Output is correct
39 Correct 5 ms 3904 KB Output is correct
40 Correct 5 ms 3932 KB Output is correct
41 Correct 1 ms 2652 KB Output is correct
42 Correct 1 ms 2652 KB Output is correct
43 Correct 1 ms 2652 KB Output is correct
44 Correct 1 ms 2652 KB Output is correct
45 Correct 1 ms 2652 KB Output is correct
46 Correct 1 ms 2652 KB Output is correct
47 Correct 2 ms 2908 KB Output is correct
48 Correct 2 ms 2908 KB Output is correct
49 Correct 2 ms 3164 KB Output is correct
50 Correct 5 ms 3420 KB Output is correct
51 Correct 5 ms 3932 KB Output is correct
52 Correct 5 ms 3932 KB Output is correct
53 Correct 5 ms 3988 KB Output is correct
54 Correct 5 ms 4128 KB Output is correct
55 Correct 6 ms 3932 KB Output is correct
56 Correct 7 ms 3932 KB Output is correct
57 Correct 5 ms 3932 KB Output is correct
58 Correct 5 ms 3932 KB Output is correct
59 Correct 5 ms 3932 KB Output is correct
60 Correct 5 ms 3932 KB Output is correct
61 Correct 5 ms 3868 KB Output is correct
62 Correct 6 ms 3932 KB Output is correct
63 Correct 5 ms 3932 KB Output is correct
64 Correct 6 ms 3968 KB Output is correct
65 Correct 5 ms 3928 KB Output is correct
66 Correct 5 ms 3996 KB Output is correct
67 Correct 5 ms 3932 KB Output is correct
68 Correct 5 ms 3776 KB Output is correct
69 Correct 5 ms 3932 KB Output is correct
70 Correct 5 ms 3932 KB Output is correct
71 Correct 3 ms 2908 KB Output is correct
72 Correct 2 ms 2904 KB Output is correct
73 Correct 2 ms 2908 KB Output is correct
74 Correct 2 ms 2908 KB Output is correct
75 Correct 2 ms 2908 KB Output is correct
76 Correct 2 ms 3164 KB Output is correct
77 Correct 3 ms 3164 KB Output is correct
78 Correct 3 ms 3164 KB Output is correct
79 Correct 3 ms 3164 KB Output is correct
80 Correct 3 ms 3164 KB Output is correct
81 Correct 4 ms 3420 KB Output is correct
82 Correct 4 ms 3420 KB Output is correct
83 Correct 4 ms 3420 KB Output is correct
84 Correct 4 ms 3364 KB Output is correct
85 Correct 4 ms 3420 KB Output is correct
86 Correct 6 ms 3420 KB Output is correct
87 Correct 5 ms 3492 KB Output is correct
88 Correct 6 ms 3420 KB Output is correct
89 Correct 6 ms 3568 KB Output is correct
90 Correct 5 ms 3416 KB Output is correct
91 Correct 9 ms 3932 KB Output is correct
92 Correct 8 ms 3932 KB Output is correct
93 Correct 8 ms 3920 KB Output is correct
94 Correct 8 ms 3932 KB Output is correct
95 Correct 8 ms 3932 KB Output is correct
96 Correct 10 ms 3984 KB Output is correct
97 Correct 10 ms 3932 KB Output is correct
98 Correct 10 ms 3928 KB Output is correct
99 Correct 9 ms 3932 KB Output is correct
100 Correct 9 ms 3932 KB Output is correct
101 Correct 10 ms 3928 KB Output is correct
102 Correct 9 ms 3932 KB Output is correct
103 Correct 10 ms 3932 KB Output is correct
104 Correct 9 ms 3932 KB Output is correct
105 Correct 9 ms 3932 KB Output is correct
106 Correct 9 ms 3932 KB Output is correct
107 Correct 9 ms 3932 KB Output is correct
108 Correct 9 ms 3864 KB Output is correct
109 Correct 9 ms 3932 KB Output is correct
110 Correct 9 ms 3932 KB Output is correct
111 Correct 10 ms 3928 KB Output is correct
112 Correct 9 ms 3932 KB Output is correct
113 Correct 9 ms 3932 KB Output is correct
114 Correct 9 ms 3932 KB Output is correct
115 Correct 9 ms 3932 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2904 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 1 ms 2648 KB Output is correct
10 Correct 1 ms 2648 KB Output is correct
11 Correct 1 ms 2652 KB Output is correct
12 Correct 1 ms 2652 KB Output is correct
13 Correct 1 ms 2652 KB Output is correct
14 Correct 2 ms 3164 KB Output is correct
15 Correct 3 ms 3420 KB Output is correct
16 Correct 5 ms 3932 KB Output is correct
17 Correct 4 ms 3932 KB Output is correct
18 Correct 4 ms 3932 KB Output is correct
19 Correct 4 ms 3932 KB Output is correct
20 Correct 4 ms 3932 KB Output is correct
21 Correct 5 ms 3932 KB Output is correct
22 Correct 4 ms 3932 KB Output is correct
23 Correct 4 ms 3932 KB Output is correct
24 Correct 4 ms 3932 KB Output is correct
25 Correct 5 ms 3932 KB Output is correct
26 Correct 1 ms 2652 KB Output is correct
27 Correct 1 ms 2652 KB Output is correct
28 Correct 1 ms 2652 KB Output is correct
29 Correct 3 ms 3164 KB Output is correct
30 Correct 4 ms 3420 KB Output is correct
31 Correct 5 ms 3932 KB Output is correct
32 Correct 5 ms 3932 KB Output is correct
33 Correct 5 ms 3932 KB Output is correct
34 Correct 5 ms 3992 KB Output is correct
35 Correct 5 ms 3928 KB Output is correct
36 Correct 6 ms 3848 KB Output is correct
37 Correct 5 ms 3932 KB Output is correct
38 Correct 5 ms 3932 KB Output is correct
39 Correct 5 ms 3904 KB Output is correct
40 Correct 5 ms 3932 KB Output is correct
41 Correct 1 ms 2652 KB Output is correct
42 Correct 1 ms 2652 KB Output is correct
43 Correct 1 ms 2652 KB Output is correct
44 Correct 1 ms 2652 KB Output is correct
45 Correct 1 ms 2652 KB Output is correct
46 Correct 1 ms 2652 KB Output is correct
47 Correct 2 ms 2908 KB Output is correct
48 Correct 2 ms 2908 KB Output is correct
49 Correct 2 ms 3164 KB Output is correct
50 Correct 5 ms 3420 KB Output is correct
51 Correct 5 ms 3932 KB Output is correct
52 Correct 5 ms 3932 KB Output is correct
53 Correct 5 ms 3988 KB Output is correct
54 Correct 5 ms 4128 KB Output is correct
55 Correct 6 ms 3932 KB Output is correct
56 Correct 7 ms 3932 KB Output is correct
57 Correct 5 ms 3932 KB Output is correct
58 Correct 5 ms 3932 KB Output is correct
59 Correct 5 ms 3932 KB Output is correct
60 Correct 5 ms 3932 KB Output is correct
61 Correct 5 ms 3868 KB Output is correct
62 Correct 6 ms 3932 KB Output is correct
63 Correct 5 ms 3932 KB Output is correct
64 Correct 6 ms 3968 KB Output is correct
65 Correct 5 ms 3928 KB Output is correct
66 Correct 5 ms 3996 KB Output is correct
67 Correct 5 ms 3932 KB Output is correct
68 Correct 5 ms 3776 KB Output is correct
69 Correct 5 ms 3932 KB Output is correct
70 Correct 5 ms 3932 KB Output is correct
71 Correct 3 ms 2908 KB Output is correct
72 Correct 2 ms 2904 KB Output is correct
73 Correct 2 ms 2908 KB Output is correct
74 Correct 2 ms 2908 KB Output is correct
75 Correct 2 ms 2908 KB Output is correct
76 Correct 2 ms 3164 KB Output is correct
77 Correct 3 ms 3164 KB Output is correct
78 Correct 3 ms 3164 KB Output is correct
79 Correct 3 ms 3164 KB Output is correct
80 Correct 3 ms 3164 KB Output is correct
81 Correct 4 ms 3420 KB Output is correct
82 Correct 4 ms 3420 KB Output is correct
83 Correct 4 ms 3420 KB Output is correct
84 Correct 4 ms 3364 KB Output is correct
85 Correct 4 ms 3420 KB Output is correct
86 Correct 6 ms 3420 KB Output is correct
87 Correct 5 ms 3492 KB Output is correct
88 Correct 6 ms 3420 KB Output is correct
89 Correct 6 ms 3568 KB Output is correct
90 Correct 5 ms 3416 KB Output is correct
91 Correct 9 ms 3932 KB Output is correct
92 Correct 8 ms 3932 KB Output is correct
93 Correct 8 ms 3920 KB Output is correct
94 Correct 8 ms 3932 KB Output is correct
95 Correct 8 ms 3932 KB Output is correct
96 Correct 10 ms 3984 KB Output is correct
97 Correct 10 ms 3932 KB Output is correct
98 Correct 10 ms 3928 KB Output is correct
99 Correct 9 ms 3932 KB Output is correct
100 Correct 9 ms 3932 KB Output is correct
101 Correct 10 ms 3928 KB Output is correct
102 Correct 9 ms 3932 KB Output is correct
103 Correct 10 ms 3932 KB Output is correct
104 Correct 9 ms 3932 KB Output is correct
105 Correct 9 ms 3932 KB Output is correct
106 Correct 9 ms 3932 KB Output is correct
107 Correct 9 ms 3932 KB Output is correct
108 Correct 9 ms 3864 KB Output is correct
109 Correct 9 ms 3932 KB Output is correct
110 Correct 9 ms 3932 KB Output is correct
111 Correct 10 ms 3928 KB Output is correct
112 Correct 9 ms 3932 KB Output is correct
113 Correct 9 ms 3932 KB Output is correct
114 Correct 9 ms 3932 KB Output is correct
115 Correct 9 ms 3932 KB Output is correct
116 Execution timed out 7047 ms 3036 KB Time limit exceeded
117 Halted 0 ms 0 KB -