[题目链接]

https://www.lydsy.com/JudgeOnline/problem.php?id=1176

[算法]

CDQ分治 + 树状数组即可

时间复杂度 : O(Nlog^2N)

[代码]

#include<bits/stdc++.h>
using namespace std;
const int N = ;
const int M = ;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull; struct Query
{
int pos , x , y , value , type , id;
} q[N * ] , t1[N * ] , t2[N * ]; int s , w , m , k;
int c[M] , ans[N]; template <typename T> inline void chkmax(T &x,T y) { x = max(x,y); }
template <typename T> inline void chkmin(T &x,T y) { x = min(x,y); }
template <typename T> inline void read(T &x)
{
T f = ; x = ;
char c = getchar();
for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
for (; isdigit(c); c = getchar()) x = (x << ) + (x << ) + c - '';
x *= f;
}
inline bool cmp(Query a , Query b)
{
if (a.x != b.x) return a.x < b.x;
else if (a.y != b.y) return a.y < b.y;
else return a.type < b.type;
}
inline int lowbit(int x)
{
return x & (-x);
}
inline void modify(int x , int val)
{
for (int i = x; i <= w; i += lowbit(i))
c[i] += val;
}
inline int query(int x)
{
int ret = ;
for (int i = x; i; i -= lowbit(i))
ret += c[i];
return ret;
}
inline void cdq(int l , int r)
{
int mid = (l + r) >> ;
if (l == r) return;
for (int i = l; i <= r; i++)
{
if (q[i].type == && q[i].pos <= mid) modify(q[i].y , q[i].value);
else if (q[i].type == && q[i].pos > mid) ans[q[i].id] += q[i].value * query(q[i].y);
}
for (int i = l; i <= r; i++)
{
if (q[i].type == && q[i].pos <= mid)
modify(q[i].y , -q[i].value);
}
int l1 = , l2 = ;
for (int i = l; i <= r; i++)
if (q[i].pos <= mid) t1[++l1] = q[i];
else t2[++l2] = q[i];
for (int i = ; i <= l1; i++) q[l + i - ] = t1[i];
for (int i = ; i <= l2; i++) q[l + l1 + i - ] = t2[i];
cdq(l , mid);
cdq(mid + , r);
} int main()
{ read(s); read(w);
while (true)
{
int type;
read(type);
if (type == ) break;
if (type == )
{
int x , y , a;
read(x); read(y); read(a);
q[++m] = (Query){m , x , y , a , , k};
} else
{
int X1 , Y1 , X2 , Y2;
read(X1); read(Y1); read(X2); read(Y2);
ans[++k] = s * (X2 - X1 + ) * (Y2 - Y1 + );
q[++m] = (Query){m , X2 , Y2 , , , k};
q[++m] = (Query){m , X1 - , Y2 , - , , k};
q[++m] = (Query){m , X2 , Y1 - , - , , k};
q[++m] = (Query){m , X1 - , Y1 - , , , k};
}
}
sort(q + , q + m + , cmp);
cdq( , m);
for (int i = ; i <= k; i++) printf("%d\n" , ans[i]); return ; }

