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 ...
随机推荐
- 使用虚拟机VM运行Linux版OpenERP
Table of Contents 下载.安装vmware player --免费 从百度云下载 镜像文件 建立vm 运行vm 访问openerp 更新代码至最新 下载.安装vmwar ...
- font-family,font-size,color
CreateTime--2017年12月20日16:43:35 Author:Marydon css设置字体样式 1.font-family 语法:属性值可以有一个或多个,多个值之间使用逗号隔开. ...
- Android兼容性测试CTS
一.简介 为了确保Android应用能够在所有兼容Android的设备上正确运行,并且保持相似的用户体验,在每个版本发布之时,Android提供了一套兼容性测试用例集合(Compatibility ...
- WCF 内存入口检查失败 Memory gates checking failed
在做JC系统时,出现这样的错误: 出现该错误信息的原因是因为WCF服务激活之前,系统应该具有的最小内存量不足config文件中设置的百分比.我是在本机调试的时候出现的. 解决方法: 关闭 ...
- 用JAVA编写浏览器内核之实现javascript的document对象与内置方法
原创文章.转载请注明. 阅读本文之前,您须要对浏览器怎样载入javascript有一定了解. 当然,对java与javascript本身也须要了解. 本文首先介绍浏览器载入并执行javascript的 ...
- eclipse svn org.tigris.subversion.javahl.ClientException: RA layer request failed
突然之间eclipse使用svn更新项目时报错,org.tigris.subversion.javahl.ClientException: RA layer request failed 网上搜的都是 ...
- 诊断并解决 ORA-4030 错误 (Doc ID 1548826.1)
适用于: Oracle Database - Enterprise Edition - 版本号 8.1.7.4 和更高版本号 本文档所含信息适用于全部平台 用途 怎样诊断 ORA-4030 错误 排错 ...
- 项目Alpha冲刺(团队8/10)
项目Alpha冲刺(团队8/10) 团队名称: 云打印 作业要求: 项目Alpha冲刺(团队) 作业目标: 完成项目Alpha版本 团队队员 队员学号 队员姓名 个人博客地址 备注 221600412 ...
- Java虚拟机平台无关性
jruby Java 虚拟机面试题全面解析(干货) - Yano_nankai的博客 - CSDN博客 http://m.blog.csdn.net/Yano_nankai/article/detai ...
- MongoDB and Redis
简介 MongoDB更类似MySQL,支持字段索引.游标操作,其优势在于查询功能比较强大,擅长查询JSON数据,能存储海量数据,但是不支持事务. Mysql在大数据量时效率显著下降,MongoDB更多 ...