题目给的输入是大坑,算法倒是很简单……

输入的是绳子的编号wire ID,而不是上(或下)挂钩对应下(或上)挂钩的编号。 所以要转换编号,转换成挂钩的顺序,然后再求逆序数。

知道了这个以后直接乱搞就可以0msAC

(这题可以用冒泡排序过的……) (n<=1000)

// by SiriusRen
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int n,tree[6666],ans=0;
struct Node
{
int x,y;
}point[1005],node[1005];
bool cmp(Node a,Node b)
{
return a.x<b.x;
}
int query(int l,int r,int pos,int W)
{
if(l>=W)return tree[pos];
int mid=(l+r)>>1;
if(mid<W)return query(mid+1,r,pos<<1|1,W);
else return query(l,mid,pos<<1,W)+query(mid+1,r,pos<<1|1,W);
}
void insert(int l,int r,int pos,int W)
{
if(l==r){tree[pos]++;return;}
int mid=(l+r)>>1;
if(mid>=W)insert(l,mid,pos<<1,W);
else insert(mid+1,r,pos<<1|1,W);
tree[pos]=tree[pos<<1]+tree[pos<<1|1];
}
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
scanf("%d%d",&point[i].x,&point[i].y);
}
for(int i=1;i<=n;i++)
{
node[point[i].x].x=i;
node[point[i].y].y=i;
}
sort(node+1,node+1+n,cmp);
for(int i=1;i<=n;i++)
{
ans+=query(1,n,1,node[i].y);
insert(1,n,1,node[i].y);
}
printf("%d\n",ans);
}

POJ 2188线段树求逆序对的更多相关文章

  1. 4163 hzwer与逆序对 (codevs + 权值线段树 + 求逆序对)

    题目链接:http://codevs.cn/problem/4163/ 题目:

  2. BNU 2418 Ultra-QuickSort (线段树求逆序对)

    题目链接:http://acm.bnu.edu.cn/bnuoj/problem_show.php?pid=2418 解题报告:就是给你n个数,然后让你求这个数列的逆序对是多少?题目中n的范围是n & ...

  3. HDU 4911 http://acm.hdu.edu.cn/showproblem.php?pid=4911(线段树求逆序对)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4911 解题报告: 给出一个长度为n的序列,然后给出一个k,要你求最多做k次相邻的数字交换后,逆序数最少 ...

  4. SGU 180 Inversions(离散化 + 线段树求逆序对)

    题目链接:http://acm.sgu.ru/problem.php?contest=0&problem=180 解题报告:一个裸的求逆序对的题,离散化+线段树,也可以用离散化+树状数组.因为 ...

  5. hdu1394(线段树求逆序对)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1394 线段树功能:update:单点增减 query:区间求和 分析:如果是0到n-1的排列,那么如果 ...

  6. poj2299 Ultra-QuickSort(线段树求逆序对)

    Description In this problem, you have to analyze a particular sorting algorithm. The algorithm proce ...

  7. HDU 1394 线段树求逆序对

    Minimum Inversion Number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java ...

  8. FZU2018级算法第五次作业 m_sort(归并排序或线段树求逆序对)

    首先对某人在未经冰少允许情况下登录冰少账号原模原样复制其代码并且直接提交的赤裸裸剽窃行为,并且最终被评为优秀作业提出抗议! 题目大意: 给一个数组含n个数(1<=n<=5e5),求使用冒泡 ...

  9. HDU 1394 Minimum Inversion Number(线段树求逆序对)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1394 解题报告:给出一个序列,求出这个序列的逆序数,然后依次将第一个数移动到最后一位,求在这个过程中 ...

随机推荐

  1. httpclient定时请求实例

    1.pom.xml <properties> <slf4j.version>1.7.21</slf4j.version> <okhttp.version> ...

  2. GreenDao 3.X之基本使用

    在GreenDao 3.X之注解已经了解到GreenDao 3.0的改动及注解.对于数据库的操作,无异于增删改查等四个操作.下面我们将了解GreenDao 3.X如何使用? AbstractDao 所 ...

  3. node.js连接数据库登录注册,修改用户(页面的ajax请求)

    首先给大家看一下目录结构,结构如下: index.html 首页(显示所有的用户信息) login.html 登录页 register.html 注册页 db.js 配置链接数据库参数 dbhelpe ...

  4. SQL 学习——简序以及学习路线

    1.最近发现自己除去简单的SQL语句好像其他的并不怎么懂哎,虽然暂时是android用不到太复杂点的语句,想来总不能一直这样把, 顺带还是看看Sql. 2.画个图规划下自己的学习路线

  5. mysql中redo和binlog的区别

    影响MySQL中redo的配置参数: innodb_log_file_size:指定每个redo日志大小,默认值48MB innodb_log_files_in_group:指定日志文件组中redo日 ...

  6. 密信(MeSince),将取代传统电子邮件

    电子邮件发展至今已经有几十年的历史,但仍然是最重要的现代互联网应用之一.在全球范围内,每小时发送的非垃圾邮件数量超过30亿封,从工作场景的使用到个人生活,电子邮件都扮演着不可或缺的角色.但是由于明文电 ...

  7. [置顶] openHAB 体系结构与编程模型 (1) --- 术语

    openHAB 术语 Item : 对硬件设备属性的抽象 ( Items are objects that can be read from or written to in order to int ...

  8. 安装Nginx的各种报错的解决

    如题,本人环境Ubuntu14.0虚拟机,安装一个nginx服务器来运行我的fastDfs文件管理的.但是安装出现了各种问题: sudo ./configure --prefix=/usr/local ...

  9. django-1-框架介绍

    <<<python虚拟环境>>> 用django框架做web开发必须要用到python虚拟环境,而且一个虚拟环境只能创建一个django项目,如果创建多个djang ...

  10. 2019-03-15 Python time datetime 获取当下时间 和 格式化时间

    import datetime start_date='2018-01-10' end_date='2019-01-10'# 转换为2018-01-10 00:00:00start_date=date ...