codeforces 301 E. Infinite Inversions
题目:
2 seconds
256 megabytes
standard input
standard output
There is an infinite sequence consisting of all positive integers in the increasing order: p = {1, 2, 3, ...}. We performed n swapoperations with this sequence. A swap(a, b) is an operation of swapping the elements of the sequence on positions a and b. Your task is to find the number of inversions in the resulting sequence, i.e. the number of such index pairs (i, j), that i < j and pi > pj.
The first line contains a single integer n (1 ≤ n ≤ 105) — the number of swap operations applied to the sequence.
Each of the next n lines contains two integers ai and bi (1 ≤ ai, bi ≤ 109, ai ≠ bi) — the arguments of the swap operation.
Print a single integer — the number of inversions in the resulting sequence.
终于脑补出来了。。,总是看不懂E文题解
由于a[i],b[i]很大,但是我们可以分为两部分计算
part1:首先计算只交换的逆序数,这个可以使离散+BIT(树状数组)
part2:未出现的数怎么计算,其实为出现的也只跟 出现的数有关,因为未出现的数的相对顺序不变。
举个例子:交换后:1 9 3 6 7 2 4 8 5
这里只有 1 3 8 没有交换,且出现
所以先是算9不满足,然后 6 也没有 7也没有(这里指计算为出现与出现部分
然后2:总共有 9 3 6 7四个 未出现的有3,那么怎么计算?
2在的位置是6那么前面有6-2个大于他的数,减去之前出现的(交换出现 只与2相关)就是答案
可以发现 5 也是如此推算:9 3 6 7 8 --》9-5=4;4-3=1;
如此云云
codeforces 301 E. Infinite Inversions的更多相关文章
- CF #301 E:Infinite Inversions(逆序数,树状数组)
A-Combination Lock B-School Marks C-Ice Cave D-Bad Luck Island E-Infinite Inversions E:Infini ...
- Codeforces Round #301 (Div. 2) E . Infinite Inversions 树状数组求逆序数
E. Infinite Inversions ...
- 线段树 离散化 E. Infinite Inversions E. Physical Education Lessons
题目一:E. Infinite Inversions 这个题目没什么思维量,还比较简单,就是离散化要加上每一个值的后面一个值,然后每一个值放进去的不是1 ,而是这个值与下一个点的差值. 因为这个数代表 ...
- 【Codeforces Round #301 (Div. 2) E】Infinite Inversions
[链接] 我是链接,点我呀:) [题意] 给你一个无限长的序列1,2,3,4... 然后给你n个操作. 每个操作ai,bi; 表示调换位置为ai和位置为bi的数的位置. (ai,bi<=10^9 ...
- CodeForces 540E - Infinite Inversions(离散化+树状数组)
花了近5个小时,改的乱七八糟,终于A了. 一个无限数列,1,2,3,4,...,n....,给n个数对<i,j>把数列的i,j两个元素做交换.求交换后数列的逆序对数. 很容易想到离散化+树 ...
- codeforces 540E"Infinite Inversions"
传送门 题意: 给你一个无限大的整数序列 p = {1, 2, 3, ...}: 有 n 次操作,每次操作交换第 ai 个数和第 aj 个数: 求序列中逆序对的个数: 题解: 考虑交换完后的序列,存 ...
- Infinite Inversions(树状数组+离散化)
思路及代码参考:https://blog.csdn.net/u014800748/article/details/45420085 There is an infinite sequence cons ...
- CodeForces 622 A.Infinite Sequence
A.Infinite Sequence time limit per test 1 second memory limit per test 256 megabytes input standard ...
- codeforces 675A A. Infinite Sequence(水题)
题目链接: A. Infinite Sequence time limit per test 1 second memory limit per test 256 megabytes input st ...
随机推荐
- sql通过 openrowset查询csv文件
两步即可完成 第一步. 创建cmmData.xml文件,并存入到能与sql服务器共享的文件夹中(如:\\10.252.21.6\sharedfolder) <?xml version=" ...
- SAP CRM调查问卷的评分和图表显示功能介绍
SAP CRM里我们使用事务码CRM_SURVEY_SUITE创建一个调查问卷(Survey): 其中调查问卷的问题和答案均可分配权值(Rate),最后该问卷总的分数等于每个问题的权值乘以客户选择答案 ...
- Recyclerview设置间距
首先自定义一个RecyclerViewDivider 继承 RecyclerView.ItemDecoration,实现自定义. public class RecyclerViewDivider ex ...
- Docker 启动时报错:iptables:No chain/target/match by the name
重新启动docker后,就好了. service docker restart
- python之路——内置函数和匿名函数
阅读目录 楔子 内置函数 匿名函数 本章小结 楔子 在讲新知识之前,我们先来复习复习函数的基础知识. 问:函数怎么调用? 函数名() 如果你们这么说...那你们就对了!好了记住这个事儿别给忘记了,咱们 ...
- C# string补位
参考:https://www.cnblogs.com/zhangqs008/archive/2012/02/01/2341078.html //1.1.左补位 "; , 'A'); //1. ...
- selenium——操作滚动条
在自动化测试的过程中,难免会应用到翻页键,但是webdriver提供的方法都是操作当前页面可见的元素,对于未在当前范围展示的翻页键,该如何操作呢? 小编在这里介绍一种方法:使用JavaScript操作 ...
- Http请求封装(对HttpClient类的进一步封装,使之调用更方便。另外,此类管理唯一的HttpClient对象,支持线程池调用,效率更高)
package com.ad.ssp.engine.common; import java.io.IOException; import java.util.ArrayList; import jav ...
- 部署安装lnmp
链接:http://pan.baidu.com/s/1skMSgDv 密码:h8rn 此安装包可在阿里云所有linux系统上部署安装.此安装包包含的软件及版本为:nginx:1.0.15.1.2.5. ...
- LINUX常见小问题汇总
1. crontab的备份与恢复 备份crontab文件: crontab -l > $HOME/mycron 恢复丢失的crontab文件: 如果不小心误删了crontab文件,假设你在自己的 ...