#include <stdio.h>
int n;
int val[1000007];
int seq[500007];
int bit[1048577], bin;
void put(int key)
{
int ind = bin+key-1;
while(ind)
{
bit[ind]++;
ind /= 2;
}
}
int sum(int left, int right)
{
int lind = bin+left-1;
int rind = bin+right-1;
int rval=0;
while(lind <= rind)
{
if(lind%2 == 1) rval += bit[lind];
if(rind%2 == 0) rval += bit[rind];
lind = (lind+1)/2;
rind = (rind-1)/2;
}return rval;
}
int main(void)
{
int i, v;
long long res=0;
scanf("%d", &n);
for(bin=1;bin<n;bin*=2);
for(i = 1; i <= n; i++)
scanf("%d", &seq[i]);
for(i = 1; i <= n; i++)
{
scanf("%d", &v);
val[v]= i;
}
for(i = 1; i <= n; i++)
seq[i] = val[seq[i]];
for(i = 1; i <= n; i++)
{
res += sum(seq[i]+1, n);
put(seq[i]);
}printf("%lld\n", res);
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
10840 KB |
Output is correct |
2 |
Correct |
0 ms |
10840 KB |
Output is correct |
3 |
Correct |
0 ms |
10840 KB |
Output is correct |
4 |
Correct |
0 ms |
10840 KB |
Output is correct |
5 |
Correct |
0 ms |
10840 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
10840 KB |
Output is correct |
2 |
Correct |
1 ms |
10840 KB |
Output is correct |
3 |
Correct |
5 ms |
10840 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
10840 KB |
Output is correct |
2 |
Correct |
29 ms |
10840 KB |
Output is correct |
3 |
Correct |
40 ms |
10840 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
57 ms |
10840 KB |
Output is correct |
2 |
Correct |
92 ms |
10840 KB |
Output is correct |
3 |
Correct |
113 ms |
10840 KB |
Output is correct |
4 |
Correct |
183 ms |
10840 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
242 ms |
10840 KB |
Output is correct |
2 |
Correct |
280 ms |
10840 KB |
Output is correct |
3 |
Correct |
266 ms |
10840 KB |
Output is correct |
4 |
Correct |
307 ms |
10840 KB |
Output is correct |
5 |
Correct |
315 ms |
10840 KB |
Output is correct |
6 |
Correct |
320 ms |
10840 KB |
Output is correct |