[BZOJ2391]Cirno的忧郁
[BZOJ2391]Cirno的忧郁
试题描述
输入
输出
输入示例
输出示例
数据规模及约定
对于30%的数据,n,m<=100; q<=100
对于60%的数据,n,m<=100; q<=10000
对于100%的数据,n,m<=1000; q<=10000
-10000<=x,y<=10000; 0<v<=10000
题解
向量真是太好使了!
首先介绍一个新东西:三角剖分。拿此题为例,我们把两类点混成一类,只是第一类点权值为 0。接下来,给所有点按照极角坐标排序,那么我们需要维护一个 tot[i][j] 表示原点、i、j 这三个点所构成的三角形包含的点的权值和,并且规定:i 到 j 是极角排序正方向时 tot[i][j] 为正(注意所有权值 v > 0),反之为负。那么在询问时对于一个简单多边形直接把相邻两个顶点的 tot 值累加起来即可。
至于如何维护 tot[i][j],可以先确定 i 并以点 i 作为新的原点,然后按极角的顺序一个一个往平衡树内加点,每次加点 j 时统计一下当前平衡树内以 i 为原点且在向量 i->j 左的向量有多少个,这个个数就是 tot[i][j]。
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <algorithm>
#include <cmath>
using namespace std; int read() {
int x = 0, f = 1; char c = getchar();
while(!isdigit(c)){ if(c == '-') f = -1; c = getchar(); }
while(isdigit(c)){ x = x * 10 + c - '0'; c = getchar(); }
return x * f;
} #define maxn 2010
struct Vec {
int x, y;
Vec() {}
Vec(int _, int __): x(_), y(__) {}
bool operator < (const Vec& t) const {
return t.y * x - t.x * y ? t.y * x - t.x * y < 0 : x * x + y * y > t.x * t.x + t.y * t.y;
}
// if a < b then a is on b's left side.
Vec operator - (const Vec& t) const { return Vec(x - t.x, y - t.y); }
} st;
struct Point {
Vec p; int val, id;
Point() {}
Point(Vec _1, int _2, int _3): p(_1), val(_2), id(_3) {}
bool operator < (const Point& t) const { return p - st < t.p - st; }
} ps[maxn];
int cp; struct Node {
Vec v;
int val, r, siz, sum;
Node() {}
Node(Vec _1, int _2, int _3): v(_1), val(_2), r(_3) {}
} ns[maxn];
int ToT, rt, fa[maxn], ch[2][maxn];
void maintain(int o) {
ns[o].siz = 1; ns[o].sum = ns[o].val;
for(int i = 0; i < 2; i++) if(ch[i][o])
ns[o].siz += ns[ch[i][o]].siz, ns[o].sum += ns[ch[i][o]].sum;
return ;
}
void rotate(int u) {
int y = fa[u], z = fa[y], l = 0, r = 1;
if(z) ch[ch[1][z]==y][z] = u;
if(ch[1][y] == u) swap(l, r);
fa[u] = z; fa[y] = u; fa[ch[r][u]] = y;
ch[l][y] = ch[r][u]; ch[r][u] = y;
maintain(y); maintain(u);
return ;
}
int insert(int& o, Point x, Point Org) {
if(!o) {
ns[o = ++ToT] = Node(x.p, x.val, rand());
maintain(o);
return x.val;
}
bool d = x.p - Org.p < ns[o].v - Org.p; d ^= 1;
int ans = 0, ls = ch[0][o] ? ns[ch[0][o]].sum : 0;
if(d) ans += ls + ns[o].val;
ans += insert(ch[d][o], x, Org); fa[ch[d][o]] = o;
if(ns[ch[d][o]].r > ns[o].r) {
int t = ch[d][o];
rotate(t); o = t;
}
maintain(o);
return ans;
} int pid[maxn], tot[maxn][maxn], n, m;
void init() {
sort(ps + 1, ps + cp + 1);
for(int i = 1; i <= (cp >> 1); i++) swap(ps[i], ps[cp-i+1]);
for(int i = 1; i <= cp; i++) if(ps[i].id <= n) pid[ps[i].id] = i;
// for(int i = 1; i <= cp; i++) printf("point[%d]: %d %d\n", i, ps[i].p.x, ps[i].p.y);
for(int i = 1; i <= cp; i++) {
memset(fa, 0, sizeof(fa));
memset(ch, 0, sizeof(ch));
rt = ToT = 0;
for(int j = i; j <= cp; j++) {
tot[i][j] = insert(rt, ps[j], ps[i]);
if(i != j) tot[j][i] = -tot[i][j];
// printf("%d %d: %d\n", i, j, tot[i][j]);
}
} return ;
} int rps[maxn], get[maxn];
int main() {
n = read(); m = read();
st = Vec(-10001, -10001);
for(int i = 1; i <= n; i++) {
int x = read(), y = read();
ps[i] = Point(Vec(x, y), 0, i);
}
for(int i = 1; i <= m; i++) {
int x = read(), y = read(), v = read();
ps[i+n] = Point(Vec(x, y), v, i + n);
}
cp = n + m; init();
int q = read();
while(q--) {
int t = read();
for(int i = 0; i < t; i++) rps[i] = pid[read()];
// for(int i = 0; i < t; i++) printf("%d%c", rps[i], i < t - 1 ? ' ' : '\n');
int ans = 0;
for(int i = 0; i < t; i++) ans += tot[rps[i]][rps[(i+1)%t]];
printf("%d\n", abs(ans));
} return 0;
}
顺便完成预习“向量”的作业。。。
[BZOJ2391]Cirno的忧郁的更多相关文章
- 「BZOJ2391」Cirno的忧郁
传送门 设p[0] = (-10001,-10001) 把所有点按p[0]极角排序, s[i][j]表示三角形p[0]p[i]p[j]内的总价值,若i到j极角增大则s为正,否则s为负. 那么答案就是按 ...
- 2391: Cirno的忧郁 - BZOJ
Description Cirno闲着无事的时候喜欢冰冻青蛙.Cirno每次从雾之湖中固定的n个结点中选出一些点构成一个简单多边形,Cirno运用自己的能力能将此多边形内所有青蛙冰冻.雾之湖生活着m只 ...
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
- 【BZOJ-1853&2393】幸运数字&Cirno的完美算数教室 容斥原理 + 爆搜 + 剪枝
1853: [Scoi2010]幸运数字 Time Limit: 2 Sec Memory Limit: 64 MBSubmit: 1817 Solved: 665[Submit][Status] ...
- 战胜忧虑<1>——不要让忧郁侵入你的生活
1.不要让忧郁侵入你的生活. 备注:忧郁:一种情绪与心理状态,指一个人呈现哀伤.心情低落的状况,绝望与沮丧为其特色. 解决方法:奥斯勒博士说的那样:用铁门把过去和未来隔断,生活在完全独立的今天. 现在 ...
- Bzoj 2393: Cirno的完美算数教室 容斥原理,深搜
2393: Cirno的完美算数教室 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 287 Solved: 175[Submit][Status][ ...
- BZOJ2393: Cirno的完美算数教室
2393: Cirno的完美算数教室 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 138 Solved: 83[Submit][Status] D ...
- 【bzoj2393】【Cirno的完美算数教室】容斥原理的剪枝应用
(上不了p站我要死了,侵权度娘背锅) 在用容斥定理时,常常会用到dfs的形式,如果枚举完所有的情况可能会超时,其剪枝的优化很是重要. Description ~Cirno发现了一种baka数,这种数呢 ...
- 【bzoj2393】Cirno的完美算数教室 数论容斥
Description ~Cirno发现了一种baka数,这种数呢~只含有2和⑨两种数字~~ 现在Cirno想知道~一个区间中~~有多少个数能被baka数整除~ 但是Cirno这么天才的妖精才不屑去数 ...
随机推荐
- Hibernate 分组查询 子查询 原生SQL
分组查询: 使用group by关键字对数据分组,使用having关键字对分组数据设定约束条件,从而完成对数据分组和统计 1.1 聚合函数:常被用来实现数据统计功能 ① count() 统计记录条数 ...
- Permutation test: p, CI, CI of P 置换检验相关统计量的计算
For research purpose, I've read a lot materials on permutation test issue. Here is a summary. Should ...
- NOI2018准备Day12
上午学了1个小时左右的指针,学了个从句子中分离单词的方法,其他的感觉没学到啥. 中午看了一会儿网络流,懵逼...... A了8道题,4道钻石.3道黄金.1道白银,自己写出了codevs"解药 ...
- Javascript四舍五入(Math.round()与Math.pow())
代码 Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ ...
- iOS面试
1.进程.线程的区别?2.“三次握手”是什么?具体细节,连接释放时需要几次“握手”,说出大概过程.3.TCP.UDP协议的区别?计算机网络分几层,以及TCP.Http协议各自工作在哪一层及相关细节.4 ...
- ASP.NET SessionState 解惑
踩坑 近日在对一个ASP.NET WEBFORM项目进行调优过程中,偶然发现页面POSTBACK事件是串行处理的,甚至不同页面的请求都是串行处理的(一个页面加载完毕后,才开始加载第二个页面).但是网站 ...
- thinkphp where条件语句整理
ThinkPHP运算符 与 SQL运算符 对照表 TP运算符 SQL运算符 例子 实际查询条件 eq = $map['id'] = array('eq',100); 等效于:$map['id'] = ...
- iOS开发小技巧--微博项目中的键盘工具条
微博项目中的键盘工具条 项目中的键盘工具条不能使用inputAccessoryView,因为inputAccessoryView不能实现键盘隐藏的时候,工具条还显示在眼前,如图: 所以,果断决定将工具 ...
- 什么是js面向对象??
简单的来说就是键值对,写一个函数,然后传值进去, function Person(name,age){ this.name = name; this.age ...
- bzoj 3110 K大数查询
第一道整体二分,因为只需要知道每个询问区间中比mid大的数有多少个,就可以直接用线段树区间加,区间求和了. #include<iostream> #include<cstdio> ...