[Balkan 2007] Mokia的更多相关文章

  1. 【BZOJ 1176】【Balkan 2007】Mokia

    http://www.lydsy.com/JudgeOnline/problem.php?id=1176 整体二分的例题 把每个询问拆成四个询问,整体二分里x坐标递增,按x坐标扫的时候用树状数组维护y ...

  2. [COGS 1752] 摩基亚Mokia

    照例先上题面 1752. [BOI2007]摩基亚Mokia 输入文件:mokia.in   输出文件:mokia.out 时间限制:1.5 s   内存限制:128 MB [题目描述] 摩尔瓦多的移 ...

  3. COGS1752. [BOI2007]摩基亚Mokia

    1752. [BOI2007]摩基亚Mokia ★★☆   输入文件:mokia.in   输出文件:mokia.out   简单对比时间限制:5 s   内存限制:128 MB [题目描述] 摩尔瓦 ...

  4. cogs1752[boi2007]mokia 摩基亚 (cdq分治)

    [题目描述] 摩尔瓦多的移动电话公司摩基亚(Mokia)设计出了一种新的用户定位系统.和其他的定位系统一样,它能够迅速回答任何形如“用户C的位置在哪?”的问题,精确到毫米.但其真正高科技之处在于,它能 ...

  5. COJS 1752. [BOI2007]摩基亚Mokia

    1752. [BOI2007]摩基亚Mokia ★★★   输入文件:mokia.in   输出文件:mokia.out   简单对比时间限制:5 s   内存限制:128 MB [题目描述] 摩尔瓦 ...

  6. ACdream1157 Segments(CDQ分治 + 线段树)

    题目这么说的: 进行如下3种类型操作:1)D L R(1 <= L <= R <= 1000000000) 增加一条线段[L,R]2)C i (1-base) 删除第i条增加的线段, ...

  7. poi读取excel模板,填充内容并导出,支持导出2007支持公式自动计算

    /** * 版权所有(C) 2016 * @author www.xiongge.club * @date 2016-12-7 上午10:03:29 */ package xlsx; /** * @C ...

  8. BZOJ 2007: [Noi2010]海拔

    2007: [Noi2010]海拔 Time Limit: 20 Sec  Memory Limit: 552 MBSubmit: 2410  Solved: 1142[Submit][Status] ...

  9. BZOJ 1176: [Balkan2007]Mokia

    1176: [Balkan2007]Mokia Time Limit: 30 Sec  Memory Limit: 162 MBSubmit: 2012  Solved: 896[Submit][St ...

随机推荐

  1. jmeter源码编译

    转载:http://blog.csdn.net/wanglha/article/details/42004943 一.下载源码 git clone git://github.com/apache/jm ...

  2. Why is chkconfig no longer available in Ubuntu?

    Question: I can not use chkconfig tools in Ubuntu 12.10 It's a very useful tools to configure the se ...

  3. redis主从连接不成功错误

    redis主从连接不成功错误 学习了:https://blog.csdn.net/wzqzhq/article/details/64919133 需要增加 masterauth  password.. ...

  4. php性能监控扩展xhprof

    XHProf是facebook开源出来的一个php轻量级的性能分析工具,跟Xdebug类似,但性能开销更低,还可以用在生产环境中,也可以由程序开 关来控制是否进行profile.总体来说是个不错的工具 ...

  5. Solaris文件系统管理

    不同的操作系统使用不同类型的文件系统 1.文件(管理)系统:是用来对文件和目录进行管理.控制的数据结构的总称. Windows当中的文件系统: ntfs ,fat32 ,fat64 Solaris 当 ...

  6. 数据库历险记(三) | 缓存框架的连环炮 数据库历险记(二) | Redis 和 Mecached 到底哪个好? 数据库历险记(一) | MySQL这么好,为什么还有人用Oracle? 面对海量请求,缓存设计还应该考虑哪些问题?

    数据库历险记(三) | 缓存框架的连环炮   文章首发于微信公众号「陈树义」,专注于 Java 技术分享的社区.点击链接扫描二维码,与500位小伙伴一起共同进步.微信公众号二维码 http://p3n ...

  7. soapUI学习笔记---断言的小使用

    转自:http://www.cnblogs.com/duimianyoushan/p/4274791.html 以下示例在soapUI 4.5中进行.刚开始学soapUI的使用,记录下以免忘记 1.创 ...

  8. MyEclipse的html/JSP编辑器添加代码自动提示

    http://lusterfly.iteye.com/blog/1872627 在myeclipse 9以前的版本中,我们如果要为html编辑器添加自动的代码提示可以这样操作: windows--&g ...

  9. npm 淘宝设置代理

    直接安装cnpm导致无限索引,因此直接使用代理 方法一: 直接在当前用户文件夹下,npmrc 文件上直接设置代理:registry=https://registry.npm.taobao.org 方法 ...

  10. 使用Apache Commons Chain(转载)

    原博客出处:http://phil-xzh.iteye.com/blog/321536 使用Commons Chain 作为程序开发人员,我们经常需要对一个实际上程序性的系统应用面向对象的方法.商业分 ...