bzoj 1176 [Balkan2007]Mokia 【CDQ分治】
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=;
int n,s,qu,tot,ans[N],t[N],p[N],cnt,q[N];
struct qwe
{
int o,x,y,v,n;
qwe(){}
qwe(int a1,int a2,int a3,int a4,int a5)
{
o=a1,x=a2,y=a3,v=a4,n=a5;
}
}a[N];
bool cmp(const qwe &a,const qwe &b)
{
return (a.x==b.x&&a.y==b.y&&a.o<b.o)||(a.x==b.x&&a.y<b.y)||(a.x<b.x);
}
int read()
{
int r=,f=;
char p=getchar();
while(p>''||p<'')
{
if(p=='-')
f=-;
p=getchar();
}
while(p>=''&&p<='')
{
r=r*+p-;
p=getchar();
}
return r*f;
}
int lb(int x)
{
return x&(-x);
}
void update(int x,int v)
{
for(int i=x;i<=n;i+=lb(i))
t[i]+=v;
}
int ques(int x)
{
int r=;
for(int i=x;i>=;i-=lb(i))
r+=t[i];
return r;
}
void cdq(int l,int r)
{
if(l==r)
return;
int mid=(l+r)/,tmp=;
cdq(l,mid);
cdq(mid+,r);
sort(a+l,a+mid+,cmp);
sort(a+mid+,a+r+,cmp);
int i=l,j=mid+;
while(j<=r)
{
for(;a[i].o==&&i<=mid;i++);
for(;a[j].o==&&j<=r;j++);
if(i<=mid&&a[i].x<=a[j].x)
update(a[i].y,a[i].v),i++,tmp=i-;
else if(j<=r)
ans[a[j].n]+=ques(a[j].y),j++;
}
for(int t=l;t<=tmp;t++)
if(a[t].o==)
update(a[t].y,-a[t].v);
}
int main()
{
s=read();n=read();
while()
{
qu=read();
if(qu==)
break;
if(qu==)
{
int x=read(),y=read(),z=read();
a[++tot]=qwe(,x,y,z,tot);
}
else
{
int x1=read(),y1=read(),x2=read(),y2=read();
p[++cnt]=tot;
q[cnt]=(x2-x1+)*(y2-y1+)*s;
a[++tot]=qwe(,x1-,y1-,,tot);
a[++tot]=qwe(,x2,y2,,tot);
a[++tot]=qwe(,x1-,y2,,tot);
a[++tot]=qwe(,x2,y1-,,tot);
}
}
cdq(,tot);
for(int i=;i<=cnt;i++)
printf("%d\n",q[i]+ans[p[i]+]+ans[p[i]+]-ans[p[i]+]-ans[p[i]+]);
return ;
}
bzoj 1176 [Balkan2007]Mokia 【CDQ分治】的更多相关文章
- BZOJ 1176: [Balkan2007]Mokia( CDQ分治 + 树状数组 )
考虑cdq分治, 对于[l, r)递归[l, m), [m, r); 然后计算[l, m)的操作对[m, r)中询问的影响就可以了. 具体就是差分答案+排序+离散化然后树状数组维护.操作数为M的话时间 ...
- BZOJ 1176[Balkan2007]Mokia(CDQ分治)
1176: [Balkan2007]Mokia Time Limit: 30 Sec Memory Limit: 162 MBSubmit: 3381 Solved: 1520[Submit][S ...
- BZOJ 1176: [Balkan2007]Mokia [CDQ分治]
题意: 有一个n * n的棋盘,每个格子内有一个数,初始的时候全部为0.现在要求维护两种操作: 1)Add:将格子(x, y)内的数加上A. 2)Query:询问矩阵(x0, y0, x1, y1)内 ...
- BZOJ 1176 [Balkan2007]Mokia ——CDQ分治
[题目分析] 同BZOJ2683,只需要提前处理s对结果的影响即可. CDQ的思路还是很清晰的. 排序解决一维, 分治时间, 树状数组解决一维. 复杂度是两个log [代码] #include < ...
- BZOJ 1176: [Balkan2007]Mokia
1176: [Balkan2007]Mokia Time Limit: 30 Sec Memory Limit: 162 MBSubmit: 2012 Solved: 896[Submit][St ...
- bzoj 1176: [Balkan2007]Mokia&&2683: 简单题 -- cdq分治
2683: 简单题 Time Limit: 50 Sec Memory Limit: 128 MB Description 你有一个N*N的棋盘,每个格子内有一个整数,初始时的时候全部为0,现在需要 ...
- BZOJ1176: [Balkan2007]Mokia CDQ分治
最近很不对啊=w= 写程序全是bug啊 ans数组开小了竟然一直不知道,小数据没问题大数据拍不过,交上去RE 蛋疼半天 这个主要把每次询问拆成3个询问. #include<cstdio> ...
- BZOJ 1176: [Balkan2007]Mokia KDtree
Code: #include<bits/stdc++.h> #define setIO(s) freopen(s".in","r",stdin), ...
- BZOJ 1176 Mokia CDQ分治+树状数组
1176: [Balkan2007]Mokia Time Limit: 30 Sec Memory Limit: 162 MBSubmit: 1854 Solved: 821[Submit][St ...
随机推荐
- 怎样去除JSP页面提示:Cannot return from outside a function or method.
今天用myeclipse10写JSP页面时出现: Cannot return from outside a function or method. onClick="return ch ...
- ADO.NET 对数据操作 以及如何通过C# 事务批量导入数据
ADO.NET 对数据操作 以及如何通过C# 事务批量导入数据 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 ...
- linux中select网络通信
//ser.cpp #include <iostream> #include <fcntl.h> #include <sys/socket.h> #include ...
- 解决:Android4.3锁屏界面Emergency calls only - China Unicom与EMERGENCY CALL语义反复
从图片中我们能够看到,这里在语义上有一定的反复,当然这是谷歌的原始设计.这个问题在博客上进行共享从表面上来看着实没有什么太大的意义,只是因为Android4.3在锁屏功能上比起老版本号做了非常大的修改 ...
- 漫谈程序猿系列:无BUG不生活
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvZm9ydW9r/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/d ...
- linux getopt函数详解
getopt(分析命令行参数) 表头文件 #include<unistd.h> 定义函数 int getopt(int argc,char * const argv[ ],const ...
- 基于ADB框架Robotium跨进程操作
转自:http://blog.csdn.net/qingchunjun/article/details/42580937 2015年2月3日更新: 有些朋友在用真机尝试本方法时,抛出了InputStr ...
- 修复Xcode升级错误 — PCH File Error
http://www.rockia.net/2013/03/fix-xcode-update-pch-file-error Error:PCH File Built From A Different ...
- Lazy freeing of keys 对数据的额异步 同步操作 Redis 4.0 微信小程序
https://github.com/antirez/redis/blob/4.0-rc1/00-RELEASENOTES 数据缓存 · 小程序 https://developers.weixin.q ...
- 如何去除Office Excel的密码保护?
企图更改Excel文件内容,然而却弹出如下提示: 根据提示,我尝试解除保护表,却要求输入密码: 这就尴尬了=_=密码不是我设定的 问了度娘,找到了解决方案 将Excel文件扩展名更改为rar, 使用压 ...