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 ...
随机推荐
- 【Java】线程需要独立的Connection,那对已经配好session的Spring/Mabatis工程该怎么办?
方法一:让线程从配置中取DataSource. 方法二:从配置中取出SessionFactory,然后交给线程去创建session和Connection,举例如下: // Get Session Fa ...
- 初识kaggle,以及记录 kaggle的使用
1.简介:Kaggle是一个数据建模和数据分析竞赛的平台.企业和研究者可在其上发布数据,统计学者和数据挖掘专家可在其上进行竞赛,通过“众包”的形式以产生最好的模型.Kaggle可以分为Competit ...
- AtomicInteger的CAS算法浅析
之前浅析过自旋锁(自旋锁浅析),我们知道它的实现原理就是CAS算法.CAS(Compare and Swap)即比较并交换,作为著名的无锁算法,它也是乐观锁的实现方式之一.JDK并发包里也有许多代码中 ...
- Window和Linux文件共享
一.先设置window上的目录共享 1.1.右击文件要共享的文件夹,选择属性 1.2.设置要共享给的用户和设置用户操作权限 二.安装CIFS共享服务 sudo yum -y install cifs- ...
- CentOS7下JSP连接Mysql
实验环境如下: youxi1 CentOS7.5 Tomcat8.5.35 192.168.5.101 youxi2 CentOS7.5 Mysql5.7.20 192.168.5.102 (1).下 ...
- oracle数据库死锁原因及分析
定义: 当两个用户希望持有对方的资源时就会发生死锁. 即两个用户互相等待对方释放资源时,oracle认定为产生了死锁,在这种情况下,将以牺牲一个用户作为代价,另一个用户继续执行,牺牲的用户的事务将回滚 ...
- MapReduce本地运行模式wordcount实例(附:MapReduce原理简析)
1. 环境配置 a) 配置系统环境变量HADOOP_HOME b) 把hadoop.dll文件放到c:/windows/System32目录下 c) ...
- jQuery BlockUI Plugin Demo 5(Simple Modal Dialog Example)
Simple Modal Dialog Example This page demonstrates how to display a simple modal dialog. The button ...
- Python3之返回函数
参考:https://www.cnblogs.com/mzc1997/p/7641995.html Python中函数不仅可以作为参数还可以作为结果返回 >>> def pro1(c ...
- Ubuntu-18.04更改安装源为国内源
环境查看 修改源文件 /etc/apt/sources.list 备份配置文件后把文件内容替换如下 deb http://mirrors.aliyun.com/ubuntu/ bionic main ...