Educational Codeforces Round 10 D.Nested Segments
来源:互联网 发布:有什么网络兼职的 编辑:程序博客网 时间:2024/05/23 20:08
题意:给你n条线段(n<=2*10^5),每条线段一个[l,r],代表他的左右区间,输出对于每条线段,有多少条线段能被他完全覆盖。
思路:对r进行离散化,然后按L对查询从大到小进行排序,对每个r查询小于等于他的r有多少个
(树状数组求前缀和)
#include <map>#include <set>#include <stack>#include <queue>#include <cmath>#include <ctime>#include <vector>#include <cstdio>#include <cctype>#include <cstring>#include <cstdlib>#include <iostream>#include <algorithm>using namespace std;#define INF 0x3f3f3f3f#define inf -0x3f3f3f3f#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1#define mem0(a) memset(a,0,sizeof(a))#define mem1(a) memset(a,-1,sizeof(a))#define mem(a, b) memset(a, b, sizeof(a))typedef __int64 ll;const int maxn=200100;int C[maxn],Hash[maxn*2],ans[maxn];struct Point{ int x,y,id;}a[maxn];int n;bool cmp(Point u,Point v){ if(u.x!=v.x) return u.x>v.x; return u.y>v.y;}void add(int x){ while(x<=n){ C[x]+=1; x+=(x&-x); }}int sum(int x){ int ret=0; while(x>0){ ret+=C[x]; x-=(x&-x); } return ret;}int main(){ int tot=0; scanf("%d",&n); for(int i=1;i<=n;i++){ scanf("%d%d",&a[i].x,&a[i].y); a[i].id=i; Hash[++tot]=a[i].y; } sort(Hash+1,Hash+tot+1); int m=unique(Hash+1,Hash+tot+1)-Hash; for(int i=1;i<=n;i++) a[i].y=lower_bound(Hash+1,Hash+m,a[i].y)-Hash; sort(a+1,a+n+1,cmp); for(int i=1;i<=n;i++){ ans[a[i].id]=sum(a[i].y); add(a[i].y); } for(int i=1;i<=n;i++) printf("%d\n",ans[i]); return 0;}
0 0
- Educational Codeforces Round 10 D. Nested Segments
- Educational Codeforces Round 10 D Nested Segments
- Educational Codeforces Round 10 D.Nested Segments
- Educational Codeforces Round 10-D. Nested Segments
- 初识树状数组 Educational Codeforces Round 10 D - Nested Segments
- Educational Codeforces Round 10 D. Nested Segments 离散化+树状数组
- 【Educational Codeforces Round 10D】【树状数组】Nested Segments 每条线段内部有多少条线段
- Educational Codeforces Round 4 D. The Union of k-Segments
- Educational Codeforces Round 4-D. The Union of k-Segments
- codeforces 652D Nested Segments
- Codeforces 612D Educational Codeforces Round 4 D. The Union of k-Segments 离散化+map
- CodeForces 652D Nested Segments 树状数组
- CodeForces D. Nested Segments【逆序对类型】
- Educational Codeforces Round 4 612D The Union of k-Segments(stl)
- Educational Codeforces Round 4 D. The Union of k-Segments(★)
- Educational Codeforces Round 4 D The Union of k-Segments (扫描线)
- Educational Codeforces Round 21-D
- Educational Codeforces Round 5 D
- 263. Ugly Number
- 51nod1417 天堂里的游戏
- Java native interface(二)
- Sharepoint 2013的WSP方案双机部署
- 如何分辨拷贝构造函数和赋值操作符两种操作
- Educational Codeforces Round 10 D.Nested Segments
- Windows中的SID详解
- Jenkins如何构建下一个job
- 抓取网站数据不再是难事了,Fizzler(So Easy)全能搞定
- Android动画(Animation)初识
- OVS重装
- tomcat 部署项目,不加项目名 直接访问
- POJ 2828 Buy Tickets(多校连萌,线段树模拟插入)
- slice()、substr()、subString()使用及区别