답안 #826727

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
826727 2023-08-15T23:38:18 Z NK_ Diversity (CEOI21_diversity) C++17
64 / 100
2390 ms 44564 KB
// Success consists of going from failure to failure without loss of enthusiasm
#include <bits/stdc++.h>
 
using namespace std;
 
#define nl '\n'
#define pb push_back 
#define mp make_pair
#define f first
#define s second
#define sz(x) int(x.size())
 
template<class T> using V = vector<T>;
using vi = V<int>;
using ll = long long;
using pi = pair<int, int>;
using vpi = V<pi>;
using vl = V<ll>;

int main() {
	cin.tie(0)->sync_with_stdio(0);
 	
	int N, Q; cin >> N >> Q;
	vi A(N); for(auto& x : A) cin >> x;
	assert(Q == 1);
	int l, r; cin >> l >> r;
	assert(l == 1 && r == N);

	map<int, int> F; for(auto& x : A) F[x]++;

	vpi B; for(auto& x : F) B.pb(mp(x.s, x.f));
	sort(begin(B), end(B));

	vpi L, R;
	for(int i = 0; i < sz(B); i += 2) L.pb(B[i]);
	for(int i = 1; i < sz(B); i += 2) R.pb(B[i]);
	reverse(begin(R), end(R));
	
	vpi ord; 
	for(auto& x : L) ord.pb(x);
	for(auto& x : R) ord.pb(x);

	map<int, int> ORD; for(int i = 0; i < sz(ord); i++) ORD[ord[i].s] = i;

	sort(begin(A), end(A), [&](int x, int y) {
		if (ORD[x] == ORD[y]) return x < y;
		return ORD[x] < ORD[y];
	});

	ll ans = 0;
	map<int, int> lst;
	for(int i = 0; i < N; i++) {
		int LST = (lst.find(A[i]) == lst.end() ? -1 : lst[A[i]]);
		ans += (i - LST) * 1LL * (N - i);
		lst[A[i]] = i;
	}
	cout << ans << nl;

	exit(0-0);
}				
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 23 ms 724 KB Output is correct
5 Correct 51 ms 1496 KB Output is correct
6 Correct 80 ms 2156 KB Output is correct
7 Correct 73 ms 2108 KB Output is correct
8 Correct 79 ms 2132 KB Output is correct
9 Correct 84 ms 2116 KB Output is correct
10 Correct 78 ms 2152 KB Output is correct
11 Correct 78 ms 2132 KB Output is correct
12 Correct 81 ms 2140 KB Output is correct
13 Correct 86 ms 2140 KB Output is correct
14 Correct 80 ms 2132 KB Output is correct
15 Correct 78 ms 2132 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 23 ms 724 KB Output is correct
5 Correct 51 ms 1496 KB Output is correct
6 Correct 80 ms 2156 KB Output is correct
7 Correct 73 ms 2108 KB Output is correct
8 Correct 79 ms 2132 KB Output is correct
9 Correct 84 ms 2116 KB Output is correct
10 Correct 78 ms 2152 KB Output is correct
11 Correct 78 ms 2132 KB Output is correct
12 Correct 81 ms 2140 KB Output is correct
13 Correct 86 ms 2140 KB Output is correct
14 Correct 80 ms 2132 KB Output is correct
15 Correct 78 ms 2132 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 3 ms 340 KB Output is correct
19 Correct 34 ms 980 KB Output is correct
20 Correct 70 ms 1624 KB Output is correct
21 Correct 108 ms 2320 KB Output is correct
22 Correct 106 ms 2260 KB Output is correct
23 Correct 105 ms 2292 KB Output is correct
24 Correct 101 ms 2272 KB Output is correct
25 Correct 104 ms 2268 KB Output is correct
26 Correct 111 ms 2268 KB Output is correct
27 Correct 107 ms 2272 KB Output is correct
28 Correct 104 ms 2240 KB Output is correct
29 Correct 118 ms 2252 KB Output is correct
30 Correct 111 ms 2248 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 23 ms 724 KB Output is correct
5 Correct 51 ms 1496 KB Output is correct
6 Correct 80 ms 2156 KB Output is correct
7 Correct 73 ms 2108 KB Output is correct
8 Correct 79 ms 2132 KB Output is correct
9 Correct 84 ms 2116 KB Output is correct
10 Correct 78 ms 2152 KB Output is correct
11 Correct 78 ms 2132 KB Output is correct
12 Correct 81 ms 2140 KB Output is correct
13 Correct 86 ms 2140 KB Output is correct
14 Correct 80 ms 2132 KB Output is correct
15 Correct 78 ms 2132 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 3 ms 340 KB Output is correct
19 Correct 34 ms 980 KB Output is correct
20 Correct 70 ms 1624 KB Output is correct
21 Correct 108 ms 2320 KB Output is correct
22 Correct 106 ms 2260 KB Output is correct
23 Correct 105 ms 2292 KB Output is correct
24 Correct 101 ms 2272 KB Output is correct
25 Correct 104 ms 2268 KB Output is correct
26 Correct 111 ms 2268 KB Output is correct
27 Correct 107 ms 2272 KB Output is correct
28 Correct 104 ms 2240 KB Output is correct
29 Correct 118 ms 2252 KB Output is correct
30 Correct 111 ms 2248 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 2 ms 340 KB Output is correct
34 Correct 6 ms 340 KB Output is correct
35 Correct 10 ms 428 KB Output is correct
36 Correct 16 ms 468 KB Output is correct
37 Correct 51 ms 752 KB Output is correct
38 Correct 66 ms 844 KB Output is correct
39 Correct 122 ms 1220 KB Output is correct
40 Correct 240 ms 1992 KB Output is correct
41 Correct 365 ms 2764 KB Output is correct
42 Correct 343 ms 2772 KB Output is correct
43 Correct 345 ms 2768 KB Output is correct
44 Correct 364 ms 2756 KB Output is correct
45 Correct 356 ms 2760 KB Output is correct
46 Correct 342 ms 2760 KB Output is correct
47 Correct 360 ms 2752 KB Output is correct
48 Correct 339 ms 2752 KB Output is correct
49 Correct 371 ms 2752 KB Output is correct
50 Correct 363 ms 2756 KB Output is correct
51 Correct 385 ms 2756 KB Output is correct
52 Correct 346 ms 2772 KB Output is correct
53 Correct 354 ms 2764 KB Output is correct
54 Correct 352 ms 2748 KB Output is correct
55 Correct 362 ms 2764 KB Output is correct
56 Correct 368 ms 2760 KB Output is correct
57 Correct 365 ms 2768 KB Output is correct
58 Correct 347 ms 2764 KB Output is correct
59 Correct 368 ms 2700 KB Output is correct
60 Correct 349 ms 2768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
14 Correct 23 ms 724 KB Output is correct
15 Correct 51 ms 1496 KB Output is correct
16 Correct 80 ms 2156 KB Output is correct
17 Correct 73 ms 2108 KB Output is correct
18 Correct 79 ms 2132 KB Output is correct
19 Correct 84 ms 2116 KB Output is correct
20 Correct 78 ms 2152 KB Output is correct
21 Correct 78 ms 2132 KB Output is correct
22 Correct 81 ms 2140 KB Output is correct
23 Correct 86 ms 2140 KB Output is correct
24 Correct 80 ms 2132 KB Output is correct
25 Correct 78 ms 2132 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 3 ms 340 KB Output is correct
29 Correct 34 ms 980 KB Output is correct
30 Correct 70 ms 1624 KB Output is correct
31 Correct 108 ms 2320 KB Output is correct
32 Correct 106 ms 2260 KB Output is correct
33 Correct 105 ms 2292 KB Output is correct
34 Correct 101 ms 2272 KB Output is correct
35 Correct 104 ms 2268 KB Output is correct
36 Correct 111 ms 2268 KB Output is correct
37 Correct 107 ms 2272 KB Output is correct
38 Correct 104 ms 2240 KB Output is correct
39 Correct 118 ms 2252 KB Output is correct
40 Correct 111 ms 2248 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 2 ms 340 KB Output is correct
44 Correct 6 ms 340 KB Output is correct
45 Correct 10 ms 428 KB Output is correct
46 Correct 16 ms 468 KB Output is correct
47 Correct 51 ms 752 KB Output is correct
48 Correct 66 ms 844 KB Output is correct
49 Correct 122 ms 1220 KB Output is correct
50 Correct 240 ms 1992 KB Output is correct
51 Correct 365 ms 2764 KB Output is correct
52 Correct 343 ms 2772 KB Output is correct
53 Correct 345 ms 2768 KB Output is correct
54 Correct 364 ms 2756 KB Output is correct
55 Correct 356 ms 2760 KB Output is correct
56 Correct 342 ms 2760 KB Output is correct
57 Correct 360 ms 2752 KB Output is correct
58 Correct 339 ms 2752 KB Output is correct
59 Correct 371 ms 2752 KB Output is correct
60 Correct 363 ms 2756 KB Output is correct
61 Correct 385 ms 2756 KB Output is correct
62 Correct 346 ms 2772 KB Output is correct
63 Correct 354 ms 2764 KB Output is correct
64 Correct 352 ms 2748 KB Output is correct
65 Correct 362 ms 2764 KB Output is correct
66 Correct 368 ms 2760 KB Output is correct
67 Correct 365 ms 2768 KB Output is correct
68 Correct 347 ms 2764 KB Output is correct
69 Correct 368 ms 2700 KB Output is correct
70 Correct 349 ms 2768 KB Output is correct
71 Correct 80 ms 972 KB Output is correct
72 Correct 81 ms 980 KB Output is correct
73 Correct 85 ms 980 KB Output is correct
74 Correct 81 ms 980 KB Output is correct
75 Correct 82 ms 972 KB Output is correct
76 Correct 211 ms 1920 KB Output is correct
77 Correct 211 ms 1928 KB Output is correct
78 Correct 209 ms 1976 KB Output is correct
79 Correct 214 ms 1912 KB Output is correct
80 Correct 211 ms 1920 KB Output is correct
81 Correct 513 ms 3660 KB Output is correct
82 Correct 497 ms 3648 KB Output is correct
83 Correct 517 ms 3660 KB Output is correct
84 Correct 502 ms 3692 KB Output is correct
85 Correct 500 ms 3656 KB Output is correct
86 Correct 633 ms 5424 KB Output is correct
87 Correct 602 ms 5464 KB Output is correct
88 Correct 641 ms 5424 KB Output is correct
89 Correct 612 ms 5428 KB Output is correct
90 Correct 636 ms 5420 KB Output is correct
91 Correct 1459 ms 19592 KB Output is correct
92 Correct 1486 ms 19592 KB Output is correct
93 Correct 1460 ms 19592 KB Output is correct
94 Correct 1467 ms 19648 KB Output is correct
95 Correct 1446 ms 19716 KB Output is correct
96 Correct 1994 ms 36248 KB Output is correct
97 Correct 1945 ms 36224 KB Output is correct
98 Correct 1906 ms 36192 KB Output is correct
99 Correct 2016 ms 36328 KB Output is correct
100 Correct 1975 ms 36232 KB Output is correct
101 Correct 1934 ms 36220 KB Output is correct
102 Correct 1980 ms 36196 KB Output is correct
103 Correct 1988 ms 36220 KB Output is correct
104 Correct 1909 ms 36228 KB Output is correct
105 Correct 2000 ms 36232 KB Output is correct
106 Correct 2185 ms 44512 KB Output is correct
107 Correct 2216 ms 44440 KB Output is correct
108 Correct 2390 ms 44564 KB Output is correct
109 Correct 2287 ms 44436 KB Output is correct
110 Correct 2339 ms 44436 KB Output is correct
111 Correct 2277 ms 44428 KB Output is correct
112 Correct 2291 ms 44440 KB Output is correct
113 Correct 2265 ms 44440 KB Output is correct
114 Correct 2253 ms 44440 KB Output is correct
115 Correct 2307 ms 44440 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
14 Correct 23 ms 724 KB Output is correct
15 Correct 51 ms 1496 KB Output is correct
16 Correct 80 ms 2156 KB Output is correct
17 Correct 73 ms 2108 KB Output is correct
18 Correct 79 ms 2132 KB Output is correct
19 Correct 84 ms 2116 KB Output is correct
20 Correct 78 ms 2152 KB Output is correct
21 Correct 78 ms 2132 KB Output is correct
22 Correct 81 ms 2140 KB Output is correct
23 Correct 86 ms 2140 KB Output is correct
24 Correct 80 ms 2132 KB Output is correct
25 Correct 78 ms 2132 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 3 ms 340 KB Output is correct
29 Correct 34 ms 980 KB Output is correct
30 Correct 70 ms 1624 KB Output is correct
31 Correct 108 ms 2320 KB Output is correct
32 Correct 106 ms 2260 KB Output is correct
33 Correct 105 ms 2292 KB Output is correct
34 Correct 101 ms 2272 KB Output is correct
35 Correct 104 ms 2268 KB Output is correct
36 Correct 111 ms 2268 KB Output is correct
37 Correct 107 ms 2272 KB Output is correct
38 Correct 104 ms 2240 KB Output is correct
39 Correct 118 ms 2252 KB Output is correct
40 Correct 111 ms 2248 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 2 ms 340 KB Output is correct
44 Correct 6 ms 340 KB Output is correct
45 Correct 10 ms 428 KB Output is correct
46 Correct 16 ms 468 KB Output is correct
47 Correct 51 ms 752 KB Output is correct
48 Correct 66 ms 844 KB Output is correct
49 Correct 122 ms 1220 KB Output is correct
50 Correct 240 ms 1992 KB Output is correct
51 Correct 365 ms 2764 KB Output is correct
52 Correct 343 ms 2772 KB Output is correct
53 Correct 345 ms 2768 KB Output is correct
54 Correct 364 ms 2756 KB Output is correct
55 Correct 356 ms 2760 KB Output is correct
56 Correct 342 ms 2760 KB Output is correct
57 Correct 360 ms 2752 KB Output is correct
58 Correct 339 ms 2752 KB Output is correct
59 Correct 371 ms 2752 KB Output is correct
60 Correct 363 ms 2756 KB Output is correct
61 Correct 385 ms 2756 KB Output is correct
62 Correct 346 ms 2772 KB Output is correct
63 Correct 354 ms 2764 KB Output is correct
64 Correct 352 ms 2748 KB Output is correct
65 Correct 362 ms 2764 KB Output is correct
66 Correct 368 ms 2760 KB Output is correct
67 Correct 365 ms 2768 KB Output is correct
68 Correct 347 ms 2764 KB Output is correct
69 Correct 368 ms 2700 KB Output is correct
70 Correct 349 ms 2768 KB Output is correct
71 Correct 80 ms 972 KB Output is correct
72 Correct 81 ms 980 KB Output is correct
73 Correct 85 ms 980 KB Output is correct
74 Correct 81 ms 980 KB Output is correct
75 Correct 82 ms 972 KB Output is correct
76 Correct 211 ms 1920 KB Output is correct
77 Correct 211 ms 1928 KB Output is correct
78 Correct 209 ms 1976 KB Output is correct
79 Correct 214 ms 1912 KB Output is correct
80 Correct 211 ms 1920 KB Output is correct
81 Correct 513 ms 3660 KB Output is correct
82 Correct 497 ms 3648 KB Output is correct
83 Correct 517 ms 3660 KB Output is correct
84 Correct 502 ms 3692 KB Output is correct
85 Correct 500 ms 3656 KB Output is correct
86 Correct 633 ms 5424 KB Output is correct
87 Correct 602 ms 5464 KB Output is correct
88 Correct 641 ms 5424 KB Output is correct
89 Correct 612 ms 5428 KB Output is correct
90 Correct 636 ms 5420 KB Output is correct
91 Correct 1459 ms 19592 KB Output is correct
92 Correct 1486 ms 19592 KB Output is correct
93 Correct 1460 ms 19592 KB Output is correct
94 Correct 1467 ms 19648 KB Output is correct
95 Correct 1446 ms 19716 KB Output is correct
96 Correct 1994 ms 36248 KB Output is correct
97 Correct 1945 ms 36224 KB Output is correct
98 Correct 1906 ms 36192 KB Output is correct
99 Correct 2016 ms 36328 KB Output is correct
100 Correct 1975 ms 36232 KB Output is correct
101 Correct 1934 ms 36220 KB Output is correct
102 Correct 1980 ms 36196 KB Output is correct
103 Correct 1988 ms 36220 KB Output is correct
104 Correct 1909 ms 36228 KB Output is correct
105 Correct 2000 ms 36232 KB Output is correct
106 Correct 2185 ms 44512 KB Output is correct
107 Correct 2216 ms 44440 KB Output is correct
108 Correct 2390 ms 44564 KB Output is correct
109 Correct 2287 ms 44436 KB Output is correct
110 Correct 2339 ms 44436 KB Output is correct
111 Correct 2277 ms 44428 KB Output is correct
112 Correct 2291 ms 44440 KB Output is correct
113 Correct 2265 ms 44440 KB Output is correct
114 Correct 2253 ms 44440 KB Output is correct
115 Correct 2307 ms 44440 KB Output is correct
116 Runtime error 1 ms 596 KB Execution killed with signal 6
117 Halted 0 ms 0 KB -