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 <cstdio>
int tree[2000000],base,index[1001000];
int sum(int l,int r){
int tmp=0;
while(l<r){
if(l%2==1) tmp+=tree[l++];
if(r%2==0) tmp+=tree[r--];
l>>=1,r>>=1;
}
if(l==r) tmp+=tree[l];
return tmp;
}
void add(int index){
while(index){
tree[index]++;
index>>=1;
}
}
int main(){
int n,i,tmp;
long long ans=0;
scanf("%d",&n);
for(base=1;base<n;base*=2);
for(i=1;i<=n;i++){
scanf("%d",&tmp);
index[tmp]=i;
}
for(i=0;i<n;i++){
scanf("%d",&tmp);
tmp=index[tmp];
ans+=sum(tmp+1+base,n+base);
add(tmp+base);
}
printf("%lld",ans);
}
# | 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... |