bzoj2683
2683: 简单题
Time Limit: 50 Sec Memory Limit: 128 MB
Submit: 1018 Solved: 413
[Submit][Status][Discuss]
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
#include<cstdio>
#include<vector>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=;
struct data
{
int x,y,dir,pos,type,delta;
}event[N];
int n,size,w,s,m,pos,opt;
vector<data> c;
int tree[N],ans[N];
bool cp(data x,data y)
{
if(x.x!=y.x) return x.x<y.x;
if(x.y!=y.y) return x.y<y.y;
return x.type<y.type;
}
int lowbit(int x)
{
return x&(-x);
}
void update(int pos,int delta)
{
for(int i=pos;i<=N+;i+=lowbit(i))
{
tree[i]+=delta;
}
}
int sum(int pos)
{
int ret=;
for(int i=pos;i>;i-=lowbit(i))
{
ret+=tree[i];
}
return ret;
} void cdq(int l,int r)
{
if(l>=r) return;
int mid=(l+r)/;
cdq(l,mid);
cdq(mid+,r);
c.clear();
for(int i=l;i<=mid;i++)
if(event[i].type==) c.push_back(event[i]);
for(int i=mid+;i<=r;i++)
if(event[i].type==) c.push_back(event[i]);
sort(c.begin(),c.end(),cp);
for(int i=;i<c.size();i++)
{
// printf("type=%d pos=%d\n",c[i].type,c[i].pos);
if(c[i].type==)
update(c[i].y,c[i].delta);
if(c[i].type==)
{
ans[c[i].pos]+=sum(c[i].y)*c[i].dir;
// printf("%d\n",sum(c[i].y));
}
}
for(int i=;i<c.size();i++)
if(c[i].type==) update(c[i].y,-c[i].delta);
} void addquery(int x,int y,int dir)
{
event[++m].x=x; event[m].y=y;
event[m].dir=dir; event[m].pos=pos;
event[m].type=;
} int main()
{
scanf("%d",&s);
while(scanf("%d",&opt))
{
if(opt==) break;
int x,y,delta,x1,y1,x2,y2;
if(opt==)
{
scanf("%d%d%d",&x,&y,&delta);
x++;
y++;
m++;
event[m].type=opt;
event[m].x=x;
event[m].y=y;
event[m].delta=delta;
}
else if(opt==)
{
++pos;
//ans[++pos]+=abs(x1-x2)*abs(y1-y2)*s;
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
x1++; x2++; y1++; y2++;
addquery(x1-,y1-,);
addquery(x2,y2,);
addquery(x1-,y2,-);
addquery(x2,y1-,-);
}
}
cdq(,m);
for(int i=;i<=pos;i++)
{
printf("%d\n",ans[i]);
}
return ;
}
bzoj2683的更多相关文章
- [BZOJ2683][BZOJ4066]简单题
[BZOJ2683][BZOJ4066]简单题 试题描述 你有一个N*N的棋盘,每个格子内有一个整数,初始时的时候全部为0,现在需要维护两种操作: 命令 参数限制 内容 1 x y A 1<=x ...
- [BZOJ2683]简单题/[BZOJ1176][BalkanOI2007]Mokia
[BZOJ2683]简单题 题目大意: 一个\(n\times n(n\le5\times10^5)\)的矩阵,初始时每个格子里的数全为\(0\).\(m(m\le2\times10^5)\)次操作, ...
- 【BZOJ1176】[Balkan2007]Mokia/【BZOJ2683】简单题 cdq分治
[BZOJ1176][Balkan2007]Mokia Description 维护一个W*W的矩阵,初始值均为S.每次操作可以增加某格子的权值,或询问某子矩阵的总权值.修改操作数M<=1600 ...
- 【bzoj1176】[Balkan2007]Mokia/【bzoj2683】简单题 CDQ分治+树状数组
bzoj1176 题目描述 维护一个W*W的矩阵,初始值均为S(题目描述有误,这里的S没有任何作用!).每次操作可以增加某格子的权值,或询问某子矩阵的总权值.修改操作数M<=160000,询问数 ...
- BZOJ2683 简单题(CDQ分治)
传送门 之前听别人说CDQ分治不难学,今天才知道果真如此.之前一直为自己想不到CDQ的方法二很不爽,今天终于是想出来了一道了,太弱-- cdq分治主要就是把整段区间分成两半,然后用左区间的值去更新右区 ...
- bzoj2683简单题
#include <iostream> #include <cstdio> #include <cmath> #include <algorithm> ...
- Bzoj2683 简单题 [CDQ分治]
Time Limit: 50 Sec Memory Limit: 128 MBSubmit: 1071 Solved: 428 Description 你有一个N*N的棋盘,每个格子内有一个整数, ...
- Bzoj2683 简单题
Time Limit: 50 Sec Memory Limit: 128 MBSubmit: 1071 Solved: 428 Description 你有一个N*N的棋盘,每个格子内有一个整数, ...
- bzoj2683简单题 cdq分治
2683: 简单题 Time Limit: 50 Sec Memory Limit: 128 MBSubmit: 1803 Solved: 731[Submit][Status][Discuss] ...
随机推荐
- Android studio 使用Gradle发布Android开源项目到JCenter 总结
1.注册账号 先到https://bintray.com注册一个账号. 这个网站支持 github 账户直接登录的 2.获取 bintray.user 和 bintray.apikey ...
- iOS cocoapods升级及问题
安装 安装RubyCocoaPods基于Ruby语言开发而成,因此安装CocoaPods前需要安装Ruby环境.幸运的是Mac系统默认自带Ruby环境,如果没有请自行查找安装.检测是否安装Ruby:$ ...
- iOS UIRefreshControl-刷新tableView
override func viewDidLoad() { super.viewDidLoad() refreshControl = UIRefreshControl.in ...
- 【iOS】在Swift中使用JSONModel
前言 首先所有的Model还是使用oc来写——看到这一句是不是想关网页了- - #,在swift里面直接写一直报错所以就将就用oc来写了,这里主要是分享一下搭配Alamofire使用的经验. 声明 欢 ...
- IOS 杂笔-16 (-(void)scrollViewDidEndScrollingAnimation:方法使用注意)
今天在写项目的时候,遇到了一件令人抓狂的事情. 正如标题所示,被这个方法弄的团团转. -(void)scrollViewDidEndScrollingAnimation:是协议里的方法. 意味当动画结 ...
- xCode5 在ios7模拟器中出现__cxa_throw _pthread_exit错误
xCode5 在ios7模拟器中出现__cxa_throw _pthread_exit错误 2013年10月28日 ⁄ 综合 ⁄ 共 233字 ⁄ 字号 小 中 大 ⁄ 评论关闭 在项目中用模拟器 ...
- OC 面试问题汇总
OC 问题汇总: 1. 你如何理解 iOS 内存管理 1. new alloc copy retain这些对象我们都要主动的release或者 autorelease 2. 如果是类方法创建的 ...
- 分布式架构中一致性解决方案——Zookeeper集群搭建
当我们的项目在不知不觉中做大了之后,各种问题就出来了,真jb头疼,比如性能,业务系统的并行计算的一致性协调问题,比如分布式架构的事务问题, 我们需要多台机器共同commit事务,经典的案例当然是银行转 ...
- SQL Server中使用PIVOT行转列
使用PIVOT行转列 1.建表及插入数据 USE [AdventureDB] GO /****** Object: Table [dbo].[Score] Script Date: 11/25/201 ...
- IE8 ajax缓存问题
娘希匹,又遇到缓存问题了. 下面的代码,在其他浏览器都是正常的,但是在IE8中出现诡异问题. $.ajax({ url:dataUrl, data:encodeURI(currentjsonform) ...