Geometers Anonymous Club CodeForces - 1195F (闵可夫斯基和)
大意: 给定$n$个凸多边形, $q$个询问, 求$[l,r]$内闵可夫斯基区间和的顶点数.
要用到一个结论, 闵可夫斯基和凸包上的点等于向量种类数.
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <map>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define pb push_back
using namespace std;
typedef pair<int,int> pii;
const int N = 1e6+10;
int n, q, cnt, x[N], y[N], c[N];
int L[N], R[N], ans[N];
struct _ {int l,r;} b[N];
vector<int> g[N];
pii a[N];
map<pii,int> pre; int gcd(int a,int b) {return b?gcd(b,a%b):a;}
pii reduce(int x, int y) {
int g = gcd(abs(x),abs(y));
if (g) x/=g,y/=g;
return pii(x,y);
}
void add(int x, int v) {
for (; x<=cnt; x+=x&-x) c[x]+=v;
}
int query(int x) {
int r = 0;
for (; x; x^=x&-x) r+=c[x];
return r;
} int main() {
scanf("%d", &n);
REP(i,1,n) {
int k;
scanf("%d", &k);
REP(j,0,k-1) scanf("%d%d",x+j,y+j);
L[i] = cnt+1;
REP(j,0,k-1) a[++cnt] = reduce(x[j]-x[(j+1)%k],y[j]-y[(j+1)%k]);
R[i] = cnt;
}
scanf("%d", &q);
REP(i,1,q) {
int l, r;
scanf("%d%d", &l, &r);
b[i].l = L[l];
b[i].r = R[r];
g[b[i].r].pb(i);
}
int now = 1;
REP(i,1,cnt) {
if (pre[a[i]]) add(pre[a[i]],-1);
pre[a[i]] = i;
add(i,1);
for (int j:g[i]) ans[j] = query(b[j].r)-query(b[j].l-1);
}
REP(i,1,q) printf("%d\n", ans[i]);
}
Geometers Anonymous Club CodeForces - 1195F (闵可夫斯基和)的更多相关文章
- Codeforces H. Malek Dance Club(找规律)
题目描述: Malek Dance Club time limit per test 1 second memory limit per test 256 megabytes input standa ...
- CodeForces 173E Camping Groups 离线线段树 树状数组
Camping Groups 题目连接: http://codeforces.com/problemset/problem/173/E Description A club wants to take ...
- Codeforces Round #309 (Div. 2) A. Kyoya and Photobooks 字符串水题
A. Kyoya and Photobooks Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/5 ...
- Codeforces Round #130 (Div. 2) A. Dubstep
题目链接: http://codeforces.com/problemset/problem/208/A A. Dubstep time limit per test:2 secondsmemory ...
- Codeforces Round #114 (Div. 1) A. Wizards and Trolleybuses 物理题
A. Wizards and Trolleybuses Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/conte ...
- Codeforces Round #309 (Div. 2)
A. Kyoya and Photobooks Kyoya Ootori is selling photobooks of the Ouran High School Host Club. He ha ...
- CodeForces Round #548 Div2
http://codeforces.com/contest/1139 A. Even Substrings You are given a string s=s1s2…sns=s1s2…sn of l ...
- Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) D. Innokenty and a Football League
地址:http://codeforces.com/contest/782/problem/D 题目: D. Innokenty and a Football League time limit per ...
- G. I love Codeforces
G. I love Codeforces 题目大意:给你n个字符串,以及m个喜欢关系,如果u喜欢v,这时候u会把它的用户名改为 I_love_ 加上v当时的用户名 Examples input 5an ...
随机推荐
- 走进JavaWeb技术世界14:通过项目逐步深入了解Mybatis(一)
通过项目逐步深入了解Mybatis(一) 2017-06-12 文章导航 Mybatis 和 SpringMVC 通过订单商品案例驱动 官方中文地址:http://www.mybatis.org/my ...
- [RK3288] 外接USB设备出现丢数
CPU:RK3288 系统:Android 5.1 主板外接 USB 接口的外设,经常会出现丢数的现象,这种问题在很多 USB 接口的外设上都遇到过,例如:USB读卡器.USB扫描枪等 有一个共同点是 ...
- 4.弹性网络( Elastic Net)
版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/qq_21904665/article/details/52315642 ElasticNet 是一种 ...
- 总结解决 Android-Studio 编译耗时(好久、太长)问题
首先通过搜索有关Android-Studio 编译耗时(好久.太长)问题的博客,速度确实有所改善. 一.暂时解决 Android-Studio 编译耗时(好久.太长)问题 本文链接:https://b ...
- java的servlet执行过程是怎么样的?
java的servlet执行过程是怎么样 答: Servlet执行过程:程序第一次访问,会调用servlet的init()方法初始化(只执行一次),每次程序执行都会根据请求调用doGet()或者d ...
- LVS的调度算法介绍
1.轮询调度(rr) 轮询调度(Round Robin 简称'RR')算法就是按依次循环的方式将请求调度到不同的服务器上,该算法最大的特点就是实现简单.轮询算法假设所有的服务器处理请求的能力都一样的, ...
- LeetCode_100. Same Tree
100. Same Tree Easy Given two binary trees, write a function to check if they are the same or not. T ...
- Spark2.x学习笔记:5、Spark On YARN模式
https://blog.csdn.net/chengyuqiang/article/details/77864246
- 未能加载文件或程序集“System.Web.Extensions, Version=1.0.61025.0, Culture=neutral
近日将电脑重装了一下,刚刚装上vs2005后打开以前的一个项目,居然出现了下面的错误: 未能加载文件或程序集“System.Web.Extensions.Design, Version=1.0.610 ...
- python迭代器、生成器、装饰器之生成器
python中只要函数内部包含有yield关键字,那么函数名()的到的结果就是生成器,并且不会执行函数内部代码,通过__next__()或者next()函数可以获取值,每调用一次,都会取出一个值,无值 ...