题意:给你若干个区间,询问每个区间包含几个其它区间

分析:区间范围比较大,然后离散化,按右端点排序,每次更新树状数组中的区间左端点,查询区间和

注:(都是套路)

#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 离散化+树状数组的更多相关文章

  1. CF Educational Codeforces Round 10 D. Nested Segments 离散化+树状数组

    题目链接:http://codeforces.com/problemset/problem/652/D 大意:给若干个线段,保证线段端点不重合,问每个线段内部包含了多少个线段. 方法是对所有线段的端点 ...

  2. CodeForces 540E - Infinite Inversions(离散化+树状数组)

    花了近5个小时,改的乱七八糟,终于A了. 一个无限数列,1,2,3,4,...,n....,给n个数对<i,j>把数列的i,j两个元素做交换.求交换后数列的逆序对数. 很容易想到离散化+树 ...

  3. Educational Codeforces Round 10 D. Nested Segments 离线树状数组 离散化

    D. Nested Segments 题目连接: http://www.codeforces.com/contest/652/problem/D Description You are given n ...

  4. 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 ...

  5. CodeForces-652D:Nested Segments(树状数组+离散化)

    You are given n segments on a line. There are no ends of some segments that coincide. For each segme ...

  6. D. Nested Segments(树状数组、离散化)

    题目链接 参考博客 题意: 给n个线段,对于每个线段问它覆盖了多少个线段. 思路: 由于线段端点是在2e9范围内,所以要先离散化到2e5内(左右端点都离散化了,而且实际上离散化的范围是4e5),然后对 ...

  7. codeforces 652D . Nested Segments 线段树

    题目链接 我们将线段按照右端点从小到大排序, 如果相同, 那么按照左端点从大到小排序. 然后对每一个l, 查询之前有多少个l比他大, 答案就是多少.因为之前的r都是比自己的r小的, 如果l还比自己大的 ...

  8. Code Forces 652D Nested Segments(离散化+树状数组)

     Nested Segments time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...

  9. HDU 5862 Counting Intersections(离散化+树状数组)

    HDU 5862 Counting Intersections(离散化+树状数组) 题目链接http://acm.split.hdu.edu.cn/showproblem.php?pid=5862 D ...

随机推荐

  1. 转载:mysql 对于百万 千万级数据的分表实现方法

    一般来说,当我们的数据库的数据超过了100w记录的时候就应该考虑分表或者分区了,这次我来详细说说分表的一些方法.目前我所知道的方法都是MYISAM的,INNODB如何做分表并且保留事务和外键,我还不是 ...

  2. 腾讯视频嵌入手机端网站demo - 就像微信文章中一样一样的

    页面中的调用如下: <iframe id="video_iframe" class="video_iframe" src="TenVideoPl ...

  3. 关于css中overflow:hidden的使用

    overflow:hidden有两个用处经常用到: 1.通过设定自身的高度,加上overflow:hidden可以隐藏超过容器本身的内容:     但是,小编在以往的使用中,发现了一个问题,只要父级容 ...

  4. 修改ECSHOP,支持图片云存储化(分离到专用图片服务器)

    为了提高页面加载速度和适应中国复杂的网络环境,我决定把所有商品图片都分离到专业的云存储服务器上,具有CDN加速功能. 首先,生成一个域名 img.xxxx.com 并映射到自己的云存储别名,然后把全部 ...

  5. Python自省学习

    1. 访问对象的属性 class MyClass(): a=' b=' def __init__(self): pass def write(self): print self.a,self.b my ...

  6. SQL sum case when then else【转】

    数据库 t 表     b 表内容        Id        Name      胜负        1          张三     胜        2          李四     ...

  7. Vijos p1165 火烧赤壁 离散化+单调栈

    题目链接:https://vijos.org/p/1165 题意:输入n(n <= 20,000)段线段的端点,问所有线段的长度总和为多少? input: -1 1 5 11 2 9 outpu ...

  8. 我的PHP之旅--PHP的函数初步认识

    函数 函数主要是将一块代码封装起来方便多次使用,方便以后维护,节省代码. 先看一个简单的函数: <?php function myFirstFunc(){ echo "Hello PH ...

  9. HTML5-canvas实例:刮刮乐游戏

    实现方法: (1)利用canvas画布,fillRect()描绘出一个矩形(不是透明),定位盖在某个标签如div上面(这个标签写着中奖的信息) (2)globalCompositeOperation ...

  10. Fast CGI 工作原理

    http://www.cppblog.com/woaidongmao/archive/2011/06/21/149092.html 一.FastCGI是什么? FastCGI是语言无关的.可伸缩架构的 ...