# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
512630 |
2022-01-16T14:42:56 Z |
phathnv |
Ekoeko (COCI21_ekoeko) |
C++11 |
|
22 ms |
3336 KB |
#include <bits/stdc++.h>
using namespace std;
struct BIT {
int n;
vector<int> d;
void init(int _n) {
n = _n;
d.assign(n + 1, 0);
}
void update(int x, int val) {
for (; x <= n; x += x & -x) {
d[x] += val;
}
}
int get(int x) {
int res = 0;
for (;x > 0; x -= x & -x) {
res += d[x];
}
return res;
}
} bit;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
string s;
cin >> n >> s;
vector<int> pos[26], newPos[26];
for (int i = 0; i < 2 * n; ++i) {
pos[s[i] - 'a'].push_back(i + 1);
}
vector<array<int, 2>> firstHalf;
for (int i = 0; i < 26; ++i) {
for (int j = 0; j < (int) pos[i].size() / 2; ++j) {
firstHalf.push_back({pos[i][j], i});
}
}
sort(firstHalf.begin(), firstHalf.end());
for (int i = 0; i < 26; ++i) {
reverse(pos[i].begin(), pos[i].end());
}
bit.init(2 * n);
long long ans = 0;
for (int t = 0; t < 2; ++t) {
for (auto x : firstHalf) {
int p = pos[x[1]].back();
//cerr << p << endl;
pos[x[1]].pop_back();
ans += bit.get(2 * n + 1 - p);
bit.update(2 * n + 1 - p, 1);
}
}
cout << ans << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
5 ms |
1332 KB |
Output is correct |
3 |
Correct |
9 ms |
2184 KB |
Output is correct |
4 |
Correct |
15 ms |
3032 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
5 ms |
1332 KB |
Output is correct |
3 |
Correct |
9 ms |
2184 KB |
Output is correct |
4 |
Correct |
15 ms |
3032 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
288 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
5 ms |
1332 KB |
Output is correct |
3 |
Correct |
9 ms |
2184 KB |
Output is correct |
4 |
Correct |
15 ms |
3032 KB |
Output is correct |
5 |
Correct |
0 ms |
296 KB |
Output is correct |
6 |
Correct |
18 ms |
3216 KB |
Output is correct |
7 |
Correct |
16 ms |
3084 KB |
Output is correct |
8 |
Correct |
16 ms |
3248 KB |
Output is correct |
9 |
Correct |
18 ms |
3120 KB |
Output is correct |
10 |
Correct |
18 ms |
3120 KB |
Output is correct |
11 |
Correct |
16 ms |
3012 KB |
Output is correct |
12 |
Correct |
16 ms |
3104 KB |
Output is correct |
13 |
Correct |
15 ms |
3172 KB |
Output is correct |
14 |
Correct |
15 ms |
3044 KB |
Output is correct |
15 |
Correct |
16 ms |
3052 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
316 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
352 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
5 ms |
1332 KB |
Output is correct |
3 |
Correct |
9 ms |
2184 KB |
Output is correct |
4 |
Correct |
15 ms |
3032 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
288 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
296 KB |
Output is correct |
10 |
Correct |
18 ms |
3216 KB |
Output is correct |
11 |
Correct |
16 ms |
3084 KB |
Output is correct |
12 |
Correct |
16 ms |
3248 KB |
Output is correct |
13 |
Correct |
18 ms |
3120 KB |
Output is correct |
14 |
Correct |
18 ms |
3120 KB |
Output is correct |
15 |
Correct |
16 ms |
3012 KB |
Output is correct |
16 |
Correct |
16 ms |
3104 KB |
Output is correct |
17 |
Correct |
15 ms |
3172 KB |
Output is correct |
18 |
Correct |
15 ms |
3044 KB |
Output is correct |
19 |
Correct |
16 ms |
3052 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
1 ms |
316 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
29 |
Correct |
1 ms |
332 KB |
Output is correct |
30 |
Correct |
1 ms |
352 KB |
Output is correct |
31 |
Correct |
0 ms |
308 KB |
Output is correct |
32 |
Correct |
16 ms |
3336 KB |
Output is correct |
33 |
Correct |
17 ms |
3292 KB |
Output is correct |
34 |
Correct |
18 ms |
3216 KB |
Output is correct |
35 |
Correct |
22 ms |
3148 KB |
Output is correct |
36 |
Correct |
20 ms |
3212 KB |
Output is correct |
37 |
Correct |
16 ms |
3256 KB |
Output is correct |
38 |
Correct |
15 ms |
3184 KB |
Output is correct |
39 |
Correct |
15 ms |
3184 KB |
Output is correct |
40 |
Correct |
15 ms |
3056 KB |
Output is correct |
41 |
Correct |
21 ms |
3064 KB |
Output is correct |