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 <stdio.h>
const int MAX = 1000010;
int A[MAX],B[MAX], T[MAX];
int Sum(int e)
{
int r=0;
while (e>0)
r+=T[e], e-=e&-e;
return r;
}
void Update(int e, int v, int N)
{
while (e<=N)
T[e]+=v, e+=e&-e;
}
int main()
{
int N,M;
scanf("%d",&N);
for (int i=1; i<=N; i++) {
scanf("%d",&M);
A[M] = i;
}
for (int i=1; i<=N; i++) {
scanf("%d",&M);
B[A[M]] = i;
}
long long ret=0;
for (int i=1; i<=N; i++) {
ret += i-Sum(B[i])-1;
Update(B[i],1,N);
}
printf("%lld\n",ret);
}
# | 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... |