题目传送门

题解:

可以将所有线段按照左端点优先小,其次右端点优先大进行排序。

然后对于第 i 条线段来说, 那么第 i+1 ---- n 的线段左端点都一定在第i条线段的右边, 接下来就需要知道 i+1 ---- n 中的这些线段有多少条的右端点是在第 i 条线段的右端点的左边。

可以通过一个树状数组来维护一个右端点的前缀合。

当我门处理第i条线段的时候, 先将第i条线段的右端点从树状数组里面删除,然后在询问在 r 之前有多少个右端点就是相应的答案了。

代码:

/*
code by: zstu wxk
time: 2019/02/23
*/
#include<bits/stdc++.h>
using namespace std;
#define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout);
#define LL long long
#define ULL unsigned LL
#define fi first
#define se second
#define pb push_back
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define lch(x) tr[x].son[0]
#define rch(x) tr[x].son[1]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
const int inf = 0x3f3f3f3f;
const int _inf = 0xc0c0c0c0;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const LL _INF = 0xc0c0c0c0c0c0c0c0;
const LL mod = (int)1e9+;
const int N = 5e5 + ;
struct Node{
int l, r, id;
bool operator< (const Node & x) const{
if(l == x.l) return r > x.r;
return l < x.l;
}
}A[N];
int b[N];
int k = , n;
int F(int x){
return lower_bound(b+, b++k, x) - b;
}
int tree[N];
void Updata(int x, int c){
while(x <= k){
tree[x] += c;
x += x & (-x);
}
return ;
}
int Query(int x){
int ret = ;
while(x > ){
ret += tree[x];
x -= x & (-x);
}
return ret;
}
int ans[N];
void Ac(){
for(int i = ; i <= n; ++i){
scanf("%d%d", &A[i].l, &A[i].r);
A[i].id = i;
b[++k] = A[i].l;
b[++k] = A[i].r;
}
sort(A+, A++n);
sort(b+, b++k);
k = unique(b+, b++k) - (b+);
for(int i = ; i <= n; ++i)
Updata(F(A[i].r), );
for(int i = ; i <= n; ++i){
Updata(F(A[i].r), -);
ans[A[i].id] = Query(F(A[i].r));
}
for(int i = ; i <= n; ++i)
printf("%d\n", ans[i]);
}
int main(){
while(~scanf("%d", &n)){
Ac();
}
return ;
}

CF - 652 D Nested Segments的更多相关文章

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

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

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

  3. ural1987 Nested Segments

    Nested Segments Time limit: 1.0 secondMemory limit: 64 MB You are given n segments on a straight lin ...

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

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

  5. codeforces 652D D. Nested Segments(离散化+sort+树状数组)

    题目链接: D. Nested Segments time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  6. Educational Codeforces Round 10 D. Nested Segments

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

  7. D - Nested Segments CodeForces - 652D (离散化+树桩数组)

    D - Nested Segments CodeForces - 652D You are given n segments on a line. There are no ends of some ...

  8. [离散化+树状数组]CodeForces - 652D Nested Segments

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

  9. Codeforces 976C Nested Segments

    题面: 传送门 C. Nested Segments Input file: standard input Output file: standard output Time limit: 2 secon ...

随机推荐

  1. 【Python-Django】浏览器同源策略

    1995年,同源政策由 Netscape 公司引入浏览器.目前,所有浏览器都实行这个政策. 同源策略是浏览器的一个安全功能,不同源的客户端脚本(js文件)在没有明确授权的情况下,不能读写对方资源.只有 ...

  2. 10个常用的linux的命令

    以下就是今天我们要介绍的Linux命令:  man  touch, cat and less  sort and grep  cut  sed  tar  find  diff  uniq  chmo ...

  3. 使用 OpenSSL 为 Nginx 创建自签名证书 并开启客户端身份验证

    本文章默认读者了解Openssl,CA,网站证书相关知识,直接实战!配置完成后,浏览器会显示"安全的HTTPS"连接.不会像其他文章那样,是红色警告的证书提示. 准备环境 笔者使用 ...

  4. oracle 正确删除归档日志,并清除 V$ARCHIVED_LOG 数据

    1. 连接 RMAN 管理 rman target / 2. 查看归档日志列表 RMAN> crosscheck archivelog all; 3. 删除所有归档日志 RMAN> DEL ...

  5. eclipse使用(一)

    使用eclipse时,编写对象的返回值非常麻烦,而使用返回值快捷键可以简化这一过程. 第一种 Alt+shift+L 将光标放在有返回值的代码句的分号后面: Resources.getResource ...

  6. win10文件备份、文件同步方案

    用个人版onedrive同步重要数据,数据安全有保障,但免费版只有15G空间,需要合理分配.(201907与别人合租家庭版,空间1T充足) google-drive可以同步指定的文件夹,但空间也只有1 ...

  7. Unable to load template file 'rj\ThinkPHP/Tpl/dispatch_jump.tpl'----thinkphp3.2.3

    Unable to load template file 'rj\ThinkPHP/Tpl/dispatch_jump.tpl'----thinkphp3.2.3 1.报错原因:将thinkphp默认 ...

  8. CEF避坑指南(一)——下载并编译第一个示例

    CEF即Chromium Embedded Framework,Chrome浏览器嵌入式框架.它提供了接口供程序员们把Chrome放到自己的程序中.许多大型公司,如网易.腾讯都开始使用CEF进行前端开 ...

  9. 前端表格数据导出excel

    使用tableExport.js导出bootstrap-table表格成excel并且支持中文 1. 下载tableExport.js https://github.com/hhurz/tableEx ...

  10. 《Java 8 in Action》Chapter 2:通过行为参数化传递代码

    你将了解行为参数化,这是Java 8非常依赖的一种软件开发模式,也是引入 Lambda表达式的主要原因.行为参数化就是可以帮助你处理频繁变更的需求的一种软件开发模式.一言以蔽之,它意味 着拿出一个代码 ...