답안 #522237

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
522237 2022-02-04T08:50:17 Z blue Ekoeko (COCI21_ekoeko) C++17
110 / 110
36 ms 9580 KB
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
using namespace std;

using vi = vector<int>;
using ll = long long;
using pii = pair<int, int>;

#define sz(x) int(x.size())

const int mx = 100'000;

int n;
vi act(2*mx);

string s;

vi pos[2*mx];

vi occ[26];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n;
    cin >> s;

    for(int i = 0; i < 2*n; i++)
    {
        occ[s[i] - 'a'].push_back(i);
    }


    vector<pii> pr;

    vector<int> ls, rs;
    for(int c = 0; c < 26; c++)
    {
        sort(occ[c].begin(), occ[c].end());
        // cerr << char('a'+c) << " : ";
        // for(int o: occ[c]) cerr << o << ' ';
        // cerr << '\n';
        // cerr << sz(occ[c])/2 << '\n';
        for(int i = 0; i < sz(occ[c])/2; i++)
        {
            // cerr << "i = " << i << '\n';
            // cerr << "pair = " << occ[c][i] << ' ' << occ[c][i + (sz(occ[c])/2)] << '\n';
            pr.push_back({occ[c][i], occ[c][i + (sz(occ[c])/2)]});
        }
        // cerr << "\n";
    }

    int ct = -1;

    sort(pr.begin(), pr.end());

    for(auto p: pr)
    {
        // cerr << p.first << ' ' << p.second << '\n';
        ct++;
        act[p.first] = ct;
        act[p.second] = ct+n;
    }

    vi I(2*n);
    for(int i = 0; i < 2*n; i++) I[i] = i;
    sort(I.begin(), I.end(), [] (int x, int y)
    {
        return act[x] > act[y];
    });

    ll res = 0;

    vi BIT(1 + 2*n, 0);
    for(int i:I)
    {
        for(int j = i+1 - 1; j >= 1; j -= j&-j)
            res += BIT[j];
        for(int j = i+1; j <= 2*n; j += j&-j)
            BIT[j]++;
    }


    // for(int i = 0; i < 2*n; i++) cout << act[i] << ' ';
    // cout << '\n';
    cout << res << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5708 KB Output is correct
2 Correct 10 ms 7216 KB Output is correct
3 Correct 19 ms 8188 KB Output is correct
4 Correct 26 ms 9440 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5708 KB Output is correct
2 Correct 10 ms 7216 KB Output is correct
3 Correct 19 ms 8188 KB Output is correct
4 Correct 26 ms 9440 KB Output is correct
5 Correct 3 ms 5708 KB Output is correct
6 Correct 3 ms 5708 KB Output is correct
7 Correct 4 ms 5708 KB Output is correct
8 Correct 3 ms 5708 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5708 KB Output is correct
2 Correct 10 ms 7216 KB Output is correct
3 Correct 19 ms 8188 KB Output is correct
4 Correct 26 ms 9440 KB Output is correct
5 Correct 3 ms 5708 KB Output is correct
6 Correct 29 ms 9580 KB Output is correct
7 Correct 27 ms 9412 KB Output is correct
8 Correct 29 ms 9552 KB Output is correct
9 Correct 29 ms 9560 KB Output is correct
10 Correct 26 ms 9456 KB Output is correct
11 Correct 27 ms 9432 KB Output is correct
12 Correct 26 ms 9372 KB Output is correct
13 Correct 26 ms 9432 KB Output is correct
14 Correct 26 ms 9292 KB Output is correct
15 Correct 26 ms 9296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5708 KB Output is correct
2 Correct 3 ms 5812 KB Output is correct
3 Correct 3 ms 5836 KB Output is correct
4 Correct 4 ms 5836 KB Output is correct
5 Correct 3 ms 5836 KB Output is correct
6 Correct 4 ms 5804 KB Output is correct
7 Correct 4 ms 5836 KB Output is correct
8 Correct 3 ms 5804 KB Output is correct
9 Correct 3 ms 5836 KB Output is correct
10 Correct 3 ms 5836 KB Output is correct
11 Correct 4 ms 5836 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5708 KB Output is correct
2 Correct 10 ms 7216 KB Output is correct
3 Correct 19 ms 8188 KB Output is correct
4 Correct 26 ms 9440 KB Output is correct
5 Correct 3 ms 5708 KB Output is correct
6 Correct 3 ms 5708 KB Output is correct
7 Correct 4 ms 5708 KB Output is correct
8 Correct 3 ms 5708 KB Output is correct
9 Correct 3 ms 5708 KB Output is correct
10 Correct 29 ms 9580 KB Output is correct
11 Correct 27 ms 9412 KB Output is correct
12 Correct 29 ms 9552 KB Output is correct
13 Correct 29 ms 9560 KB Output is correct
14 Correct 26 ms 9456 KB Output is correct
15 Correct 27 ms 9432 KB Output is correct
16 Correct 26 ms 9372 KB Output is correct
17 Correct 26 ms 9432 KB Output is correct
18 Correct 26 ms 9292 KB Output is correct
19 Correct 26 ms 9296 KB Output is correct
20 Correct 3 ms 5708 KB Output is correct
21 Correct 3 ms 5812 KB Output is correct
22 Correct 3 ms 5836 KB Output is correct
23 Correct 4 ms 5836 KB Output is correct
24 Correct 3 ms 5836 KB Output is correct
25 Correct 4 ms 5804 KB Output is correct
26 Correct 4 ms 5836 KB Output is correct
27 Correct 3 ms 5804 KB Output is correct
28 Correct 3 ms 5836 KB Output is correct
29 Correct 3 ms 5836 KB Output is correct
30 Correct 4 ms 5836 KB Output is correct
31 Correct 3 ms 5708 KB Output is correct
32 Correct 36 ms 9576 KB Output is correct
33 Correct 28 ms 9564 KB Output is correct
34 Correct 30 ms 9480 KB Output is correct
35 Correct 26 ms 9532 KB Output is correct
36 Correct 30 ms 9440 KB Output is correct
37 Correct 26 ms 9408 KB Output is correct
38 Correct 26 ms 9484 KB Output is correct
39 Correct 26 ms 9464 KB Output is correct
40 Correct 25 ms 9304 KB Output is correct
41 Correct 25 ms 9368 KB Output is correct