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 ...
随机推荐
- IOS UIPickView+sqlite 选择中国全部城市案例
1.案例简单介绍 通过读取文件.将中国全部城市写入sqlite数据库中,现通过UIPickView实现中国全部城市的选择,效果图例如以下所看到的 2.城市对象模型 中国全部城市数据请看http://b ...
- Android开发的环境搭建及HelloWorld的实现
安装JDK和配置Java开发环境 http://www.oracle.com/technetwork/java/javase/downloads/java-se-jdk-7-download-4321 ...
- 从头学起-CLR的执行模型
1.将源代码编译成托管代码 公共运行时(Common Language Runtime) a.面向运行时的所有语言都可以通过异常报告错误 b.面向运行时的所有语言都可以创建线程 c.核心功能:管理内存 ...
- c#中的多态 c#中的委托
C#中的多态性 相信大家都对面向对象的三个特征封装.继承.多态很熟悉,每个人都能说上一两句,但是大多数都仅仅是知道这些是什么,不知道CLR内部是如何实现的,所以本篇文章主要说说多态性 ...
- net spy memcached 使用demo
package memcached; import java.io.IOException; import java.net.InetSocketAddress; import net.spy.mem ...
- HTML5与Javascript 实现网页弹球游戏
终于效果图: 1. 使用html 5 的canvas 技术和javascript实现弹球游戏 总体流程图: 1.1 html5 canvas技术的使用 首先在html页面中定义画布. <canv ...
- ios自动生成对象类,提高开发速率
#import "autoGenerationFileUtility.h" @implementation autoGenerationFileUtility - (void)cr ...
- Python开发【2.3 模块】
1.模块导入 import 模块名 from 模块名 import 函数/类/变量 2.模块路径 import sys sys.path 3.模块重新导入 Python3若想在同一次会话中再次运行文件 ...
- 检測磁盘驱动的健康程度SMART
在server中,全部组件中一般最easy坏掉的就是磁盘.所以一般採取RAID来保证系统的稳定性,通过冗余磁盘的方式防止磁盘故障. 现代硬件驱动器一般支持SMART(自我监測分析和报告技术),它可以监 ...
- Django之cookie 和 session
一. 1.cookie的由来!!! 由于HTTP协议是无状态的,既每一次的请求都是独立的,他不会因为你之前来过,就记住你,所以每次浏览器去访问服务器的时候,都是一个全新的过程,之前的数据也不会保留,所 ...