[题目链接]

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. Windows10系统修复

    sfc /scannow 命令将扫描所有受保护的系统文件,并用位于 %WinDir%\System32\dllcache 的压缩文件夹中的缓存副本替换损坏的文件. %WinDir% 占位符代表Wind ...

  2. Android——滑动事件冲突解决

    android中的事件类型分为按键事件和屏幕触摸事件,Touch事件是屏幕触摸事件的基础事件. android系统中的每个View的子类都具有下面三个与TouchEvent处理密切相关的方法: (1) ...

  3. shell脚本编写-自动部署及监控

    1.编写脚本自动部署反向代理.web.nfs: I.部署nginx反向代理两个web服务,调度算法使用加权轮询 II.所有web服务使用共享存储nfs,保证所有web都对其有读写权限,保证数据一致性: ...

  4. inch mil mm换算

    inch:英寸 mil:密耳 mm:毫米 1mil=0.0254mm=25.4um 1mm=39.37mil 1inch=1000mil=25.4mm

  5. 笔记16 C# typeof() & GetType()

    C#中任何对象都具有GetType()方法,它的作用和typeof()相同,返回Type类型的当前对象的类型.typeof(x)中的x,必须是具体的类名.类型名称等,不可以是变量名称:GetType( ...

  6. 关于 ++x 和 x++ 比较难的一个例子

    public class testMain { static{ int x = 5;//如果后面有static int x, 前面的定义就没有用x会被重新定义为0 } static int y; st ...

  7. FastDFS的配置、部署与API使用解读(8)FastDFS多种文件上传接口详解(转)

    1.StorageClient与StorageClient1的区别 相信使用happy_fish的FastDFS的童鞋们,一定都熟悉StorageClient了,或者你熟悉的是StorageClien ...

  8. android mvp高速开发框架介绍(dileber的简单介绍)

    今天我为大家介绍一款android mvp框架:dileber(https://github.com/dileber/dileber.git) 官方交流qq群:171443726 我个人qq:2971 ...

  9. 问题 “cell 出栈 selectBox 已选的图标,被释放掉,再次进入屏幕时,没有了已选图标 ” 解决方案

    如何 去解决 列表里面的selectBox已选情况,在滑出屏幕后被清除的问题.      我来在这里 详细说明一下, 在cell里面写一个方法,去专门修复滑出后,又滑进来 图标被冲刷掉的cell. 在 ...

  10. 【BZOJ1528】[POI2005]sam-Toy Cars 贪心

    [BZOJ1528][POI2005]sam-Toy Cars Description Jasio 是一个三岁的小男孩,他最喜欢玩玩具了,他有n 个不同的玩具,它们都被放在了很高的架子上所以Jasio ...