poj3109 Inner Vertices
思路:
树状数组 + 扫描线。
实现:
#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的更多相关文章
- 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 ...
- cf293E Close Vertices(树分治+BIT)
E. Close Vertices You've got a weighted tree, consisting of n vertices. Each edge has a non-negative ...
- atcoder NIKKEI Programming Contest 2019 E - Weights on Vertices and Edges
题目链接:Weights on Vertices and Edges 题目大意:有一个\(n\)个点\(m\)条边的无向图,点有点权,边有边权,问至少删去多少条边使得对于剩下的每一条边,它所在的联通块 ...
- Maya cmds filterExpand 列出 选择的 uvs vertices faces edges 等 component 类型
Maya cmds filterExpand 列出 选择的 uvs vertices faces edges 等 component 类型 cmds.ls() 的 flags 中没有指明 uvs 等这 ...
- [CC-BLREDSET]Black and Red vertices of Tree
[CC-BLREDSET]Black and Red vertices of Tree 题目大意: 有一棵\(n(\sum n\le10^6)\)个结点的树,每个结点有一种颜色(红色.黑色.白色).删 ...
- codeforces 293E Close Vertices
题目链接 正解:点分治+树状数组. 点分治板子题,直接点分以后按照$w$排序,扫指针的时候把$w$合法的路径以$l$为下标加入树状数组统计就行了. 写这道题只是想看看我要写多久..事实证明我确实是老年 ...
- Interesting Vertices
Interesting Vertices(前向星+思维+dfs回溯) 参考博客:https://blog.csdn.net/I_believe_CWJ/article/details/10247201 ...
- openmesh - impl - Remove Duplicated Vertices
openmesh - impl - Remove Duplicated Vertices 关于openmesh元素删除实现的介绍参见:openmesh - src - trimesh delete a ...
- CF 293 E Close Vertices (树的分治+树状数组)
转载请注明出处,谢谢http://blog.csdn.net/ACM_cxlove?viewmode=contents by---cxlove 题目:给出一棵树,问有多少条路径权值和不大于w,长 ...
随机推荐
- android 浮动窗体学习笔记及个人理解(仿360手机助手)
很感谢原文作者 http://blog.csdn.net/guolin_blog/article/details/8689140 经自己理解 程序执行界面例如以下图: 1.程序入口界面 2.小浮动窗体 ...
- 密码过期导致Oracle process耗尽问题
oracle忽然连不上! 大致是报这样的错: ORA-12516: TNS: 监听程序找不到符合协议堆栈要求的可用处理程序 ORA-12520: TNS: 监听程序无法为请求的服务器类型找到可用的处理 ...
- yummain.py install yum 不能运行的原因 yummain.py not found
[root@akinlau ~] wget http://tel.mirrors.163.com/centos/6/os/x86_64/Packages/python-urlgrabber-3.9.1 ...
- uboot中关于LCD的代码分析【转】
本文转载自:http://blog.csdn.net/oqqHuTu12345678/article/details/72236117 以下内容源于朱有鹏<物联网大讲坛>课程的学习,如有侵 ...
- java中字节数组byte[]和字符(字符串)之间的转换
转自:http://blog.csdn.net/linlzk/article/details/6566124 Java与其他语言编写的程序进行tcp/ip socket通讯时,通讯内容一般都转换成by ...
- bzoj 2744 朋友圈
题目大意: 两个国家 各有A和B个人,每个人有一个数值. 若两个A国的人满足$val_i\space xor \space val_j \mod 2 =1$ 则他们为朋友 若两个B国的人满足$val_ ...
- bzoj 3481 DZY loves math —— 反演+Pollard_rho分解质因数
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3481 推式子:xy % P = Q 的个数 由于 0 <= x,y < P,所以 ...
- 搭建gerrit服务器(apache&nginx反向代理方式)
这段时间,想搭建一个gerrit,用于代码托管,gerrit的搭建,网上有很多种教程,但是自己按照别人的教程逐步操作,一直出现诸多问题.最头痛的就是:Configuration Error Check ...
- snnu1111(子序列求和)
1111: 子序列求和 Time Limit: 3 Sec Memory Limit: 64 MBSubmit: 10 Solved: 2[Submit][Status][Web Board] [ ...
- 配置DTD提示的方法
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE sqlMap PUBLIC "-/ ...