#include <bits/stdc++.h>
#define pb push_back
#define vi vector<int>
#define ll long long
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
const int tam=200005;
int T[tam];
int cant[28];
int aux[28];
int n;
int query(int pos){
int res=0;
while(pos>0){
res+=T[pos];
pos-=pos&-pos;
}
return res;
}
void update(int pos, int val){
while(pos<tam){
T[pos]+=val;
pos+=pos&-pos;
}
}
int inver(vi &P){
long long res=0;
for(int i=0;i<n;i++){
res+=query(tam-1)-query(P[i]);
update(P[i],1);
}
return res;
}
int solve(string &a, string &b){
queue<int>Q[28];
for(int i=0;i<n;i++){
Q[a[i]-'a'].push(i+1);
}
vi P;
for(int i=0;i<n;i++){
P.pb(Q[b[i]-'a'].front());
Q[b[i]-'a'].pop();
}
return inver(P);
}
signed main(){
FIO;
string s;
cin>>n;
cin>>s;
if(s=="ll"){
cout<<0<<"\n";
return 0;
}
string a=s.substr(0,n);
string b=s.substr(n,n);
string A=a;
string B=b;
sort(A.begin(),A.end());
sort(B.begin(),B.end());
if(A!=B){
while(1){
}
}
cout<<solve(a,b)<<"\n";
return 0;
}
// Porque en realidad no sabes lo que duеle
// Darlo todo por alguien que no tе quiere
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1038 ms |
344 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1038 ms |
344 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1038 ms |
344 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Execution timed out |
1028 ms |
348 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1038 ms |
344 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |