Nested Segments codeforces 652D 树状数组 +离散化
来源:互联网 发布:淘宝代销管理软件 编辑:程序博客网 时间:2024/05/23 19:19
给定n个区间,问你第i个区间包含多少个区间。
数据达到了 1e9,但是量只有2*1e5 离散化即可
一开始想着离散两边,发现不可行,因为离散化两边对真实的区间边界交集有变化 造成不好的影响
所以只能离散一个边,然后利用排序,把一个个区间添加进去,离散右边界,左边界从右到左更新,然后更新右边界,那么区间永远是是最大的那个
#include <bits/stdc++.h>using namespace std;const int maxn=2*1e5+100;#define lowbit(x) (x)&(-x)struct node{ int l,r; int id,num;}s[maxn];int tree[maxn];int num[maxn];int n;int cmp(node a,node b){ return a.l>b.l;}int cmp1(node a,node b){ return a.id<b.id;}int getid(int x){ return (lower_bound(num,num+n,x)-num);}void update(int x,int v){ while(x<n+10) { tree[x]+=v; x+=lowbit(x); }}int sum(int x){ int res=0; while(x>0) { res+=tree[x]; x-=lowbit(x); } return res;}int main(){ cin>>n; for(int i=0;i<n;i++) { scanf("%d%d",&s[i].l,&s[i].r); num[i]=s[i].r; s[i].id=i; } sort(num,num+n); for(int i=0;i<n;i++) { s[i].r=getid(s[i].r); s[i].r++; } sort(s,s+n,cmp); for(int i=0;i<n;i++) { s[i].num=sum(s[i].r); update(s[i].r,1); } sort(s,s+n,cmp1); for(int i=0;i<n;i++) { printf("%d\n",s[i].num ); }}
阅读全文
0 0
- Codeforces 652D Nested Segments 【树状数组 + 离散化】
- CodeForces 652D Nested Segments(树状数组+离散化)
- CodeForces 652D Nested Segments(离散化,树状数组)
- 【Codeforces 652 D Nested Segments】+ 树状数组 + 离散化
- Codeforces 652D Nested Segments【离散化+思维+树状数组】
- Nested Segments codeforces 652D 树状数组 +离散化
- CodeForces 652D Nested Segments(树状数组 离散化)
- Nested Segments CodeForces 652D 树状数组+离散化
- CodeForces 652D Nested Segments 树状数组
- Educational Codeforces Round 10 D. Nested Segments 离散化+树状数组
- CodeForces 652D Nested Segments (树状数组)
- Codeforces 652D Nested Segments 树状数组离线处理
- Code Forces 652D Nested Segments(离散化+树状数组)
- CodeForce 652D Nested Segments 树状数组
- 初识树状数组 Educational Codeforces Round 10 D - Nested Segments
- codeforces 652D Nested Segments
- cf#ECR10-D. Nested Segments-树状数组+二分
- 【Educational Codeforces Round 10D】【树状数组】Nested Segments 每条线段内部有多少条线段
- HTTP协议
- 幂等性的研究及后台验证短时间内同一申请是否重复提交的方案
- Kotlin学习(二)Hello Kotlin
- 网页中怎样禁止通过输入url直接访问
- C/C++使用openssl进行摘要和加密解密(md5, sha256, des, rsa)
- Nested Segments codeforces 652D 树状数组 +离散化
- 坑了,comet4j 405 居然会受 com.sun.jersey 或者 javax.ws.rs 的影响 linux
- EncodeFilter编码过滤器
- CentOS 7 安装jdk 1.8
- 人机大战第二局,柯洁中盘认输说明了什么?
- 【PAT】1052. 卖个萌 (20)
- Spring mvc Interceptor 解决Session超时配置流程
- Java-Alarm
- Linux目录-常用增删改查命令