# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1003801 | vjudge1 | Ekoeko (COCI21_ekoeko) | C++17 | 20 ms | 4028 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int maxa = 30;
const int maxn = 2e5 + 10;
vector<int> bit(maxn), ocorrencias[maxa];
void update( int id, int val ){ for( int i = id; i < maxn; i += i&-i ) bit[i] += val; }
int query( int id ){ int sum = 0; for( int i = id; i > 0; i -= i&-i ) sum += bit[i]; return sum; }
int main(){
int n; cin >> n;
for( int i = 1; i <= 2*n; i++ ){
char c; cin >> c;
ocorrencias[c - 'a'].push_back(i);
}
vector<pair<int, int>> original;
for( int i = 0; i < 26; i++ ) for( int j = 0; j < ocorrencias[i].size()/2; j++ ) original.push_back({ ocorrencias[i][j], i });
sort( original.begin(), original.end() );
vector<int> cont(maxa), v(2*n + 1);
for( int i = 0; i < original.size(); i++){
int letra = original[i].second;
v[ocorrencias[letra][cont[letra]]] = i + 1;
v[ocorrencias[letra][cont[letra] + ocorrencias[letra].size()/2]] = n + i + 1;
cont[letra]++;
}
ll resp = 0;
for( int i = 1; i <= 2*n; i++ ){
update(v[i], 1);
int inversoes = i - query(v[i]);
resp += inversoes;
}
cout << resp << endl;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |