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,长 ...
随机推荐
- cell.getCellType有几种
CellType 类型 值CELL_TYPE_NUMERIC 数值型 0CELL_TYPE_STRING 字符串型 1CELL_TYPE_FORMULA 公式型 2CELL_TYPE_BLANK 空值 ...
- Spring事物注意事项
一.尽量用注解声明事务 过去开发喜欢用tx:advice+aop命名空间方式来配置事务,一次配置对满足切点规则的方法永久生效.但也可能因此导致事务滥用,在不需要用到事务的地方用了会影响系统的并发性能. ...
- bzoj1426 (洛谷P4550) 收集邮票——期望
题目:https://www.luogu.org/problemnew/show/P4550 推式子……:https://blog.csdn.net/pygbingshen/article/detai ...
- CodeForces 722A Broken Clock (水题)
题意:给定一个时间,然后改最少的数字,使得它成为12进制或者24进制. 析:24进制主要判是不是大于23,如果是把第一位变成0,12进制判是不是大于12,如果是再看第二位是不是0,是0,第一位变成1, ...
- Swift4 基本数据类型(范围型, Stride型, 数组, 字符串, 哈希表)
创建: 2018/02/28 完成: 2018/03/04 更新: 2018/05/03 给主要标题加上英语, 方便页内搜索 [任务表]TODO 范围型(Range)与Stride型 与范围运算符相 ...
- bzoj 4951: [Wf2017]Money for Nothing【分治】
参考:https://blog.csdn.net/herobrine_tkj/article/details/78404426?locationNum=8&fps=1 为什么从1开始存就挂了, ...
- bzoj 1502 月下柠檬树【Simpson积分】
投影到地面之后,会发现圆形在平行光下面积和形状是不会变的,也就是所要求的图形是若干个圆和把相邻两个圆连起来的公切线所组成的. 公切线和圆间距瞎求一下就行,注意要去掉被完全覆盖的圆 然后simpson即 ...
- pytest特色与实用插件
pytest特色 1.fixture的特点 fixture是pytest特有的功能,其特点如下: 必须用pytest.fixture装饰器装饰:fixture有明确的名字,在其他函数(function ...
- AutoCAD2012启动错误 1308 源文件未找到
启动AutoCAD2012时,弹出错误1308,如图所示: 是何原因? 对CAD的运行有何影响?
- redis问题集结
redis和memcached比较? redis中数据库默认是多少个db 及作用? python操作redis的模块? 如果redis中的某个列表中的数据量非常大,如果实现循环显示每一个值? redi ...