不存在-1的情况,而且最多一轮就结束了。如果新增加的黑点v0会产生新的黑点v1,那么v0和v1肯定是在一条轴上的,而原来这条轴上已经有黑点了。

离散以后扫描线统计,往线段上插点,然后查询区间上点数。

不妨以x为主轴,用一条条平行于y轴的线去扫。

按照x为主y为副排序以后,记录下标,将下标按y为主排序,为的是把y相同的一系列点变成一个入点(d[id] = 1),一个出点(d[id] = -1),

可能某个相同y值的点只有一个,所以最后的出点 -= 1。

点可能有重复,判重的话就标记一下平行x轴的线。

/*********************************************************
* ------------------ *
* author AbyssalFish *
**********************************************************/
#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<queue>
#include<vector>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<cmath>
#include<numeric>
using namespace std; const int maxn = 1e5; typedef long long ll;
typedef pair<int,int> Point;
#define xc first
#define yc second
Point p[maxn];
int ys[maxn], d[maxn]; //discrete y, scan line
int n;
int r[maxn]; bool cmp(int a,int b)
{
return p[a].yc < p[b].yc || (p[a].yc == p[b].yc && p[a].xc < p[b].xc);
} int C[maxn+], n0;
bool vis[maxn+]; int sum(int x)
{
int re = ;
while(x > ){
re += C[x]; x &= x-;
}
return re;
} void add(int x,int d)
{
while(x <= n0){
C[x] += d;
x += x&-x;
}
} void solve()
{
for(int i = ; i < n; i++){
scanf("%d%d",&p[i].xc,&p[i].yc);
r[i] = i;
}
//compress
sort(p,p+n);
sort(r,r+n,cmp);
ys[r[]] = ; d[r[]] = ;
for(int i = ; i < n; i++){
ys[r[i]] = ys[r[i-]];
if(p[r[i]].yc != p[r[i-]].yc) {
d[r[i-]] -= ;
ys[r[i]]++;
d[r[i]] = ;
}
}
n0 = ys[r[n-]];
d[r[n-]] -= ;
//memset(C+1,0,sizeof(int)*n0); ll ans = n;
for(int i = , j; i < n;){
j = i;
while(j < n && p[j].xc == p[i].xc) { //不包含端点
if(d[j] < ) {
vis[ys[j]] = false;
add(ys[j], -);
}
j++;
}
if(ys[i] < ys[j-]-) {
ans += sum(ys[j-]-) - sum(ys[i]);
for(int k = i+; k < j-; k++){ //去重
if(vis[ys[k]]) ans--;
}
}
while(i < j) {
if(d[i] > ) {
add(ys[i],);
vis[ys[i]] = true;
}
i++;
}
}
printf("%I64d\n", ans);
} //#define LOCAL
int main()
{
#ifdef LOCAL
freopen("in.txt","r",stdin);
#endif
scanf("%d", &n);
solve();
return ;
}

POJ - 3109 Inner Vertices的更多相关文章

  1. POJ 2109 Inner Vertices(扫描线+树状数组)

    [题目链接] http://poj.org/problem?id=3109 [题目大意] 在一个棋盘上放满白子,现在把一些白子变成黑子, 如果一个白子上下左右都有黑子,就会变成黑子,问最终黑子个数 [ ...

  2. poj 3109

                                                                                                         ...

  3. poj很好很有层次感(转)

    OJ上的一些水题(可用来练手和增加自信) (POJ 3299,POJ 2159,POJ 2739,POJ 1083,POJ 2262,POJ 1503,POJ 3006,POJ 2255,POJ 30 ...

  4. POJ题目分类推荐 (很好很有层次感)

    著名题单,最初来源不详.直接来源:http://blog.csdn.net/a1dark/article/details/11714009 OJ上的一些水题(可用来练手和增加自信) (POJ 3299 ...

  5. 计算几何--求凸包模板--Graham算法--poj 1113

    Wall Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 28157   Accepted: 9401 Description ...

  6. poj 1113:Wall(计算几何,求凸包周长)

    Wall Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 28462   Accepted: 9498 Description ...

  7. 【POJ】1113 Wall(凸包)

    http://poj.org/problem?id=1113 答案是凸包周长+半径为l的圆的周长... 证明?这是个坑.. #include <cstdio> #include <c ...

  8. 【POJ】2954 Triangle(pick定理)

    http://poj.org/problem?id=2954 表示我交了20+次... 为什么呢?因为多组数据我是这样判断的:da=sum{a[i].x+a[i].y},然后!da就表示没有数据了QA ...

  9. poj 1179 Polygon

    http://poj.org/problem?id=1179 Polygon Time Limit: 1000MS   Memory Limit: 10000K Total Submissions:  ...

随机推荐

  1. chrome插件 crap jsonview

    最近有用到几个非常好用的Chrome  记录一下: 1.Crap Api debug,直接在Chrome标签打开的,界面大概长这样,方便调试 2. adblock 比较大众 3. tampermonk ...

  2. C++容器嵌套实现动态二维数组(Vector2D)

    转: http://blog.csdn.net/Touch_Dream/article/details/74931891 #include<stdio.h> #include <io ...

  3. robotFramework接口测试GET和POST请求

    安装: 接口测试需要安装Request和RequestLibrary 包 使用cmd命令安装:pip install requests 使用cmd命令安装:pip install -U robotfr ...

  4. 查看Python支持的.whl文件版本

    AMD64 import pip._internal print(pip._internal.pep425tags.get_supported()) WIN32 import pip print(pi ...

  5. [转]jQueryUI中Datepicker(日历)插件的介绍和使用

    http://jqueryui.com/datepicker/ 本文转自:http://blog.csdn.net/redarmy_chen/article/details/7400571 jQuer ...

  6. My first Python program(附增加清屏方法)

    #TempConvert.py TempStr = input("请输入带有符号的温度值:") if TempStr[-1] in ['F', 'f']: C = (eval(Te ...

  7. ASP.NET中多语言的实现

    一个网站可能具备多个语言,要实现这个功能在ASP.NET中是非常简单的.我们需要为项目添加资源文件文件夹,并且添加针对网站的特定的资源文件等即可.在ASP.NET中资源文件分成两类:全局和页面级(即“ ...

  8. 关于get_magic_quotes_gpc()函数(交互数据转义的判断)

    在PHP中get_magic_quotes_gpc()函数是内置的函数,这个函数的作用就是得到php.ini设置中magic_quotes_gpc选项的值. 那么就先说一下magic_quotes_g ...

  9. jQuery 3 有哪些新东西

    jQuery 的横空出世,至今已有十个年头了,而它的长盛不衰显然不是没有理由的.jQuery 提供了极为友好的接口,使得开发者们可以方便地进行 DOM 操作.发起 Ajax 请求.生成动画……不一而足 ...

  10. Servlet细节整合

    最近在复习Servlet,发现其中有很多细节方面的东西都没有接触到,只是学了大概 1.请求转发和请求重定向的区别 2.输入参数为中文时候的乱码问题 3.Web工程中的目录写法 下面分别阐述 1.请求转 ...