Bzoj2683 简单题
Time Limit: 50 Sec Memory Limit: 128 MB
Submit: 1071 Solved: 428
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 2 2 2
2 2 2 3 4
3
Sample Output
5
HINT
Source
嘛,真是简单题啊,才调了两天就过了。
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; ; LL read(){ LL x=,f=;char ch=getchar(); ;ch=getchar();} +ch-';ch=getchar();} return x*f; } struct node{ int l,r; ],max[]; ]; int w; LL sum; }t[mxn]; ,nowD; int cmp(const node a,const node b){ return a.d[nowD]<b.d[nowD]; } int n,cnt; ; 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){ ] && 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){ ] || x2<t[k].min[] || y1>t[k].max[] || y2<t[k].min[]); } int Build(int l,int r,int D){ ; nowD=D;; 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){ ; LL res=; if(in(x1,y1,x2,y2,rt)){return t[rt].sum;} ;} ] && 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=; int X1,X2,Y1,Y2; ){ op=read(); )break; ){ t[++cnt].d[]=read();t[cnt].d[]=read(); t[cnt].w=read();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();Y1=read();X2=read();Y2=read(); printf("%lld\n",query(root,X1,Y1,X2,Y2)); } } ; }
Bzoj2683 简单题的更多相关文章
- [BZOJ2683]简单题/[BZOJ1176][BalkanOI2007]Mokia
[BZOJ2683]简单题 题目大意: 一个\(n\times n(n\le5\times10^5)\)的矩阵,初始时每个格子里的数全为\(0\).\(m(m\le2\times10^5)\)次操作, ...
- bzoj2683简单题 cdq分治
2683: 简单题 Time Limit: 50 Sec Memory Limit: 128 MBSubmit: 1803 Solved: 731[Submit][Status][Discuss] ...
- bzoj2683简单题
#include <iostream> #include <cstdio> #include <cmath> #include <algorithm> ...
- BZOJ2683: 简单题(cdq分治 树状数组)
Time Limit: 50 Sec Memory Limit: 128 MBSubmit: 2142 Solved: 874[Submit][Status][Discuss] Descripti ...
- BZOJ2683 简单题(CDQ分治)
传送门 之前听别人说CDQ分治不难学,今天才知道果真如此.之前一直为自己想不到CDQ的方法二很不爽,今天终于是想出来了一道了,太弱-- cdq分治主要就是把整段区间分成两半,然后用左区间的值去更新右区 ...
- Bzoj2683 简单题 [CDQ分治]
Time Limit: 50 Sec Memory Limit: 128 MBSubmit: 1071 Solved: 428 Description 你有一个N*N的棋盘,每个格子内有一个整数, ...
- 【对询问分块】【主席树】bzoj2683 简单题
对操作序列分块,每S次暴力重建主席树. 当S=sqrt(n*log(n))时,复杂度为O(m*sqrt(n*log(n))). 在线的. #include<cstdio> #include ...
- cdq分治——bzoj2683简单题
https://www.lydsy.com/JudgeOnline/problem.php?id=2683 知识点:1.以操作的顺序进行分治 2.cdq分治维护矩阵 3.计算比mid小的给比mid大 ...
- [BZOJ2683][BZOJ4066]简单题
[BZOJ2683][BZOJ4066]简单题 试题描述 你有一个N*N的棋盘,每个格子内有一个整数,初始时的时候全部为0,现在需要维护两种操作: 命令 参数限制 内容 1 x y A 1<=x ...
随机推荐
- Web API删除JSON格式的文件记录
Insus.NET的系列Web Api学习文章,这篇算是计划中最后一篇了,删除JSON格式的文件记录.前一篇<Web Api其中的PUT功能演示>http://www.cnblogs.co ...
- codevs3143 二叉树的序遍历
难度等级:白银 3143 二叉树的序遍历 题目描述 Description 求一棵二叉树的前序遍历,中序遍历和后序遍历 输入描述 Input Description 第一行一个整数n,表示这棵树的节点 ...
- Android的媒体管理框架:Glide
Glide是一个高效.开源. Android设备上的媒体管理框架,它遵循BSD.MIT以及Apache 2.0协议发布.Glide具有获取.解码和展示视频剧照.图片.动画等功能,它还有灵活的API,这 ...
- shell 使用
echo -e "1\t2\t3" #-e echo -e "\e[1;31m This is red text \e[0m" #color echo -e & ...
- 安装Ubuntu时的硬盘分区方案
如果你准备在硬盘里只安装Ubuntu一个操作系统的话,建议你采用一个“/”.一个“swap”和一个“/home”的三分区方案:/ :10GB-15GB.swap:物理内存小于或等于 512MB,建议分 ...
- Python2.5-原理之模块
此部分来自于<Python学习手册>第五部分 一.模块(21章) 模块是最高级别的程序组织单元,它将程序代码和数据封装起来以便重用..模块往往对应于python程序文件.每个文件就是一个模 ...
- JavaScript Array
1.常用方法 // 数组构造 var a = new Array(20); // 长度为20的数组 var b = new Array('red', 'blue', 'white'); var c = ...
- C# 7.0 新特性1: 基于Tuple的“多”返回值方法
本文基于Roslyn项目中的Issue:#347 展开讨论. 1. C# 7.0 新特性1: 基于Tuple的“多”返回值方法 2. C# 7.0 新特性2: 本地方法 3. C# 7.0 新特性3: ...
- HTML5+JS 《五子飞》游戏实现(一)规则
很久没写文章了,这个游戏其实已经写了有段时间了,一直没有完善,赶在新年之际,分享给大家. 该<五子飞>游戏,不是平常大家所说的<五子棋>,这个玩法简单,是我们老家儿时常玩的一种 ...
- [HDOJ5445]Food Problem(优先队列优化多重背包)
题目:http://acm.hdu.edu.cn/showproblem.php?pid=5445 题意:多重背包 分析:f[i][j]=max(f[i-1][j-k*w[i]]+k*v[i]) 将j ...