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 ...
随机推荐
- label设置渐变时不显示纯英文纯数字字符串
提出问题: 当对UILabel设置渐变color时,有点小问题.即:text为中文或中英混合字符串时显示正常,纯英文字符串不显示!!! 剖析问题: 经搜索了解到:在显示中文时,绘制渐变color的 ...
- IOS添加真机调试设备
注意点: 有时需要同意协议什么的,很多时候刷新出来都是白屏,解决办法: 对于不能确认新协议的问题,我发现了一个解决方法:登陆后,直接在浏览器的地址框访问:https://developer.apple ...
- win10 Ubuntu16 双系统
https://www.cnblogs.com/coxiseed/p/9945202.html UEFI分区顺序 1 根目录 / 主分区 2 交换空间 逻辑分区 3 引导 /boot 逻辑分区 4 / ...
- Qt之模型/视图(委托)
概念 不同于模型 - 视图 - 控制器模式,模型/视图设计不包括用于管理与用户交互的一个完全独立的组件.一般情况,视图负责将模型数据呈现给用户以及处理用户输入.为了输入更加具有灵活性,则由委托来执行交 ...
- Link static data in sql source control
You can link data that doesn't change very often to SQL Source Control. This lets you commit data ch ...
- Angular 执行 css3 简单的动画
<div class="content"> 内容区域 <button (click)="showAside()">弹出侧边栏</b ...
- flutter 引入第三方 Icon 图标(以阿里图标库为例)
在fluttter中引入第三方图标库的具体方法: 1.在阿里图标库选好需要用的图标,添加进购物车将选好的图标打包下载到本地(下载代码),复制iconfont.ttf文件到项目中 2.存放途径:lib/ ...
- 25.Flutter中的表单 Radio RadioListTile Switch SwitchListTile 以及表单组件实现一个简单的学员登记系统(下)
四.Radio.RadioListTile单选按钮组件 Radio常用属性: value单选的值. onChanged改变时触发. activeColor:选中的颜色.背景颜色 groupValue: ...
- 【Leetcode_easy】724. Find Pivot Index
problem 724. Find Pivot Index 题意:先求出数组的总和,然后维护一个当前数组之和curSum,然后对于遍历到的位置,用总和减去当前数字,看得到的结果是否是curSum的两倍 ...
- 第十五章 单点登录——《跟我学Shiro》
目录贴:跟我学Shiro目录贴 Shiro 1.2开始提供了Jasig CAS单点登录的支持,单点登录主要用于多系统集成,即在多个系统中,用户只需要到一个中央服务器登录一次即可访问这些系统中的任何一个 ...