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 ...
随机推荐
- LeetCode——Binary Tree Level Order Traversal
Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, ...
- iOS simulator+Appium
Why are you trying to run iOS automation on a real device? That's a bad idea. iOS Automation on a re ...
- Apache Qpid消息通讯模型和消息地址简介
Broker知识准备 Broker内置两种节点类型:一种是 queue,一种是 topic. 1. queue 节点能够缓存消息,直到被读取走为止.queue节点满足两个重要的 PTP 通信的特征, ...
- Leetcode(58)题解:Length of Last Word
https://leetcode.com/problems/length-of-last-word/ 题目: Given a string s consists of upper/lower-case ...
- 将线上服务器生成的日志信息实时导入kafka,采用agent和collector分层传输,app的数据通过thrift传给agent,agent通过avro sink将数据发给collector,collector将数据汇集后,发送给kafka
记flume部署过程中遇到的问题以及解决方法(持续更新) - CSDN博客 https://blog.csdn.net/lijinqi1987/article/details/77449889 现将调 ...
- org.gradle.api.publication.maven.internal.DefaultMavenFactory错误
Error:Unable to load class 'org.gradle.api.publication.maven.internal.DefaultMavenFactory'. Possible ...
- iOS UI控件之间的关系图
- maven安装的详细步骤
1.下载maven的bin,在apache官方网站下载.window系统下的下载红色方框的 2.解压后, 把bin的位置设在环境变量里,新建环境变量 MAVEN_HOME.这个配置是方便以后更换mav ...
- hdu 1166 敌兵布阵 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1166 题目意思:给出 N 个数你,通过对某些数进行更改(或者 + 或者 -),当输入的是 Query ...
- Oracle基础:表空间名称大小写问题
现场环境: 操作系统:windows Oracle版本:10g 今天在通过imp导入数据时,日志提示TS_W5_D表空间不存在.感觉很奇怪,导入用户的表空间是ts_w5_d,并 ...