Permutation Graphs

Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu

 #include<stdio.h>
#include<string.h> int temp[],a[],b[],c[],b1[];
long long num; void merg_sort(int a[],int l,int r)
{
int i,j,len=r-l,p1,p2;
if(len<=)
return;
int mid=l+len/;
merg_sort(a,l,mid);
merg_sort(a,mid,r);
p1=l,p2=mid;
for(i=l;i<r;i++)
{
if(p1==mid)
{
temp[i]=a[p2];
p2++;
}
else if(p2==r)
{
temp[i]=a[p1];
p1++;
}
else
{
if(a[p1]<=a[p2])
{
temp[i]=a[p1];
p1++;
}
else
{
temp[i]=a[p2];
p2++;
num=num+mid-p1;
}
}
}
for(i=l;i<r;i++)
a[i]=temp[i];
return;
} int main()
{
int T;
int n,i,j,k;
scanf("%d",&T);
while(T--)
{
num=;
scanf("%d",&n);
for(i=;i<=n;i++)
scanf("%d",&b[i]);
for(i=;i<=n;i++)
b1[b[i]]=i; for(i=;i<=n;i++)
scanf("%d",&c[i]);
for(i=;i<=n;i++)
a[i]=b1[c[i]]; /*for(i=1;i<=n;i++)
printf("%d ",a[i]);*/
merg_sort(a,,n+);
printf("%lld\n",num);
}
return ;
}

UVALive 6508 Permutation Graphs的更多相关文章

  1. 逆序数 UVALive 6508 Permutation Graphs

    题目传送门 /* 题意:给了两行的数字,相同的数字连线,问中间交点的个数 逆序数:第一行保存每个数字的位置,第二行保存该数字在第一行的位置,接下来就是对它求逆序数 用归并排序或线段树求.想到了就简单了 ...

  2. UVaLive 11525 Permutation (线段树)

    题意:有一个由1到k组成的序列,最小是1 2 … k,最大是 k k-1 … 1,给出n的计算方式,n = s0 * (k - 1)! + s1 * (k - 2)! +… + sk-1 * 0!, ...

  3. UVALIVE 4556 The Next Permutation

    4556 The Next PermutationFor this problem, you will write a program that takes a (possibly long) str ...

  4. Permutation Sequence

    The set [1,2,3,-,n] contains a total of n! unique permutations. By listing and labeling all of the p ...

  5. [LeetCode] Palindrome Permutation II 回文全排列之二

    Given a string s, return all the palindromic permutations (without duplicates) of it. Return an empt ...

  6. [LeetCode] Palindrome Permutation 回文全排列

    Given a string, determine if a permutation of the string could form a palindrome. For example," ...

  7. [LeetCode] Permutation Sequence 序列排序

    The set [1,2,3,…,n] contains a total of n! unique permutations. By listing and labeling all of the p ...

  8. [LeetCode] Next Permutation 下一个排列

    Implement next permutation, which rearranges numbers into the lexicographically next greater permuta ...

  9. Leetcode 60. Permutation Sequence

    The set [1,2,3,-,n] contains a total of n! unique permutations. By listing and labeling all of the p ...

随机推荐

  1. 夺命雷公狗---node.js---11之文件上传

    我们在做文件上传前需要用npm来安装一个插件先, 首先打开项目所在的目录,然后按住shift键然后右键鼠标进入命令行安装formidable 然后开始编写上传的静态页面: <!DOCTYPE h ...

  2. Yii多表关联

    表结构 现在有客户表.订单表.图书表.作者表, 客户表Customer    (id  customer_name) 订单表Order           (id  order_name       ...

  3. composer未升级报错

    错误: Cannot adopt OID in SQUID-MIB: cacheClients ::= { cacheProtoAggregateStats 15 } Cannot adopt OID ...

  4. loadruner报错:Step download timeout(120 seconds)的一个解决方法

    一个网友问了我一个问题如下: loadruner报错:Error -27728: Step download timeout (120 seconds) 如何解决 语 法检查通过,但是在并发执行一个查 ...

  5. javaWeb 使用jsp标签进行防盗链

    /** * 1.新建类继承SimpleTagSupport * 新建2个属性, 添加对应的set方法 * 覆盖doTag()方法 */ import java.io.IOException; impo ...

  6. javaWeb 使用cookie显示商品浏览记录

    package de.bvb.cookie; import java.io.IOException; import java.io.PrintWriter; import java.util.Date ...

  7. flex 添加右键链接

    private var myMenu:ContextMenu; private function setViewerVersion():void { var menuItem:ContextMenuI ...

  8. restful 注解

    @Path @Path 注释被用来描述根资源.子资源方法或子资源的位置.value 值可以包含文本字符.变量或具有定制正则表达式的变量. @GET.@POST.@PUT.@DELETE.@HEAD @ ...

  9. HDU 1890:Robotic Sort(Splay)

    http://acm.hdu.edu.cn/showproblem.php?pid=1890 题意:有一个无序序列,经过不断地翻转,使得最后的序列是一个升序的序列,而且如果相同数字要使在原本序列靠前的 ...

  10. HDU 1728:逃离迷宫(BFS)

    http://acm.hdu.edu.cn/showproblem.php?pid=1728 逃离迷宫 Problem Description   给定一个m × n (m行, n列)的迷宫,迷宫中有 ...