답안 #1003944

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1003944 2024-06-20T20:40:13 Z vjudge1 Ekoeko (COCI21_ekoeko) C++17
110 / 110
16 ms 3356 KB
#include <bits/stdc++.h>

using namespace std;
using lli = long long;

const int MAXN = 2e5 + 10;

int bit[MAXN];

void add(int idx, int x, int n) {
	for (; idx < n; idx = idx | (idx + 1))
		bit[idx] += x;
}

int pref(int idx) {
	int sum = 0;
	for (; idx >= 0; idx = (idx & (idx + 1)) - 1)
		sum += bit[idx];

	return sum;
}

int sum(int l, int r) { return pref(r) - pref(l-1); }

int main() {
	int n;
	cin >> n;

	n *= 2;

	string s;
	cin >> s;

	vector<vector<int>> cnt(26);
	for (int i = 0; i < n; ++i)
		cnt[s[i] - 'a'].push_back(i);

	vector<int> perm(n);
	int atual = 0; string final;
	vector<int> cnt2(26);
	for (int i = 0; i < n; ++i) {
		int c = s[i] - 'a';
		if (cnt2[c] < cnt[c].size()/2) {
			++cnt2[c];
			perm[i] = atual++;
			final.push_back(s[i]);
		}
	}

	for (char c: final)
		perm[cnt[c - 'a'][cnt2[c - 'a']++]] = atual++;

	lli ans = 0;
	for (int i = 0; i < n; ++i) {
		ans += sum(perm[i], n);
		add(perm[i], 1, n);
	}

	cout << ans << "\n";
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:43:15: warning: comparison of integer expressions of different signedness: '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |   if (cnt2[c] < cnt[c].size()/2) {
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 4 ms 1428 KB Output is correct
3 Correct 9 ms 2276 KB Output is correct
4 Correct 14 ms 3044 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 4 ms 1428 KB Output is correct
3 Correct 9 ms 2276 KB Output is correct
4 Correct 14 ms 3044 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 4 ms 1428 KB Output is correct
3 Correct 9 ms 2276 KB Output is correct
4 Correct 14 ms 3044 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 13 ms 3252 KB Output is correct
7 Correct 9 ms 3308 KB Output is correct
8 Correct 16 ms 3308 KB Output is correct
9 Correct 10 ms 3308 KB Output is correct
10 Correct 15 ms 3288 KB Output is correct
11 Correct 11 ms 3020 KB Output is correct
12 Correct 9 ms 3048 KB Output is correct
13 Correct 10 ms 3040 KB Output is correct
14 Correct 9 ms 3052 KB Output is correct
15 Correct 14 ms 3052 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 4 ms 1428 KB Output is correct
3 Correct 9 ms 2276 KB Output is correct
4 Correct 14 ms 3044 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 13 ms 3252 KB Output is correct
11 Correct 9 ms 3308 KB Output is correct
12 Correct 16 ms 3308 KB Output is correct
13 Correct 10 ms 3308 KB Output is correct
14 Correct 15 ms 3288 KB Output is correct
15 Correct 11 ms 3020 KB Output is correct
16 Correct 9 ms 3048 KB Output is correct
17 Correct 10 ms 3040 KB Output is correct
18 Correct 9 ms 3052 KB Output is correct
19 Correct 14 ms 3052 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 14 ms 3356 KB Output is correct
33 Correct 10 ms 3308 KB Output is correct
34 Correct 16 ms 3056 KB Output is correct
35 Correct 14 ms 3052 KB Output is correct
36 Correct 15 ms 3048 KB Output is correct
37 Correct 14 ms 3196 KB Output is correct
38 Correct 10 ms 3052 KB Output is correct
39 Correct 10 ms 3052 KB Output is correct
40 Correct 10 ms 3052 KB Output is correct
41 Correct 9 ms 3052 KB Output is correct