POJ_3067 Japan[ 逆序数 树状数组 or 归并排序)
来源:互联网 发布:黄金交易软件排名 编辑:程序博客网 时间:2024/05/01 15:55
传送门:POJ_3067
题目:n,m,k;左右两列数,数的范围分别1-n,1-m,然给k个连线。
Sample Input
13 4 41 42 33 23 1
Sample Output
Test case 1: 5
思路:逆序数
代码:
//树状数组版
//树状数组#include<iostream>#include<cstring>#include<cmath>#include<cstdio>#include<algorithm>#include<string>#include<map>#include<vector>#include<queue>#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1#define INF 0x3f3f3f3f#define PI acos(-1.0)#define mem(a,b) memset(a,b,sizeof a)#define read_ freopen("i.txt","r",stdin)using namespace std;typedef long long LL;const int N=1010;int n,m,k;int c[N];struct node{ int a,b;}p[1000010];int cmp(node a,node b){ if(a.a==b.a) return a.b<b.b; return a.a<b.a;}int lowbit(int x){ return x&(-x);}void add(int x,int v){ while(x<=m) { c[x]+=v; x+=lowbit(x); }}LL sum(int x){ LL ret=0; while(x>0) { ret=ret+c[x]; x-=lowbit(x); } return ret;}int main(){ int T; scanf("%d",&T); for(int cas=1;cas<=T;cas++) { mem(c,0); scanf("%d%d%d",&n,&m,&k); for(int i=0;i<k;i++) scanf("%d%d",&p[i].a,&p[i].b); sort(p,p+k,cmp); LL ans=0; for(int i=0;i<k;i++){ add(p[i].b,1); ans+=sum(m)-sum(p[i].b); } printf("Test case %d: %I64d\n",cas,ans); } return 0;}
0 0
- POJ_3067 Japan[ 逆序数 树状数组 or 归并排序)
- 【树状数组or归并排序求逆序数】HDU 1394
- 树状数组--逆序数--Japan
- POJ 2299 Ultra-QuickSort 【归并排序求逆序数 OR 树状数组求逆序数】
- 归并排序&&树状数组求逆序数
- 归并排序 树状数组 求逆序数
- 树状数组(归并排序) 之 求逆序数nyoj117
- POJ 3067 Japan (树状数组求逆序数)
- POJ 3067 Japan(树状数组/求逆序数)
- POJ 3067 Japan(树状数组+逆序数)
- POJ 3067 Japan (树状数组求逆序数---经典)
- POJ 3067-Japan(树状数组-逆序数)
- Japan 树状数组加逆序数...
- POJ3067 Japan【树状数组】【逆序数】
- poj--3067 Japan(树状数组+逆序数)
- poj3067 Japan 树状数组 逆序数
- POJ3067 Japan(树状数组,逆序数)
- POJ 3067 Japan (树状数组 + 逆序数)
- C# Webrowser 屏蔽弹出窗口
- 1000 A + B Problem
- cocos2dx 3D战斗类游戏制作:【三】——基于数据库的3D精灵动画1
- 比较全面的一个自定义导航栏
- Android UI(五)云通讯录项目之联系人列表,带侧滑选择,带搜索框
- POJ_3067 Japan[ 逆序数 树状数组 or 归并排序)
- Apache配置虚拟目录
- C#调用存储过程(转)
- 个人技术博客站点
- C学习笔记 控制数组的有效长度并统计数组中重复数字。
- 刷题-Maximum Depth of Binary Tree
- Java EE 7 教程 前言
- 我要的你给不起!
- Android5.0 BLE 周边(BluetoothLeAdvertiser)