您的位置:首页 > 其它

UVALive 6508 Permutation Graphs

2015-10-04 20:13 375 查看

Permutation Graphs

Time Limit: 3000ms
Memory Limit: 131072KB
This problem will be judged on UVALive. Original ID: 6508
64-bit integer IO format: %lld Java class name: Main

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 100010;
int c[maxn],hhash[maxn],n;
void add(int i){
while(i > 0){
c[i] += 1;
i -= i&-i;
}
}
int sum(int i,int ret = 0){
while(i < maxn){
ret += c[i];
i += i&-i;
}
return ret;
}
int main(){
int kase,tmp;
scanf("%d",&kase);
while(kase--){
scanf("%d",&n);
for(int i = 1; i <= n; ++i){
scanf("%d",&tmp);
hhash[tmp] = i;
}
memset(c,0,sizeof c);
LL ret = 0;
for(int i = 0; i < n; ++i){
scanf("%d",&tmp);
ret += sum(hhash[tmp] + 1);
add(hhash[tmp]);
}
printf("%lld\n",ret);
}
return 0;
}


View Code
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: