大意: 给定$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. 【转】Eclipse MAT内存分析工具(Memory Analyzer Tool)

    Eclipse MAT内存分析工具(Memory Analyzer Tool) MAT内存分析工具# MAT是Memory Analyzer的简称,它是一款功能强大的Java堆内存分析器.可以用于查找 ...

  2. 2018-2019-2 《网络对抗技术》Exp8 Web基础 Week11-12 20165233

    Exp8 Web基础 目录 一.基础问题 二.实验步骤 实验点一:Web前端HTML 能正常安装.启停Apache.理解HTML,理解表单,理解GET与POST方法,编写一个含有表单的HTML. 实验 ...

  3. 2018-2019-2 20165234 《网络对抗技术》 Exp9 Web安全基础

    Exp9 Web安全基础 一. 实践内容 1. 安装JDK.Webgoat 2. SQL注入攻击 数字型注入(Numeric SQL Injection) 日志欺骗(Log Spoofing) 字符串 ...

  4. OpenResty之replace-filter-nginx-module

    原文: openresty/replace-filter-nginx-module 1. 概要 location /t { default_type text/html; echo abc; repl ...

  5. sql server 使用SqlBulkCopy批量插入数据库

    sql server sqlbulkcopy 批量数据插入数据库使用的是System.Data.SqlClient中的 SqlBulkCopy批量数据插入数据库 sql server 使用SqlBul ...

  6. 中间件 | mq消息队列解说

    消息队列 1.1 什么是消息队列 我们可以把消息队列比作是一个存放消息的容器,当我们需要使用消息的时候可以取出消息供自己使用.消息队列是分布式系统中重要的组件,使用消息队列主要是为了通过异步处理提高系 ...

  7. ObjectAnimator简单示例

    <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android=&quo ...

  8. Tomcat监听shutdown释放数据库连接池

    开发时因为更新代码,频繁重启Tomcat,遇到一个问题:在执行shutdown脚本后,Tomcat进程没有关闭依然存在(但是HTTP服务已经停止),需要手动执行kill命令才行.查了一些资料结合经验, ...

  9. ASP程序中调用Now()总显示“上午”和“下午”,如何解决?

    ASP程序中调用Now()总显示这样的格式:“2007-4-20 下午 06:06:38”,我要的正确格式为“2007-4-20 18:06:38”,我已经通过控制面板==>区域和语言选项==& ...

  10. EasyUI动态展示用户信息

    业务需求:用户登录后展示用户名.用户对应的角色.EasyUI只不过是一个前端的框架,封装了一些组件和样式,你可以用jsp直接调后台获取到用户信息展示,但我这里想用html页面,用目前流行的说法:前后端 ...