Bzoj4066 简单题
Time Limit: 50 Sec Memory Limit: 20 MB
Submit: 2185 Solved: 581
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
Source
同Bzoj2683。
嘛,真是简单题啊,才调了两天就过了。
由于强制在线,所以不能像2683那样各种方法乱搞,只能老实写K-Dtree(好像还有块链之类的解法)
K-Dtree定期重构,强行维护数据。常数写不好的话会T飞。
之前把47行的左右边界取错了,时间复杂度直接突破天际。
/*by SilverN*/
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<vector>
#define LL long long
using namespace std;
const int mxn=;
LL read(){
LL x=,f=;char ch=getchar();
while(ch<'' || ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>='' && ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
struct node{
int l,r;
int min[],max[];
int d[];
int w;
LL sum;
}t[mxn];
int root=,nowD;
int cmp(const node a,const node b){
return a.d[nowD]<b.d[nowD];
}
int n,cnt;
int lim=;
inline void pushup(int rt,int x){
t[rt].max[]=max(t[rt].max[],t[x].max[]);
t[rt].max[]=max(t[rt].max[],t[x].max[]);
t[rt].min[]=min(t[rt].min[],t[x].min[]);
t[rt].min[]=min(t[rt].min[],t[x].min[]);
return;
}
inline bool in(int x1,int y1,int x2,int y2,int k){
return (x1<=t[k].min[] && t[k].max[]<=x2 &&
y1<=t[k].min[] && t[k].max[]<=y2);
}
inline bool out(int x1,int y1,int x2,int y2,int k){
return (x1>t[k].max[] || x2<t[k].min[] || y1>t[k].max[] || y2<t[k].min[]);
}
int Build(int l,int r,int D){
if(l>r)return ;
nowD=D;int mid=(l+r)>>;
nth_element(t+l,t+mid,t+r+,cmp);///
t[mid].max[]=t[mid].min[]=t[mid].d[];
t[mid].max[]=t[mid].min[]=t[mid].d[];
t[mid].sum=t[mid].w;
//
t[mid].l=Build(l,mid-,D^);
if(t[mid].l)pushup(mid,t[mid].l);
t[mid].r=Build(mid+,r,D^);
if(t[mid].r)pushup(mid,t[mid].r);
//
t[mid].sum=t[mid].w+t[t[mid].l].sum+t[t[mid].r].sum;
return mid;
}
void insert(int &now,int x,int D){
if(!now){now=x;return;}
if(t[x].d[D]==t[now].d[D] && t[x].d[!D]==t[now].d[!D]){
t[now].w+=t[x].w;
t[now].sum+=t[x].w;
--cnt;
return;
}
if(t[x].d[D]<t[now].d[D]){
insert(t[now].l,x,D^);
pushup(now,t[now].l);
}
else{
insert(t[now].r,x,D^);
pushup(now,t[now].r);
}
t[now].sum=t[now].w+t[t[now].l].sum+t[t[now].r].sum;
return;
}
LL query(int rt,int x1,int y1,int x2,int y2){
if(!rt)return ;
LL res=;
if(in(x1,y1,x2,y2,rt)){return t[rt].sum;}
if(out(x1,y1,x2,y2,rt)){return ;}
if(x1<=t[rt].d[] && t[rt].d[]<=x2 &&
y1<=t[rt].d[] && t[rt].d[]<=y2) res+=t[rt].w;
res+=query(t[rt].l,x1,y1,x2,y2)+query(t[rt].r,x1,y1,x2,y2);
return res;
}
int main(){
int i,j,op,x,y,w;
n=read();lim=;
LL lans=;int X1,X2,Y1,Y2;
while(){
op=read();
if(op==)break;
if(op==){
t[++cnt].d[]=read()^lans;t[cnt].d[]=read()^lans;
t[cnt].w=read()^lans;t[cnt].sum=t[cnt].w;
t[cnt].max[]=t[cnt].min[]=t[cnt].d[];
t[cnt].max[]=t[cnt].min[]=t[cnt].d[];
insert(root,cnt,);
if(cnt==lim){
lim+=;
root=Build(,cnt,);
}
}
else{ X1=read()^lans;Y1=read()^lans;X2=read()^lans;Y2=read()^lans;
lans=query(root,X1,Y1,X2,Y2);
printf("%lld\n",lans);
}
}
return ;
}
Bzoj4066 简单题的更多相关文章
- [BZOJ2683][BZOJ4066]简单题
[BZOJ2683][BZOJ4066]简单题 试题描述 你有一个N*N的棋盘,每个格子内有一个整数,初始时的时候全部为0,现在需要维护两种操作: 命令 参数限制 内容 1 x y A 1<=x ...
- bzoj4066: 简单题 K-Dtree
bzoj4066: 简单题 链接 bzoj 思路 强制在线.k-dtree. 卡常啊.空间开1e6就T了. 代码 #include <bits/stdc++.h> #define my_m ...
- BZOJ4066 简单题(KD-Tree)
板子题. #include<iostream> #include<cstdio> #include<cmath> #include<cstdlib> # ...
- 【kd-tree】bzoj4066 简单题
同p1176. #include<cstdio> #include<cmath> #include<algorithm> using namespace std; ...
- BZOJ4066:简单题(K-D Tree)
Description 你有一个N*N的棋盘,每个格子内有一个整数,初始时的时候全部为0,现在需要维护两种操作: 命令 参数限制 内容 1 x y A 1<=x,y<=N,A是正整数 ...
- 【BZOJ4066】简单题(KD-Tree)
[BZOJ4066]简单题(KD-Tree) 题面 BZOJ 题解 如果这题不卡空间,并且不强制在线的话 显然可以用\(CDQ\)分治做 但是它又卡空间又强制在线,于是我们欢快的来用\(KD-Tree ...
- 【BZOJ4066】简单题 KDtree
[BZOJ4066]简单题 Description 你有一个N*N的棋盘,每个格子内有一个整数,初始时的时候全部为0,现在需要维护两种操作: 命令 参数限制 内容 1 x y A 1<=x,y& ...
- [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] ...
随机推荐
- handlebars+require
handlebars+require 最近在某网站看到了handlebars.js,出于好奇就百度了下这是神马玩意,结果让我很是欢喜,于是就开始自学下,handlebars就几个方法,蛮简单,言归正传 ...
- mybatis 3.x 缓存Cache的使用
mybatis 3.x 已经支持cache功能了,使用很简单,在mappper的xml文件里添加以下节点: <mapper namespace="com.cnblogs.yjmyzz. ...
- 2015-2016-2 《Java程序设计》 游戏化
2015-2016-2 <Java程序设计> 游戏化 实践「<程序设计教学法--以Java程序设计为例>」中的「游戏化(Gamification)理论」,根据 2015-201 ...
- 关于BOM
BOM:浏览器对象模型 (Browser Object Model)主要定义的是JS操作浏览器的方法和属性. 大部分方法都在window下. 常用方法:(JS里面规定如果方法前面是window,win ...
- Android反编译工具的使用-Android Killer
今天百度搜索“Android反编译”搜索出来的结果大多数都是比较传统的教程.刚接触反编译的时候,我也是从这些教程慢慢学起的.在后来的学习过程中,我接触到比较方便操作的Android反编译.在这,我将使 ...
- WordPress使用固定链接
WordPress安装后我们会发现,文章默认的url是很丑的,http://example.com/?p=N,其中N是文章ID,一串数字.默认链接在所有的环境下都运转良好,但和其他的类型比起来却没那么 ...
- Android开发自学笔记—1.1(番外)AndroidStudio常用功能介绍
一.界面区介绍 1.项目组织结构区,用于浏览项目文件,默认Project以Android组织方式展示. 2.设计区,默认在打开布局文件时为设计模式,可直接拖动控件到界面上实现所见即所得,下方的Desi ...
- jquery的getjson与jsonp
仔细的学习jquery的getjson的用法. http://www.cnblogs.com/leejersey/p/3750232.html http://www.jb51.net/article/ ...
- [BZOJ1924][Sdoi2010]所托门王的宝藏(缩点+DP)
题目:http://www.lydsy.com:808/JudgeOnline/problem.php?id=1924 分析: 首先把传送门作为点建图 这个数据很弱的,没有那种卡你的. 把每行的情况存 ...
- 关于document.getElement获取元素返回值的问题
获取网页元素有很多种方法,如下: document.all[];返回HTMLElement对象 document.all.tags[];返回NodeList对象,类似数组 document.getEl ...