Time Limit: 50 Sec  Memory Limit: 128 MB
Submit: 1071  Solved: 428

Description

你有一个N*N的棋盘,每个格子内有一个整数,初始时的时候全部为0,现在需要维护两种操作:

命令

参数限制

内容

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

输入文件第一行一个正整数N。
接下来每行一个操作。
 

Output

对于每个2操作,输出一个对应的答案。
 

Sample Input

4
1 2 3 3
2 1 1 3 3
1 2 2 2
2 2 2 3 4
3

Sample Output

3
5

HINT

1<=N<=500000,操作数不超过200000个,内存限制20M。
对于100%的数据,操作1中的A不超过2000。

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 简单题的更多相关文章

  1. [BZOJ2683]简单题/[BZOJ1176][BalkanOI2007]Mokia

    [BZOJ2683]简单题 题目大意: 一个\(n\times n(n\le5\times10^5)\)的矩阵,初始时每个格子里的数全为\(0\).\(m(m\le2\times10^5)\)次操作, ...

  2. bzoj2683简单题 cdq分治

    2683: 简单题 Time Limit: 50 Sec  Memory Limit: 128 MBSubmit: 1803  Solved: 731[Submit][Status][Discuss] ...

  3. bzoj2683简单题

    #include <iostream> #include <cstdio> #include <cmath> #include <algorithm> ...

  4. BZOJ2683: 简单题(cdq分治 树状数组)

    Time Limit: 50 Sec  Memory Limit: 128 MBSubmit: 2142  Solved: 874[Submit][Status][Discuss] Descripti ...

  5. BZOJ2683 简单题(CDQ分治)

    传送门 之前听别人说CDQ分治不难学,今天才知道果真如此.之前一直为自己想不到CDQ的方法二很不爽,今天终于是想出来了一道了,太弱-- cdq分治主要就是把整段区间分成两半,然后用左区间的值去更新右区 ...

  6. Bzoj2683 简单题 [CDQ分治]

    Time Limit: 50 Sec  Memory Limit: 128 MBSubmit: 1071  Solved: 428 Description 你有一个N*N的棋盘,每个格子内有一个整数, ...

  7. 【对询问分块】【主席树】bzoj2683 简单题

    对操作序列分块,每S次暴力重建主席树. 当S=sqrt(n*log(n))时,复杂度为O(m*sqrt(n*log(n))). 在线的. #include<cstdio> #include ...

  8. cdq分治——bzoj2683简单题

    https://www.lydsy.com/JudgeOnline/problem.php?id=2683 知识点:1.以操作的顺序进行分治  2.cdq分治维护矩阵 3.计算比mid小的给比mid大 ...

  9. [BZOJ2683][BZOJ4066]简单题

    [BZOJ2683][BZOJ4066]简单题 试题描述 你有一个N*N的棋盘,每个格子内有一个整数,初始时的时候全部为0,现在需要维护两种操作: 命令 参数限制 内容 1 x y A 1<=x ...

随机推荐

  1. 内网机(无网络安装 .NET Core win开发环境

    1.安装 vs2015 update3 2.按顺序安装以下包 DotNetCore.1.0.0-SDK.Preview2-x64.exe aspnetcoremodule_x64_en_rc2_14. ...

  2. swift 随机生成背景颜色

    swift是一门新语言,相关的文档资料现在基本上还不是很完整.在尝试开发过程中,走了不少弯路.在这里记录一下自己的”路“,希望以后能少走弯路. 生成随机背景颜色使用的语法和C#或者JAVA基本一致. ...

  3. 如何把Json格式字符写进text文件中

    本篇一步一步学习怎样把显示于网页的json格式的字符串写进text文件中,并保存起来.学习到创建model, Entity, 序列化List<object>转换为json,显示于网页上.然 ...

  4. Makefile 中:= ?= += =的区别

    在Makefile中我们经常看到 = := ?= +=这几个赋值运算符,那么他们有什么区别呢?我们来做个简单的实验 新建一个Makefile,内容为:ifdef DEFINE_VRE    VRE = ...

  5. caffe的python接口学习(2):生成solver文件

    caffe在训练的时候,需要一些参数设置,我们一般将这些参数设置在一个叫solver.prototxt的文件里面,如下: base_lr: 0.001 display: 782 gamma: 0.1 ...

  6. datahub

    https://help.aliyun.com/document_detail/27854.html

  7. Theano2.1.2-基础知识之第一步:代数

    来自:http://deeplearning.net/software/theano/tutorial/adding.html Baby Steps - Algebra 一.两个标量相加 在学习the ...

  8. 大新闻!HoloLens即将入华商用

    昨天微软搞了大新闻,Terry和Alexi到了深圳,在WinHEC大会上宣布了2017上半年HoloLens正式入华商用. 关于HoloLens的技术原理和细节官方文档和报道已经披露很多了,他是一款真 ...

  9. nodepad++快捷键收集

    Notepad++ 快捷键 大全Ctrl+C 复制Ctrl+X 剪切Ctrl+V 粘贴Ctrl+Z 撤消Ctrl+Y 恢复Ctrl+A 全选Ctrl+F 键查找对话框启动Ctrl+H 查找/替换对话框 ...

  10. 【转】XSD (xml Schema Definition)

    来自:http://www.cnblogs.com/newsouls/archive/2011/10/28/2227765.html Xml Schema的用途 1.  定义一个Xml文档中都有什么元 ...