답안 #850449

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
850449 2023-09-16T14:55:08 Z serifefedartar Ekoeko (COCI21_ekoeko) C++17
0 / 110
1000 ms 3676 KB
#include <bits/stdc++.h>
using namespace std;
 
#define fast ios::sync_with_stdio(0);cin.tie(0);
#define s second
#define f first
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll LOGN = 20;
const ll MAXN = 2e5 + 5;

vector<int> occ[30];
int n;
ll fen[MAXN];
ll query(int k) {
    ll res = 0;
    while (k >= 1) {
        res += fen[k];
        k -= (k&-k);
    }
    return res;
}

void update(int k, ll val) {
    while (k <= n) {
        fen[k] += val;
        k += (k&-k);
    }
}

int main() {
    fast
    memset(fen, 0, sizeof(fen));
    string s;
    cin >> n >> s;
    s = "#" + s;

    for (int i = n; i >= 1; i--) {
        occ[s[i]-'a'].push_back(i);
    }
    
    vector<int> v;
    for (int i = n+1; i <= 2*n; i++) {
        v.push_back(occ[s[i]-'a'].back());
        occ[s[i]-'a'].pop_back();
    }

    ll ans = 0;
    int cnt = 0;
    for (auto u : v) {
        ans += cnt - query(u);
        update(u, 1);
        cnt++;
    }
    cout << ans << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 3676 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 3676 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 3676 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1884 KB Output is correct
2 Execution timed out 1082 ms 1884 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 3676 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -