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 findVIewById()在线生成工具
今天突然发现一个好工具,能够依据你输入的XML布局文件,自己主动生成findViewById的代码.还支持android annotation的注解方式.真是太棒了.由于我正是使用androidann ...
- 微软Build2016:Xamarin杂记
去年的Build2015技术大会.留给人印象最深的莫过是Windows 10在手机端.PC端.Xbox等硬件平台上的大一统.还有非常具有科幻气质的HoloLens技术的各种展示.去年尽管也展示了Xam ...
- qt之旅-1纯手写Qt界面
通过手写qt代码来认识qt程序的构成,以及特性.设计一个查找对话框.以下是设计过程 1 新建一个empty qt project 2 配置pro文件 HEADERS += \ Find.h QT += ...
- autofac如何注册静态方法里的接口对象
标题可能是不准确的,因为我不知道如何描述.不知道的原因,是对依赖注入一知半解. Autofac可以自动注册对象实例到接口,人所尽知.而在asp.net mvc中,这个实例化的工作,通常在每个控制器的构 ...
- python set dict tuple and list
1 set 1.1 不变集合,frozenset 也就是说,集合中的元素不能删除,也不能增加. 1.2 两个集合之间的关系 isdisjoint()函数. 2 各个数据结构的不同显示 2.1 set ...
- ABAP 检查全角半角
check全角or半角的方法 第一种方法SJIS_DBC_TO_SBC 全角转半角 SJIS_SBC_TO_DBC 半角转换为全角 设定 import all =xtext = 文本全角-〉半角,返回 ...
- HDU1069 Monkey and Banana —— DP
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=1069 Monkey and Banana Time Limit: 2000/1000 MS ...
- 函数,#include <>和#include " "区别
l 4..函数定义到使用分三步:1.声明.2.定义函数.3.调用函数. 2.函数的定义格式:返回值 函数名(形参列表){ 函数体; return } 命名规则:1.只能由字母.数字.下划线或者美元符号 ...
- bzoj 4571 美味 —— 主席树
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4571 区间找异或值最大,还带加法,可以用主席树: 可以按位考虑,然后通过加上之前已经有的答案 ...
- bzoj4720
期望dp n久以前做过,再做一遍 你只能决定决策,不能决定结果,这是这道题的关键,因为我们换了教室不一定成功,所以我们应该这样设dp状态,dp[i][j][k],第i天,换j次,换没换,转移: dp[ ...