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 n, mp[1000005], t;
int c[500005];
struct f{
int tree[530000], lim;
void init(int n){
for (lim = 1; lim <= n+1; lim <<= 1);
}
void add(int x){
x++;
while(x <= lim){
tree[x]++;
x += x & -x;
}
}
int sum(int x){
x++;
int res = 0;
while(x){
res += tree[x];
x -= x & -x;
}
return res;
}
}bit;
int main(){
scanf("%d",&n);
for (int i=0; i<n; i++) {
scanf("%d",&t);
mp[t] = i;
}
for (int i=0; i<n; i++) {
scanf("%d",&t);
c[mp[t]] = i;
}
bit.init(n);
long long res = 0;
for (int i=0; i<n; i++) {
res += i - bit.sum(c[i]);
bit.add(c[i]);
}
printf("%lld",res);
}
# | 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... |