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;
map<int,int>um;
class FW{
vector<int>F;
int N;
public:
FW(int k){F.assign((N=k)+1,0);}
void in(int X,int Y){for(;X<=N;X+=X&-X)F[X]+=Y;}
int out(int X){int sum=0;for(;X;X-=X&-X)sum+=F[X];return sum;}
};
int main()
{
int N;
cin>>N;
FW tr(N);
vector<int>V(N);
for(auto&I:V)cin>>I;
for(int i=1;i<=N;i++)
{
int a;
cin>>a;
um[a]=i;
}
long long S=0;
for(int i=0;i<N;i++)
{
S+=i-tr.out(um[V[i]]);
tr.in(um[V[i]],1);
}
printf("%lld",S);
}
# | 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... |