大意: 给定$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 (闵可夫斯基和)的更多相关文章

  1. Codeforces H. Malek Dance Club(找规律)

    题目描述: Malek Dance Club time limit per test 1 second memory limit per test 256 megabytes input standa ...

  2. CodeForces 173E Camping Groups 离线线段树 树状数组

    Camping Groups 题目连接: http://codeforces.com/problemset/problem/173/E Description A club wants to take ...

  3. 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 ...

  4. Codeforces Round #130 (Div. 2) A. Dubstep

    题目链接: http://codeforces.com/problemset/problem/208/A A. Dubstep time limit per test:2 secondsmemory ...

  5. 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 ...

  6. Codeforces Round #309 (Div. 2)

    A. Kyoya and Photobooks Kyoya Ootori is selling photobooks of the Ouran High School Host Club. He ha ...

  7. CodeForces Round #548 Div2

    http://codeforces.com/contest/1139 A. Even Substrings You are given a string s=s1s2…sns=s1s2…sn of l ...

  8. 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 ...

  9. G. I love Codeforces

    G. I love Codeforces 题目大意:给你n个字符串,以及m个喜欢关系,如果u喜欢v,这时候u会把它的用户名改为 I_love_ 加上v当时的用户名 Examples input 5an ...

随机推荐

  1. 【零基础】神经网络优化之dropout和梯度校验

    一.序言 dropout和L1.L2一样是一种解决过拟合的方法,梯度检验则是一种检验“反向传播”计算是否准确的方法,这里合并简单讲述,并在文末提供完整示例代码,代码中还包含了之前L2的示例,全都是在“ ...

  2. HearthBuddy模拟对手的回合

    start calculations, current time: 10:29:48 V2019.09.01.002 Rush 10000 face 27 berserk:1 ets 200 secr ...

  3. [微信小程序]实现一个自定义遮罩层

    正文: 先上效果图: 点击按钮Show显示遮罩层,再次点击屏幕任何地方隐藏遮罩层; <button bindtap="showview">Show</button ...

  4. A filter or servlet of the current chain does not support asynchronous operations. 错误解决记录

    做视频文件上传一直报这个错误: java.lang.IllegalStateException: A filter or servlet of the current chain does not s ...

  5. Android下拉涮新第三方通用控件

    Android下拉涮新第三方通用控件https://github.com/chrisbanes/Android-PullToRefresh Pull To Refresh Views for Andr ...

  6. Ionic4.x 新增底部 tabs 页面

    1.创建 tab4 模块 ionic g page tab4 2.修改根目录里 app-routing.module.ts 文件里面的路由配置,去掉默认增加的路由 3.tabs.router.modu ...

  7. 有关Linux

    关于nginx https://www.cnblogs.com/jingmoxukong/p/5945200.html 停止命令 sudo systemctl stop nginx.service

  8. springboot集成调用Azkaban

    springboot集成调用Azkaban 一. 说明 1.Azkaban是由Linkedin公司推出的一个批量工作流任务调度器,主要用于在一个工作流内以一个特定的顺序运行一组工作和流程,它的配置是通 ...

  9. 讲sql注入原理的 这篇不错(有空可以看看)

    我们围绕以下几个方面来看这个问题: 1.什么是sql注入? 2.为什么要sql注入? 3.怎样sql注入? 1.什么是sql注入? 所谓SQL注入,就是通过把SQL命令插入到Web表单递交或输入域名或 ...

  10. kafka shell file

    1. start kafka and schema_registry #!/bin/sh export KAFKA_HOME=/home/lenmom/workspace/software/confl ...