POJ-3109-Inner Vertices
来源:互联网 发布:h5免费制作网站 知乎 编辑:程序博客网 时间:2024/06/05 13:26
这个题参考了下http://www.hankcs.com/program/algorithm/poj-3109-inner-vertices.html,方法也差不多。发现扫描线还有这样的用法~
代码:
#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>#include<vector>using namespace std;const int inf=1<<29;const int maxn=2e5+100;struct Point{ int x; int y; bool operator < (const Point &a)const { if(y==a.y) return x<a.x; return y<a.y; }}a[maxn];int n,cnt,p[maxn],t[maxn];bool isr[maxn],isl[maxn],vis[maxn];int lowbit(int x){ return x&(-x);}void Update(int x,int val){ for(;x<maxn;t[x]+=val,x+=lowbit(x));}int Sum(int x){ long long ans=0; for(;x>0;ans+=t[x],x-=lowbit(x)); return ans;}void Init(){ memset(t,0,sizeof(t)); sort(p,p+cnt); cnt=unique(p,p+cnt)-p; for(int i=0;i<n;i++) { a[i].x=lower_bound(p,p+cnt,a[i].x)-p+1; a[i].y=lower_bound(p,p+cnt,a[i].y)-p+1; } sort(a,a+n); memset(vis,0,sizeof(vis)); for(int i=0;i<n;i++) { if(!vis[a[i].x]) { isl[i]=1; vis[a[i].x]=1; } else isl[i]=0; } memset(vis,0,sizeof(vis)); for(int i=n-1;i>=0;i--) { if(!vis[a[i].x]) { isr[i]=1; vis[a[i].x]=1; } else isr[i]=0; }}void solve(){ long long ans=0; for(int i=0;i<n;) { int j=i; while(j<n-1&&a[j+1].y==a[j].y) j++; for(int k=i;k<=j;k++) if(!isl[k]&&isr[k]) Update(a[k].x,-1); if(i!=j) ans+=Sum(a[j].x-1)-Sum(a[i].x); if(i<j) for(int k=i+1;k<j;k++) if(!isl[k]&&!isr[k]) ans--; while(i<=j) { if(isl[i]&&!isr[i]) Update(a[i].x,1); i++; } } printf("%I64d\n",ans+n);}int main(){ while(scanf("%d",&n)!=EOF) { cnt=0; for(int i=0;i<n;i++) { scanf("%d%d",&a[i].x,&a[i].y); p[cnt++]=a[i].x; p[cnt++]=a[i].y; } Init(); solve(); } return 0;}
0 0
- POJ-3109-Inner Vertices
- POJ - 3109Inner Vertices
- poj 3109 Inner Vertices
- poj 3109 Inner Vertices(树状数组)
- POJ 3109 Inner Vertices 树状数组
- POJ 3109 Inner Vertices(线段树)
- POJ 3109 Inner Vertices 已翻译
- poj 3109 Inner Vertices 树状数组+离散化
- POJ3109-Inner Vertices
- poj3109 Inner Vertices(树状数组)
- poj3109 Inner Vertices 扫描线+树状数组
- POJ3109-Inner Vertices-离散化+扫描线
- vertices
- Happy Vertices
- D3D9 Samples(2)--Vertices
- UVa209 - Triangular Vertices(几何)
- 顶点缓存Vertices
- CodeForces 293EClose Vertices
- 【爱上Java8】一步一步走进 java8 lambda表达式
- Codeforces Round #261 (Div. 2) D. Pashmak and Parmida's problem(树状数组+逆序数对)
- Leetcode练习- Unique Binary Search Tree
- VC调试
- linux守护进程编程
- POJ-3109-Inner Vertices
- StringBuffer
- 【爱上Java8】Java8函数式方法的方法引用
- hdu1548BFS
- 基于统计语言模型的拼音输入法
- 利用正则表达式处理字符
- Trie树(字典树)poj3630+hdu1671
- 做个JAVA 8的调查?
- poj 3261 Milk Patterns