UVALive 6508 Permutation Graphs
2015-10-04 20:13
375 查看
Permutation Graphs
Time Limit: 3000msMemory 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
相关文章推荐
- 网络故障之DHCP广播风暴------运维上看交换机的CPU占用率100%
- 左右JAVA示例代码事件分发和监督机制来实现-绝对原创有用
- 核心技术篇:6.android网络编程之json解析
- 机器学习笔记 线性判别分析(中)
- STC12C4052AD,4位数据总线驱动1602 LCD液晶屏,8位ADC功能,0--255级别
- 动态变量和静态变量的区别
- 动态规划(算法分析与设计)
- 自己的练习四之对象与数组的组合
- iOS 转场动画等
- 信息安全系统设计基础第三周学习总结
- UVALive 4853 Emoogle Balance
- ASP.NET MVC + Bootstrap + XML + WCF 封装短信验证服务(一)
- AOP运行过程解析
- 第二次作业利用java语言编写计算器进行四则运算
- 自己的练习三之复制构造函数
- MFC Radio Button 和 Combox Button的简单操作
- 第三周学习总结
- [android]完美的解决方案ListView加载网络图片反弹问题
- 弱校联萌十一大决战之如日中天 G Gadget Hackwrench
- A018-布局之TableLayout