bzoj3815: 卡常数
随机数据,带修改,求到空间中到给定点距离为给定值的点的编号,唯一解。
建三维kdtree,对查询用可行性剪枝在树上找,由于数据随机,插入删除时不需要维护平衡。
#include<bits/stdc++.h>
using namespace std;
typedef double ld;
const ld _0=1e-;
int n,m,res;
ld _a,_b,la=0.1,X[],R;
void mins(ld&a,ld b){if(a>b)a=b;}
void maxs(ld&a,ld b){if(a<b)a=b;}
ld f(ld x){return x=la*x+,_a*x-_b*sin(x);}
void $(ld&x){
ld L=-,R=;
while(R-L>1e-){
ld M=(L+R)*.;
f(M)<x?L=M:R=M;
}
x=(L+R)*.;
}
char ib[],*ip=ib;
int _(){
int x=;
while(*ip<)++ip;
while(*ip>)x=x*+*ip++-;
return x;
}
ld _Lf(){
ld x=;
bool f=;
while(*ip<)*ip++=='-'?f=:;
while(*ip>)x=x*+(*ip++-);
if(*ip=='.'){
ld a=.;
for(++ip;*ip>;x+=(*ip++-)*a,a*=.);
}
return f?-x:x;
}
ld max(ld a,ld b){return a>b?a:b;}
ld near(ld x,ld l,ld r){return x<l?l-x:max(x-r,);}
ld far(ld x,ld l,ld r){return max(r-x,x-l);}
ld dis(ld a,ld b,ld c){return a*a+b*b+c*c;}
struct node{
node*c[],*f;
ld x[],mn[],mx[];
int id;
bool chk1(){
return this
&& dis(near(X[],mn[],mx[]),near(X[],mn[],mx[]),near(X[],mn[],mx[]))<R+_0
&& dis( far(X[],mn[],mx[]), far(X[],mn[],mx[]), far(X[],mn[],mx[]))>R-_0;
}
bool chk2(){
return id&&fabs(dis(x[]-X[],x[]-X[],x[]-X[])-R)<_0;
}
void init(int ID,bool d){
id=ID;
for(int i=;i<;++i){
x[i]=_Lf();
if(d)$(x[i]);
mn[i]=mx[i]=x[i];
}
}
void up(){
if(id)for(int i=;i<;++i)mn[i]=mx[i]=x[i];
else for(int i=;i<;++i)mn[i]=1e10,mx[i]=-1e10;
for(int i=;i<;++i)if(c[i]){
c[i]->f=this;
if(c[i]->mn[]>c[i]->mx[])c[i]=;
else for(int j=;j<;++j){
mins(mn[j],c[i]->mn[j]);
maxs(mx[j],c[i]->mx[j]);
}
}
}
}ns[],*np=ns,*rt,*nr[];
int D=;
bool operator<(const node&a,const node&b){
return a.x[D]<b.x[D];
}
node*build(node*l,node*r){
if(l==r)return ;
node*m=l+(r-l>>);
nth_element(l,m,r);
D=(D+)%;
m->c[]=build(l,m);
m->c[]=build(m+,r);
m->up();
D=(D+)%;
return m;
}
void ins(node*w,node*a,int D){
int d=a->x[D]>w->x[D];
if(w->c[d])ins(w->c[d],a,(D+)%);
else w->c[d]=a;
w->up();
}
bool find(node*w){
if(!w->chk1())return ;
if(w->chk2())return res=w->id,;
return find(w->c[])||find(w->c[]);
}
int main(){
fread(ib,,sizeof(ib),stdin);
n=_(),m=_(),_a=_Lf(),_b=_Lf();
for(int i=;i<=n;++i)np++->init(i,);
rt=build(ns,np);
for(node*a=ns;a!=np;++a)nr[a->id]=a;
while(m--){
int op=_();
if(op){
X[]=_Lf();
X[]=_Lf();
X[]=_Lf();
R=_Lf();
$(X[]),$(X[]),$(X[]),$(R);
R*=R;
find(rt);
la=res;
printf("%d\n",res);
}else{
ld _id=_Lf();
$(_id);
int id=round(_id);
node*u=nr[id];
for(u->id=;u;u->up(),u=u->f);
np->init(id,);
ins(rt,nr[id]=np++,);
}
}
return ;
}
bzoj3815: 卡常数的更多相关文章
- Interesting卡常数
C++ Interesting卡常数 作为一名OIer,在Noip中卡(kǎ 我就爱读kǎ)常数可以说是必备技巧.在此总结一下我所知卡常数的神奇手法: IO优化 fread 和 fwrite ,如果还 ...
- CF 86D 莫队(卡常数)
CF 86D 莫队(卡常数) D. Powerful array time limit per test 5 seconds memory limit per test 256 megabytes i ...
- NOIP卡常数技巧
NOIP卡常数技巧 https://blog.csdn.net/a1351937368/article/details/78162078 http://www.mamicode.com/info-de ...
- ACM卡常数(各种玄学优化)
首先声明,本博文部分内容仅仅适用于ACM竞赛,并不适用于NOIP与OI竞赛,违规使用可能会遭竞赛处理,请慎重使用!遭遇任何情况都与本人无关哈=7= 我也不想搞得那么严肃的,但真的有些函数在NOIP与O ...
- HDU 6211 卡常数取模 预处理 数论
求所有不超过1e9的 primitive Pythagorean triple中第2大的数取模$2^k$作为下标,对应a[i]数组的和. 先上WIKI:https://en.wikipedia.org ...
- 【UER #1】DZY Loves Graph(待卡常数)
题解: 正解是可持久化并查集 但这个显然是lct可以维护的 但这常数是个问题啊??? #include <bits/stdc++.h> using namespace std; struc ...
- HDU-5373-水题-卡常数时间
姿势就是力量啊! 第一次意识到long long 比 int要慢很多.当时想到了各种优化仍然TLE,最后也没A出来,就是用了long long #include <cstdio> #inc ...
- Vijos p1892 树上的最大匹配 树形DP+计数 被卡常我有特殊技巧heheda
https://vijos.org/p/1892 此题需要手动开栈: <<; //256MB char *p=(char*)malloc(size)+size; __asm__(" ...
- OI中卡常数技巧
一.I/O优化 读入优化是卡常数最重要的一条! inline int read() { ,f=;char c=getchar(); ;c=getchar();} +c-';c=getchar();} ...
随机推荐
- IIS 7上导入SSL证书
1.将SSL证书文件上传至服务器 2.导入证书 1)在IIS设置项中,打开‘服务器证书’ 2)选择导入 3)将网站绑定SSL证书
- HPU组队赛L(没有标题。。)(贪心)
时间限制 1 Second 内存限制 512 Mb 题目描述 给个字符串s和整数k.(字符串中只有0-9) 问至少修改字符串中的几位才可以让字符串的各个位之和大于等于k. 输入 第一行一个整数T表 ...
- 基于PaaS和SaaS研发平台体系
基于PaaS和SaaS研发的商业云平台实战 背景介绍 SaaS.PaaS.IaaS等云服务模式已经被大家普遍认可,在研发过程中借力一些PaaS和SaaS平台,能够提升产品的研发速度和功能稳定程度.本文 ...
- lucene随笔 IKAnalyzer StandardAnalyzer
StandardAnalyzer 是单词分词器: String msg = "我喜欢你,我的祖国!china 中国,I love you!中华人民共和国"; 分词后的结果:[我], ...
- 【牛客练习赛22 C】
https://www.nowcoder.com/acm/contest/132/C 题目大意:在n个区间中取出n个数,相加的和一共会出现多少种结果. 题目分析:对于这种挑选数字相加,由于每一步不同的 ...
- exception in thread "http-apr-80-exec-24" java.lang.OutOfMemoryError:PermGen...
今天客户说项目访问不了了,我急忙看了下告警,发现上报:“exception in thread "http-apr-80-exec-24" java.lang.OutOfMemor ...
- centos7设置grub密码保护
设置grub密码保护:查看grub登录用户名cat /etc/grub.d/01_users,可以看到用户名为root.通过grub2-setpasswords设置grub密码,确认密码 cat /b ...
- 非系统服务如何随系统启动时自动启动(rc.local加了可执行权限,仍然没有生效)
我们知道,例如我们直接yum 安装的httpd mysqld之类的服务可以直接systemctl enable mysql使服务自动启动,但是,我们应该关心的是但是的那部分 例如nginx,我的话,我 ...
- python基础(五)——CGI编程
使用python实现get方法和post方法传值,多选按钮,单选按钮.文本编辑区.下拉列表数据的传递,cookie的设置文件上传,文件下载.本文未经整理,仅供参考 #!/usr/bin/python ...
- Scalable MySQL Cluster with Master-Slave Replication, ProxySQL Load Balancing and Orchestrator
MySQL is one of the most popular open-source relational databases, used by lots of projects around t ...