codeforces 652D Nested Segments 离散化+树状数组
题意:给你若干个区间,询问每个区间包含几个其它区间
分析:区间范围比较大,然后离散化,按右端点排序,每次更新树状数组中的区间左端点,查询区间和
注:(都是套路)
#include<cstdio>
#include<cstring>
#include<queue>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<cmath>
using namespace std;
typedef long long LL;
const int N=2e5+;
const int INF=0x3f3f3f3f;
int a[N<<],n,d;
struct pair{
int l,r,id;
bool operator<(const pair &e)const{
return r<e.r;
}
}p[N];
int c[N<<];
void change(int x){
for(int i=x;i<=d;i+=i&(-i))
++c[i];
}
int query(int x){
int ans=;
for(int i=x;i>;i-=i&(-i))
ans+=c[i];
return ans;
}
int res[N];
int main(){
scanf("%d",&n);
int tot=;
for(int i=;i<=n;++i){
scanf("%d%d",&p[i].l,&p[i].r),p[i].id=i;
a[++tot]=p[i].l;
a[++tot]=p[i].r;
}
sort(a+,a++tot);
d=;
for(int i=;i<=tot;++i)
if(a[i]!=a[i-])a[++d]=a[i];
sort(p+,p++n);
for(int i=;i<=n;++i){
int r=lower_bound(a+,a++d,p[i].r)-a;
int l=lower_bound(a+,a++d,p[i].l)-a;
res[p[i].id]=query(r)-query(l-);
change(l);
}
for(int i=;i<=n;++i)
printf("%d\n",res[i]);
return ;
}
codeforces 652D Nested Segments 离散化+树状数组的更多相关文章
- CF Educational Codeforces Round 10 D. Nested Segments 离散化+树状数组
题目链接:http://codeforces.com/problemset/problem/652/D 大意:给若干个线段,保证线段端点不重合,问每个线段内部包含了多少个线段. 方法是对所有线段的端点 ...
- CodeForces 540E - Infinite Inversions(离散化+树状数组)
花了近5个小时,改的乱七八糟,终于A了. 一个无限数列,1,2,3,4,...,n....,给n个数对<i,j>把数列的i,j两个元素做交换.求交换后数列的逆序对数. 很容易想到离散化+树 ...
- Educational Codeforces Round 10 D. Nested Segments 离线树状数组 离散化
D. Nested Segments 题目连接: http://www.codeforces.com/contest/652/problem/D Description You are given n ...
- Educational Codeforces Round 10 D. Nested Segments 【树状数组区间更新 + 离散化 + stl】
任意门:http://codeforces.com/contest/652/problem/D D. Nested Segments time limit per test 2 seconds mem ...
- CodeForces-652D:Nested Segments(树状数组+离散化)
You are given n segments on a line. There are no ends of some segments that coincide. For each segme ...
- D. Nested Segments(树状数组、离散化)
题目链接 参考博客 题意: 给n个线段,对于每个线段问它覆盖了多少个线段. 思路: 由于线段端点是在2e9范围内,所以要先离散化到2e5内(左右端点都离散化了,而且实际上离散化的范围是4e5),然后对 ...
- codeforces 652D . Nested Segments 线段树
题目链接 我们将线段按照右端点从小到大排序, 如果相同, 那么按照左端点从大到小排序. 然后对每一个l, 查询之前有多少个l比他大, 答案就是多少.因为之前的r都是比自己的r小的, 如果l还比自己大的 ...
- Code Forces 652D Nested Segments(离散化+树状数组)
Nested Segments time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...
- HDU 5862 Counting Intersections(离散化+树状数组)
HDU 5862 Counting Intersections(离散化+树状数组) 题目链接http://acm.split.hdu.edu.cn/showproblem.php?pid=5862 D ...
随机推荐
- 安装Apache Web 服务器软件
Apache下载地址:http://pan.baidu.com/s/1kTKCEOn 1: 右击安装 2: 3: 4: 5:安装成功: 6:测试在浏览器地址栏输入:localhost; 会出现一个页面 ...
- 002.TPerlRegEx简单测试
我要做什么? 将一个字符串中的所有连续的数字替换成一个* 代码: program Project1; {$APPTYPE CONSOLE} uses System.SysUtils, PerlRegE ...
- __sync_fetch_and_add
最近在公司离职的前辈写的代码哪里看到了__sync_fetch_and_add这个东东.比较好奇.找些资料学习学习 http://www.lxway.com/4091061956.htm http:/ ...
- Windows常用CMD命令
远程桌面:mstsc 记事本:notepad 写字板:write 计算器:calc IIS重启:iisreset 60秒倒计时关机命令:tsshutdn 15秒关机:rononc ...
- sencha architect/sencha touch , to prevent breakpoint lost when you debug
add this to your loader config: Ext.Loader.setConfig({ disableCaching: false }); or : click 'applica ...
- windows store app search contract
代码如下: html: <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> ...
- 领域驱动设计和实践(转:http://kb.cnblogs.com/page/112298/)
引言 软件系统面向对象的设计思想可谓历史悠久,20世纪70年代的Smalltalk可以说是面向对象语言的经典,直到今天我们依然将这门语言视为面向对象语言的基础.随着编程语言和技术的发展,各种语言特性层 ...
- 使用Yeoman搭建 AngularJS 应用 (3) —— 让我们搭建一个网页应用
原文地址:http://yeoman.io/codelab/setup.html 与Yeoman的交互大多数是通过命令行.在苹果机器需要使用Terminal应用,在Linux使用shell.如果使用W ...
- Java OCR tesseract 图像智能字符识别技术 Java实现
Java OCR tesseract 图像智能字符识别技术 Java代码实现 接着上一篇OCR所说的,上一篇给大家介绍了tesseract 在命令行的简单用法,当然了要继承到我们的程序中,还是需要代码 ...
- Windows 2008 故障转移群集介绍
转载:http://dufei.blog.51cto.com/382644/902026 今天有客户问起Windows 群集的相关内容,毕竟Windows Server2008所支持的群集技术和Win ...