# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
742201 |
2023-05-15T18:50:21 Z |
SamAnd |
Ekoeko (COCI21_ekoeko) |
C++17 |
|
13 ms |
3428 KB |
#include <bits/stdc++.h>
using namespace std;
#define m_p make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
typedef long long ll;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
mt19937 rnf(2106);
const int N = 200005;
int n;
char a[N];
int m;
char b[N];
int u[N];
int t[N];
void ubd(int x, int y)
{
while (x <= n * 2)
{
t[x] += y;
x += (x & (-x));
}
}
int qry(int x)
{
int ans = 0;
while (x)
{
ans += t[x];
x -= (x & (-x));
}
return ans;
}
void solv()
{
cin >> n;
cin >> (a + 1);
int q[26] = {};
for (int i = 1; i <= n * 2; ++i)
{
q[a[i] - 'a']++;
}
for (int i = 0; i < 26; ++i)
q[i] /= 2;
for (int i = 1; i <= n * 2; ++i)
{
if (q[a[i] - 'a'])
{
b[++m] = a[i];
--q[a[i] - 'a'];
}
}
for (int i = n + 1; i <= n * 2; ++i)
{
b[i] = b[i - n];
}
vector<int> v[26];
for (int i = 1; i <= n * 2; ++i)
{
v[b[i] - 'a'].push_back(i);
}
for (int i = n * 2; i >= 1; --i)
{
u[i] = v[a[i] - 'a'].back();
v[a[i] - 'a'].pop_back();
}
ll ans = 0;
for (int i = n * 2; i >= 1; --i)
{
ans += qry(u[i]);
ubd(u[i], 1);
}
cout << ans << "\n";
}
int main()
{
#ifdef SOMETHING
freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
#endif // SOMETHING
ios_base::sync_with_stdio(false), cin.tie(0);
int tt = 1;
//cin >> tt;
while (tt--)
{
solv();
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
5 ms |
1380 KB |
Output is correct |
3 |
Correct |
8 ms |
2360 KB |
Output is correct |
4 |
Correct |
11 ms |
3404 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
5 ms |
1380 KB |
Output is correct |
3 |
Correct |
8 ms |
2360 KB |
Output is correct |
4 |
Correct |
11 ms |
3404 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
5 ms |
1380 KB |
Output is correct |
3 |
Correct |
8 ms |
2360 KB |
Output is correct |
4 |
Correct |
11 ms |
3404 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
12 ms |
3316 KB |
Output is correct |
7 |
Correct |
11 ms |
3428 KB |
Output is correct |
8 |
Correct |
10 ms |
3392 KB |
Output is correct |
9 |
Correct |
11 ms |
3324 KB |
Output is correct |
10 |
Correct |
10 ms |
3296 KB |
Output is correct |
11 |
Correct |
10 ms |
3284 KB |
Output is correct |
12 |
Correct |
11 ms |
3276 KB |
Output is correct |
13 |
Correct |
11 ms |
3260 KB |
Output is correct |
14 |
Correct |
12 ms |
3228 KB |
Output is correct |
15 |
Correct |
10 ms |
3184 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
5 ms |
1380 KB |
Output is correct |
3 |
Correct |
8 ms |
2360 KB |
Output is correct |
4 |
Correct |
11 ms |
3404 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
12 ms |
3316 KB |
Output is correct |
11 |
Correct |
11 ms |
3428 KB |
Output is correct |
12 |
Correct |
10 ms |
3392 KB |
Output is correct |
13 |
Correct |
11 ms |
3324 KB |
Output is correct |
14 |
Correct |
10 ms |
3296 KB |
Output is correct |
15 |
Correct |
10 ms |
3284 KB |
Output is correct |
16 |
Correct |
11 ms |
3276 KB |
Output is correct |
17 |
Correct |
11 ms |
3260 KB |
Output is correct |
18 |
Correct |
12 ms |
3228 KB |
Output is correct |
19 |
Correct |
10 ms |
3184 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
344 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
300 KB |
Output is correct |
32 |
Correct |
11 ms |
3420 KB |
Output is correct |
33 |
Correct |
11 ms |
3412 KB |
Output is correct |
34 |
Correct |
10 ms |
3256 KB |
Output is correct |
35 |
Correct |
13 ms |
3348 KB |
Output is correct |
36 |
Correct |
11 ms |
3284 KB |
Output is correct |
37 |
Correct |
12 ms |
3396 KB |
Output is correct |
38 |
Correct |
11 ms |
3284 KB |
Output is correct |
39 |
Correct |
10 ms |
3284 KB |
Output is correct |
40 |
Correct |
10 ms |
3184 KB |
Output is correct |
41 |
Correct |
9 ms |
3256 KB |
Output is correct |