BZOJ 4605 崂山白花蛇草水 权值线段树+K-D树
Description
Input
Output
Sample Input
1 1 1 1
1 2 2 3
1 4 1 2
1 3 4 4
2 1 1 4 1 3
2 2 2 3 5 4
2 2 1 4 4 2
Sample Output
NAIVE!ORZzyz.
3
麻麻我树套树一A辣!!
这题一看就是树套树的裸题啊
首先要查k小值,那么就要在外面来颗权值线段树,然后像主席树查询一样查询,那么就需要排名,排名是矩形里的点的个数,用K-D树维护一下就好了!。
代码略长
#include <stdio.h>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
using std::min;
using std::max;
using std::nth_element;
const double alpha = 0.755;
const int MAXN = 100005;
const int inf = 1000000000;
int now,x0,x1,y0,y1,len,Ans,n,Q;template<typename _t>
inline _t read(){_t x=0,f=1;char ch=getchar();for(;!isdigit(ch);ch=getchar())if(ch=='-')f=-f;for(;isdigit(ch);ch=getchar())x=x*10+(ch^48);return x*f;
}struct Point{int d[2];inline int& operator [](int x){return d[x];}inline bool operator < (const Point &a)const{return d[now]==a.d[now]?d[now^1]<a.d[now^1]:d[now]<a.d[now];}
}pt[MAXN];struct node{node *ls,*rs;Point point;int mn[2],mx[2],s,split;inline void Update(node *p){if(!p)return;for(int i=0;i<=1;i++)mn[i]=min(mn[i],p->mn[i]);for(int i=0;i<=1;i++)mx[i]=max(mx[i],p->mx[i]);}inline void Maintain(){s=1;mn[0]=mx[0]=point[0];mn[1]=mx[1]=point[1];if(ls)s+=ls->s,Update(ls);if(rs)s+=rs->s,Update(rs);}inline bool in(int x0,int y0,int x1,int y1){return x0<=mn[0]&& x1>=mx[0]&& y0<=mn[1]&& y1>=mx[1];}inline bool out(int x0,int y0,int x1,int y1){return mn[0]>x1|| mx[0]<x0|| mn[1]>y1|| mx[1]<y0;}inline bool self(int x0,int y0,int x1,int y1){return point[0]>=x0&& point[0]<=x1&& point[1]>=y0&& point[1]<=y1;}node(Point x,int sp){split = sp;ls = rs= NULL;point = x;s=1;mn[0]=mx[0]=x[0];mn[1]=mx[1]=x[1];}node(){}void* operator new(size_t);void operator delete(void *p);#define size(x) ((x)?(x)->s:(0))inline bool bad(){return size(ls)>=s*alpha||size(rs)>=s*alpha;}
}*C,*mempool,*need;
std::vector<node*>bin;void build(node *&o,int l,int r,int d=0){if(l>r){o=NULL;return;}now = d;int mid = l+r>>1;nth_element(&pt[l],&pt[mid],&pt[r+1]);o = new node(pt[mid],now);build(o->ls,l,mid-1,d^1);build(o->rs,mid+1,r,d^1);o->Maintain();
}void* node :: operator new(size_t){node *p;if(!bin.empty()){p = bin.back();bin.pop_back();}else{if(C==mempool){C=new node[1<<15];mempool=C+(1<<15);}p=C++;}return p;
}void node::operator delete(void* p){bin.push_back((node*)p);
}int Query(node *o){if(!o)return 0;if(o->in(x0,y0,x1,y1))return o->s;if(o->out(x0,y0,x1,y1))return 0;int Ans = 0;if(o->self(x0,y0,x1,y1))Ans ++;return Ans+Query(o->ls)+Query(o->rs);
}void dfs(node *p){if(!p)return;dfs(p->ls);pt[++len]=p->point;dfs(p->rs);delete p;
}inline void rebuild(node *&o){len = 0;register int split = o->split;dfs(o);build(o,1,len,split);
}void insert(node *&o,Point po,int d=0){if(!o){o=new node(po,d);return;}if(po[d]<o->point[d])insert(o->ls,po,d^1);else insert(o->rs,po,d^1);o->Maintain();if(o->bad())need = o;
}inline void ins(node *&o,Point po){need = NULL;insert(o,po);if(need!=NULL)rebuild(need);
}struct Seg_tree{Seg_tree *ls,*rs;node *root;Seg_tree(){ls=rs=NULL;root=NULL;}
}*root;void Seg_insert(Seg_tree *&o,int l,int r,Point x,int val){if(!o) o = new Seg_tree();ins(o->root,x);if(l==r)return;int mid = l+r>>1;if(val<=mid)Seg_insert(o->ls,l,mid,x,val);else Seg_insert(o->rs,mid+1,r,x,val);
}inline int Seg_Query(Seg_tree *o){if(!o)return 0;return Query(o->root);
}inline void Ask(){x0=read<int>()^Ans,y0=read<int>()^Ans,x1=read<int>()^Ans,y1=read<int>()^Ans;register int k = read<int>()^Ans;if(Seg_Query(root)<k){Ans = 0;printf("NAIVE!ORZzyz.\n");return;}int l=1,r=inf;Seg_tree *rt=root;while(l<r){int mid = l+r>>1,ans=Seg_Query(rt->rs);if(k>ans)k-=ans,rt=rt->ls,r=mid;else rt=rt->rs,l=mid+1;}printf("%d\n",Ans=l);
}inline void change(){Point cur;cur[0]=read<int>()^Ans;cur[1]=read<int>()^Ans;int val = read<int>()^Ans;Seg_insert(root,1,inf,cur,val);
}int main(){n=read<int>();Q=read<int>();while(Q--){register int tmp = read<int>();if(tmp == 1)change();else Ask();}
}
BZOJ 4605 崂山白花蛇草水 权值线段树+K-D树相关推荐
- 崂山白花蛇草水 权值线段树套KDtree
崂山白花蛇草水 权值线段树套KDtree Description 神犇Aleph在SDOI Round2前立了一个flag:如果进了省队,就现场直播喝崂山白花蛇草水.凭借着神犇Aleph的实 力,他轻 ...
- bzoj4605: 崂山白花蛇草水 权值线段树套KDtree
bzoj4605: 崂山白花蛇草水 链接 bzoj loj 思路 强制在线,那就权值线段树套KDtree好了,没啥好讲的. KDtree要加平衡因子来重构.另外,那水真难喝. 错误 树套树一边写过了, ...
- 【BZOJ4605】崂山白花蛇草水 权值线段树+kd-tree
[BZOJ4605]崂山白花蛇草水 Description 神犇Aleph在SDOI Round2前立了一个flag:如果进了省队,就现场直播喝崂山白花蛇草水.凭借着神犇Aleph的实力,他轻松地进了 ...
- 【bzoj4605】崂山白花蛇草水 权值线段树套KD-tree
题目描述 神犇Aleph在SDOI Round2前立了一个flag:如果进了省队,就现场直播喝崂山白花蛇草水.凭借着神犇Aleph的实力,他轻松地进了山东省省队,现在便是他履行诺言的时候了.蒟蒻Bob ...
- bzoj4605 崂山白花蛇草水 权值线段树套kd树
Description Q次操作,要求资瓷 在(x,y)处放一个数字x 查询(x1,y1)到(x2,y2)矩形内第k大 Solution 非常裸的权值线段树套kd树,为了保证复杂度可以定期重构也可以平 ...
- BZOJ 4605: 崂山白花蛇草水 树套树 权值线段树套kdtree
4605: 崂山白花蛇草水 Time Limit: 80 Sec Memory Limit: 512 MB Submit: 527 Solved: 153 [Submit][Status][Dis ...
- [BZOJ]4605 崂山白花蛇草水 线段树套KD-Tree
4605: 崂山白花蛇草水 Time Limit: 80 Sec Memory Limit: 512 MB Submit: 527 Solved: 153 [Submit][Status][Dis ...
- BZOJ 4605 崂山白花蛇草水(权值线段树+KD树)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=4605 [题目大意] 操作 1 x y k 表示在点(x,y)上放置k个物品, 操作 2 ...
- bzoj 4605 崂山白花蛇草水
http://www.elijahqi.win/archives/3722 Description 神犇Aleph在SDOI Round2前立了一个flag:如果进了省队,就现场直播喝崂山白花蛇草水. ...
最新文章
- 移民澳洲好网站http://home.hexun.com/ausky/default.html
- ubuntu15.04中安装mysql和mysql-workbench
- Spring 5 新特性:函数式Web框架
- thinkphp传递参数
- Dalvik VM的主要特征
- 机器学习第一篇:开篇
- Pandas学习笔记1(序列部分)
- javaScript第六天(1)
- lol新服务器怎么发信息,《英雄联盟手游》国服新消息 最新玩法发布
- C# PDF 转成图片利用GhostScript
- 3、redis之java client环境搭建
- Python3 函数参数
- MQ消息队列概述及主流MQ分析
- 第四章:项目整合管理 - (4.1 制定项目章程)
- matlab去除图片水印_一种基于MATLAB去图片水印方法
- R语言缺失值判断与处理mice包-3
- 微信公众号获取永久素材
- Windows_01_Windows系统的中的32位和64位(System32和SysWOW64)
- 两台虚拟服务器如何串联,两台tp-link路由器串联设置教程 | 192路由网
- Premiere Pro CC 2018 经典教程
热门文章
- 集成支付宝支付(AliPay)详解,防跳坑
- php模拟彩票生成器,一种彩票号码生成器的制作方法
- Emoji开源项目解读(一)系统表情
- cdma200 matlab 仿真,CDMA通信系统的MATLAB仿真
- 重建控制文件,并且不干净的关闭数据库测试
- 公务员考试行测资料分析技巧
- 矩阵连乘问题(动态规划)
- RK3326 8.1系统定制化通用修改
- HTML5期末大作业:新疆旅游模板网站设计——新疆旅游模板首页(1页) HTML+CSS+JavaScript
- 什么是Mysql的next-key、插入缓冲、二次写、自适应哈希索引和预读