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,长 ...
随机推荐
- 暴力破解zip文件
#coding=utf-8 """ 用户输入-z参数指定要破解的zip文件,输入-d参数输入字典文件,即可暴力破解加密的zip文件 """ ...
- (八)Java 修饰符
Java 修饰符 Java语言提供了很多修饰符,主要分为以下两类: 访问修饰符 非访问修饰符 修饰符用来定义类.方法或者变量,通常放在语句的最前端.我们通过下面的例子来说明: public class ...
- AJAX请求提交数据
1,AJAX准备知识:JSON JSON指的是JavaScript对象表示方法(JavaScript Object Notation) JSON是轻量级的文本数据交换格式 JSON独立于语言 JSON ...
- mysql12----explain
explain 可以帮助我们在不真正执行某个sql语句时,就执行mysql怎样执行,这样利用我们去分析sql指令.尽量避免全表扫描. Id: SELECT识别符.这是SELECT的查询序列号 ) \G ...
- mongo11---Access control is not enabled for the database
今天使用MongoDB时遇到了一些问题 建立数据库连接时出现了warnings 出现这个警告的原因是新版本的MongDB为了让我们创建一个安全的数据库 必须要进行验证 后来在外网找到了答案 解决方案如 ...
- URAL1099 Work Scheduling —— 一般图匹配带花树
题目链接:https://vjudge.net/problem/URAL-1099 1099. Work Scheduling Time limit: 0.5 secondMemory limit: ...
- silverlight子窗体操作数据库后刷新父窗体
silverlight子窗体操作数据库后刷新父窗体 作者 Kant 写于 2011 年 07 月 02 日 分类目录 学习笔记, 所有文章 C# Silverlight 代码 刷新 学习 异步刷新 数 ...
- 并不对劲的bzoj1861: [Zjoi2006]Book 书架
传送门-> 这题的正确做法是splay维护这摞书. 但是并不对劲的人选择了暴力(皮这一下很开心). #include<algorithm> #include<cmath> ...
- choice() 函数
描述 choice() 方法返回一个列表,元组或字符串的随机项. 语法 以下是 choice() 方法的语法: import random random.choice( seq ) 注意:choice ...
- 《MuseGAN: Multi-track Sequential Generative Adversarial Networks for Symbolic Music Generation and Accompaniment》论文阅读笔记
出处:2018 AAAI SourceCode:https://github.com/salu133445/musegan abstract: (写得不错 值得借鉴)重点阐述了生成音乐和生成图片,视频 ...