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 作者 陈越 这次真的没骗你 —— 这道超级简单的题目没有任何输入. ...
随机推荐
- win7 32位配置apache+wsgi+django环境
1下载xampp,里面有apache,mysql,phpmyadmin, 2 下载wsgi,http://download.csdn.net/download/copter/9192361 将对应的模 ...
- [Algorithom] Stack Data Structure in JavaScript
A stack is a collection of items that obeys the principle of "last in, first out". Like a ...
- h5调用手机照相机
camera.html <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> & ...
- C++11 并发指南三(std::mutex 详解)(转)
转自:http://www.cnblogs.com/haippy/p/3237213.html 上一篇<C++11 并发指南二(std::thread 详解)>中主要讲到了 std::th ...
- caffe2--ubuntu16.04--14.04--install
Install Welcome to Caffe2! Get started with deep learning today by following the step by step guide ...
- anaconda的所有版本大全--下载地址
地址: https://repo.continuum.io/archive/ 内容: Anaconda installer archive Filename Size Last Modified MD ...
- openh264 在 osx 上的 nasm 问题
先在 pc 上编译,熟悉一下. 编译遇到一个问题: nasm -DUNIX64 -DPREFIX -f macho64 -I./codec/common/x86/ -o codec/common/x8 ...
- ComboBox在WPF中的绑定示例:绑定项、集合、转换,及其源代码
示例1.Selector(基类) 的示例Controls/SelectionControl/SelectorDemo.xaml <Page x:Class="Windows10.Con ...
- 2809: [Apio2012]dispatching
2809: [Apio2012]dispatching Time Limit: 10 Sec Memory Limit: 128 MB Submit: 3102 Solved: 1641 [Sub ...
- Hadoop实战-使用Eclipse开发Hadoop API程序(四)
一.准备运行所需Jar包 1)avro-1.7.4.jar 2)commons-cli-1.2.jar 3)commons-codec-1.4.jar 4)commons-collections-3. ...