思路:

树状数组 + 扫描线。

实现:

 #include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
const int MAXN = ;
int x[MAXN], y[MAXN], bit[MAXN], cnt[MAXN], now[MAXN], n;
bool vis[MAXN];
vector<int> lines[MAXN];
int lowbit(int x) { return x & -x; }
void add(int i, int x)
{
while (i <= MAXN) { bit[i] += x; i += lowbit(i); }
}
int sum(int i)
{
int ans = ;
while (i) { ans += bit[i]; i -= lowbit(i); }
return ans;
}
int compress(int * a)
{
vector<int> v(a, a + n);
sort(v.begin(), v.end());
v.erase(unique(v.begin(), v.end()), v.end());
for (int i = ; i < n; i++) a[i] = lower_bound(v.begin(), v.end(), a[i]) - v.begin() + ;
return v.size();
}
int main()
{
scanf("%d", &n);
for (int i = ; i < n; i++) scanf("%d %d", x + i, y + i);
int X = compress(x), Y = compress(y);
for (int i = ; i < n; i++) { lines[x[i]].push_back(y[i]); cnt[y[i]]++; }
int ans = ;
for (int i = ; i <= X; i++)
{
sort(lines[i].begin(), lines[i].end());
for (int j = ; j < lines[i].size() - ; j++) ans += sum(lines[i][j + ] - ) - sum(lines[i][j]);
for (int j = ; j < lines[i].size(); j++)
{
int tmp = lines[i][j];
if (!vis[tmp]) { vis[tmp] = true; add(tmp, ); }
now[tmp]++;
if (now[tmp] == cnt[tmp]) add(tmp, -);
}
}
printf("%d\n", ans + n);
return ;
}

poj3109 Inner Vertices的更多相关文章

  1. dataStructure@ Find if there is a path between two vertices in a directed graph

    Given a Directed Graph and two vertices in it, check whether there is a path from the first given ve ...

  2. cf293E Close Vertices(树分治+BIT)

    E. Close Vertices You've got a weighted tree, consisting of n vertices. Each edge has a non-negative ...

  3. atcoder NIKKEI Programming Contest 2019 E - Weights on Vertices and Edges

    题目链接:Weights on Vertices and Edges 题目大意:有一个\(n\)个点\(m\)条边的无向图,点有点权,边有边权,问至少删去多少条边使得对于剩下的每一条边,它所在的联通块 ...

  4. Maya cmds filterExpand 列出 选择的 uvs vertices faces edges 等 component 类型

    Maya cmds filterExpand 列出 选择的 uvs vertices faces edges 等 component 类型 cmds.ls() 的 flags 中没有指明 uvs 等这 ...

  5. [CC-BLREDSET]Black and Red vertices of Tree

    [CC-BLREDSET]Black and Red vertices of Tree 题目大意: 有一棵\(n(\sum n\le10^6)\)个结点的树,每个结点有一种颜色(红色.黑色.白色).删 ...

  6. codeforces 293E Close Vertices

    题目链接 正解:点分治+树状数组. 点分治板子题,直接点分以后按照$w$排序,扫指针的时候把$w$合法的路径以$l$为下标加入树状数组统计就行了. 写这道题只是想看看我要写多久..事实证明我确实是老年 ...

  7. Interesting Vertices

    Interesting Vertices(前向星+思维+dfs回溯) 参考博客:https://blog.csdn.net/I_believe_CWJ/article/details/10247201 ...

  8. openmesh - impl - Remove Duplicated Vertices

    openmesh - impl - Remove Duplicated Vertices 关于openmesh元素删除实现的介绍参见:openmesh - src - trimesh delete a ...

  9. CF 293 E Close Vertices (树的分治+树状数组)

    转载请注明出处,谢谢http://blog.csdn.net/ACM_cxlove?viewmode=contents    by---cxlove 题目:给出一棵树,问有多少条路径权值和不大于w,长 ...

随机推荐

  1. Python爬虫开发【第1篇】【Scrapy框架】

    Scrapy 框架介绍 Scrapy是用纯Python实现一个为了爬取网站数据.提取结构性数据而编写的应用框架. Srapy框架,用户只需要定制开发几个模块就可以轻松的实现一个爬虫,用来抓取网页内容以 ...

  2. windows内存管理的机制以及优缺点

    分页存储管理基本思想:用户程序的地址空间被划分成若干固定大小的区域,称为“页”,相应地,内存空间分成若干个物理块,页和块的大小相等.可将用户程序的任一页放在内存的任一块中,实现了离散分配. 分段存储管 ...

  3. .NET的委托和匿名函数应用一例

    闲话休提,大家都是成年人,直接上代码.有代码有J8: delegate string dlgGetTotal(); void TongJi() { dlgGetTotal getTotalInt = ...

  4. http的session和cookie

    1 http session和http请求之间的关系 http协议是无状态的,一次会话服务端需要处理多次http请求,就算是长连接,也是要发送多次请求的,由于http无状态所有每次的请求都是独立的,服 ...

  5. CXF+Spring+Tomcat 案例

    多系统(异构系统)进行交互时,一种良好的方式便是调用Web Service,本示例基于Apache组织的CXF 环境:EclipseJDK6Tomcat6CXF2.6.1Spring3 示例项目结构图 ...

  6. codeforces 739E - Gosha is hunting

    这道题有三种做法,感受一下: 感觉到了歪果仁费尽脑汁想出来的神仙贪心脑洞题被中国人套路算法踩爆的凄凉...(我的名字是不是暴露了我的真实实力) ============================ ...

  7. YTU 2915: Shape系列-1

    2915: Shape系列-1 时间限制: 1 Sec  内存限制: 128 MB 提交: 283  解决: 221 题目描述 小强开始迷恋彩色的Shape,于是决定做一个Shape类.Shape类有 ...

  8. HubbleDotNet 开源全文搜索数据库项目--为数据库现有表或视图建立全文索引(三) 多表关联全文索引模式

    关系型数据库中,多表关联是很常见的事情,HubbleDotNet 可以对部分情况的多表关联形式建立关联的全文索引,这样用户就不需要专门建一个大表 来解决多表关联时的全文索引问题. 下面以 为数据库现有 ...

  9. ios app 上架AppStore

    一.证书的导出      1.1 前期工作        首先你需要有一个苹果的开发者帐号,一个Mac系统.        如果没有帐号可以在打开http://developer.apple.com/ ...

  10. Git 仓库结构 (一)***

    Git 仓库      1.1Git 基本概念    在Git中,我们将需要进行版本控制的文件目录叫做一个仓库(repository),每个仓库可以简单理解成一个目录,这个目录里面的所有文件都通过Gi ...