# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1003847 |
2024-06-20T18:57:57 Z |
vjudge1 |
Ekoeko (COCI21_ekoeko) |
C++17 |
|
2 ms |
2712 KB |
#include <bits/stdc++.h>
using namespace std;
vector<int> tree;
void update(int pos, int i, int f, int idx){
if(i == f){
tree[pos]++;
return;
}
int meio = (i+f)/2;
if(idx <= meio) update(2*pos+1, i, meio, idx);
else update(2*pos+2, meio+1, f, idx);
tree[pos] = tree[2*pos+1] + tree[2*pos+2];
return;
}
int query(int pos, int i, int f, int l, int r){
if(l<=i and f<=r){
return tree[pos];
}
int meio =(i+f)/2;
int res = 0;
if(l <= meio) res += query(2*pos+1, i, meio, l, r);
if(r > meio) res += query(2*pos+2, meio+1, f, l, r);
return res;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
vector<vector<int>> letra(30);
int n; cin >> n;
tree.assign(4*(n+1), 0);
string s; cin >> s;
n *=2;
for(int i=0; i<n; i++){
int nmr = s[i] - 'a';
letra[nmr].push_back(i);
}
vector<int> qnt(30,0);
int res = 0;
for(int i = 0; i<n/2; i++){
int nmr = s[i] - 'a';
int sz = letra[nmr].size();
sz/=2;
int posicao = letra[nmr][sz + qnt[nmr]];
res += query(0,0,n,posicao, n);
update(0,0,n, posicao);
qnt[nmr]++;
}
cout << res << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Runtime error |
2 ms |
2712 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Runtime error |
2 ms |
2712 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Runtime error |
2 ms |
2712 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Runtime error |
1 ms |
456 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Runtime error |
2 ms |
2712 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |