BZOJ_4066_简单题_KDtree
BZOJ_4066_简单题_KDtree
Description
|
命令 |
参数限制 |
内容 |
|
1 x y A |
1<=x,y<=N,A是正整数 |
将格子x,y里的数字加上A |
|
2 x1 y1 x2 y2 |
1<=x1<= x2<=N 1<=y1<= y2<=N |
输出x1 y1 x2 y2这个矩形内的数字和 |
|
3 |
无 |
终止程序 |
Input
Output
Sample Input
1 2 3 3
2 1 1 3 3
1 1 1 1
2 1 1 0 7
3
Sample Output
5
HINT
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define N 200050
#define FAC 0.75
#define ls ch[p][0]
#define rs ch[p][1]
#define _max(x,y) ((x)>(y)?(x):(y))
#define _min(x,y) ((x)<(y)?(x):(y))
int ch[N][2],sum[N],mx[N][2],mn[N][2],now,root,dep[N],n;
struct Point {
int p[2],v;
bool operator < (const Point &x) const {
return p[now]==x.p[now]?p[!now]<x.p[!now]:p[now]<x.p[now];
}
}a[N];
inline char nc() {
static char buf[100000],*p1,*p2;
return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
int rd() {
int x=0; char s=nc();
while(s<'0'||s>'9') s=nc();
while(s>='0'&&s<='9') x=(x<<3)+(x<<1)+s-'0',s=nc();
return x;
}
void pushup(int p,int x) {
mx[p][0]=_max(mx[p][0],mx[x][0]);
mn[p][0]=_min(mn[p][0],mn[x][0]);
mx[p][1]=_max(mx[p][1],mx[x][1]);
mn[p][1]=_min(mn[p][1],mn[x][1]);
sum[p]+=sum[x];
}
int build(int l,int r,int type) {
int mid=(l+r)>>1; now=type;
nth_element(a+l,a+mid,a+r+1);
mx[mid][0]=mn[mid][0]=a[mid].p[0];
mx[mid][1]=mn[mid][1]=a[mid].p[1];
sum[mid]=a[mid].v;
ch[mid][0]=ch[mid][1]=0;
if(l<mid) ch[mid][0]=build(l,mid-1,!type),pushup(mid,ch[mid][0]);
if(r>mid) ch[mid][1]=build(mid+1,r,!type),pushup(mid,ch[mid][1]);
return mid;
}
void insert(int x) {
int p=root;
mx[x][0]=mn[x][0]=a[x].p[0];
mx[x][1]=mn[x][1]=a[x].p[1];
sum[x]=a[x].v;
if(!p) {root=x; return ;}
now=0;
while(1) {
pushup(p,x);
if(a[x]<a[p]) {
if(ls) p=ls;
else {ls=x; return ;}
}else {
if(rs) p=rs;
else {rs=x; return ;}
}
now^=1;
}
}
int query(int x,int y,int z,int w,int p) {
if(mn[p][0]>=x&&mx[p][0]<=z&&mn[p][1]>=y&&mx[p][1]<=w) return sum[p];
int re=0;
if(a[p].p[0]<=z&&a[p].p[0]>=x&&a[p].p[1]<=w&&a[p].p[1]>=y) re+=a[p].v;
if(ls&&mn[ls][0]<=z&&mx[ls][0]>=x&&mn[ls][1]<=w&&mx[ls][1]>=y) re+=query(x,y,z,w,ls);
if(rs&&mn[rs][0]<=z&&mx[rs][0]>=x&&mn[rs][1]<=w&&mx[rs][1]>=y) re+=query(x,y,z,w,rs);
return re;
}
int main() {
rd();
int opt,x,y,z,w,ans=0;
while(1) {
opt=rd();
if(opt==3) break;
if(opt==1) {
n++;
x=rd(); y=rd(); z=rd();
a[n].p[0]=x^ans;
a[n].p[1]=y^ans;
a[n].v=z^ans;
insert(n);
if(n%10000==0) root=build(1,n,0);
}else {
x=rd(); y=rd(); z=rd(); w=rd();
x^=ans; y^=ans; z^=ans; w^=ans;
printf("%d\n",ans=query(x,y,z,w,root));
}
}
}
BZOJ_4066_简单题_KDtree的更多相关文章
- [bzoj4066/2683]简单题_KD-Tree
简单题 bzoj-4066 题目大意:n*n的棋盘,开始为均为0,支持:单点加权值,查询矩阵权值和,强制在线. 注释:$1\le n\le 5\cdot 10^5$,$1\le m \le 2\cdo ...
- BZOJ 2683: 简单题
2683: 简单题 Time Limit: 50 Sec Memory Limit: 128 MBSubmit: 913 Solved: 379[Submit][Status][Discuss] ...
- 【BZOJ-1176&2683】Mokia&简单题 CDQ分治
1176: [Balkan2007]Mokia Time Limit: 30 Sec Memory Limit: 162 MBSubmit: 1854 Solved: 821[Submit][St ...
- Bzoj4066 简单题
Time Limit: 50 Sec Memory Limit: 20 MBSubmit: 2185 Solved: 581 Description 你有一个N*N的棋盘,每个格子内有一个整数,初 ...
- Bzoj2683 简单题
Time Limit: 50 Sec Memory Limit: 128 MBSubmit: 1071 Solved: 428 Description 你有一个N*N的棋盘,每个格子内有一个整数, ...
- 这样leetcode简单题都更完了
这样leetcode简单题都更完了,作为水题王的我开始要更新leetcode中等题和难题了,有些挖了很久的坑也将在在这个阶段一一揭晓,接下来的算法性更强,我就要开始分专题更新题目,而不是再以我的A题顺 ...
- [BZOJ2683][BZOJ4066]简单题
[BZOJ2683][BZOJ4066]简单题 试题描述 你有一个N*N的棋盘,每个格子内有一个整数,初始时的时候全部为0,现在需要维护两种操作: 命令 参数限制 内容 1 x y A 1<=x ...
- HDU 1753 大明A+B(字符串模拟,简单题)
简单题,但要考虑一些细节: 前导0不要,后导0不要,小数长度不一样时,有进位时,逆置处理输出 然后处理起来就比较麻烦了. 题目链接 我的代码纯模拟,把小数点前后分开来处理,写的很繁杂,纯当纪念——可怜 ...
- 团体程序设计天梯赛-练习集L1-014. 简单题
L1-014. 简单题 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 这次真的没骗你 —— 这道超级简单的题目没有任何输入. ...
随机推荐
- sqlalchemy如何实现时间列自动更新?
目标:数据表的时间列在其他列内容更新的时候,自动更新时间列到更新的时间 方法:数据库表模型如下:server_default表示初始时间,onupdate表示更新的时间 class MonitorDa ...
- .NET组件编程
链接 http://www.cnblogs.com/mapserver/archive/2006/03/06/343632.html
- 学习笔记 Java类的封装、继承和多态 2014.7.10
1.问题:toString()没搞懂? int a = 1; Integer aa = new Integer(a); //这是实现的过程 System.out.println("Hello ...
- jquery获取<div></div>之间的内容.text() 和 .html()区别
jQuery 获取 div 之间的内容,有两种方法,$(selector).text().$(selector).html() . html: <div> <p>test< ...
- C# 将链表存入二进制文件及读取二进制文件得到链表示例
// 将tasks保存到二进制文件中 public Boolean saveToFile(String file) { try { ) { // 没任务就不存 return false; } if ( ...
- python 图像识别转文字
rom PIL import Image import pytesseract #上面都是导包,只需要下面这一行就能实现图片文字识别 #text=pytesseract.image_to_string ...
- PHP compact() 函数
Compact ---- 创建一个包含变量名和它们的值的数组: <?php $firstname = "Bill"; $lastname = "Gates" ...
- react 自定义 TabBar 组件
1.创建 组件 src/components/TabBar/index.js /** * TabBar 组件 */ import React ,{ PureComponent } from 'reac ...
- windows ffmpeg 推送摄像头数据到rtmp服务
文本主要讲述windows系统下如何利用ffmpeg获取摄像机流并推送到rtmp服务,命令的用法前文 中有讲到过,这次是通过代码来实现.实现该项功能的基本流程如下: 图1 ffmpeg推流流程图 较前 ...
- Block系列1:初识block
//-------1.定义函数----- //1.函数 int sum(int a,int b) { return a+b; } //------------------2.声明--------- / ...