[题目链接]

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. [C++11]_[0基础]_[左值引用声明和右值引用声明]

    场景: 在 remove_reference 结构体中能看到右值引用的身影 &&, 那么这里的右值引用究竟有什么用呢? 常常也发现int& 和int&& 这两种 ...

  2. C++中sizeof(struct)怎么计算?(转)

    struct为空时,大小为1. 1. sizeof应用在结构上的情况 请看下面的结构: struct MyStruct { double dda1; char dda; int type; }; 对结 ...

  3. linux与python

    linux一般都装有python,但是版本不一定,需要自己查看,如果版本过低,需要重装.查看python版本方法,直接在命令行输入 python,此时会进入python命令行,同时会显示python版 ...

  4. C# SQL 整表插入

    说明: (1)表A的一部分数据插入到表B (2)DataAccess 类,是放在DAL层下的底层类; da.StrConnection 写在DataAccess类中; //整表插入方法 private ...

  5. C# 通过Hook的方法 屏蔽快捷键

     #region 屏蔽Windows功能键(快捷键)         public delegate int HookProc(int nCode, int wParam, IntPtr lParam ...

  6. 物联网网络编程和web编程

    本文是基于嵌入式物联网研发project师的视觉对网络编程和web编程进行阐述. 对于专注J2EE后端服务开发的同学来说,这篇文章可能略微简单.可是网络编程和web编程对于绝大部分嵌入式物联网proj ...

  7. Discuz系列1:安装

    http://www.discuz.net/forum.php     官网,点击“Discuz! 程序发布” 代码库: https://git.oschina.net/ComsenzDiscuz/D ...

  8. 采用ADM2582E/ADM2587E实现完全半/全双工的RS-485/RS-422接口隔离

    RS-485标准是一种常见的总线架构,其通用性及远距离传输能力使其广泛应用于各种通信接口电路.在多数情况下,由于应用环境的恶劣,需要对RS-485接口采用隔离方案以防止出现接地环路. 对RS-485接 ...

  9. EasyCamera Android安卓移动视频监控单兵设备接入EasyDarwin开源流媒体云平台

    前言 随着Android系统的不断更新和发展,现在越来越多的硬件产品选择用安卓系统作为运行环境,电视机,机顶盒.门禁.行车记录仪.车载系统.单兵设备等等,Android系统底层还是Linux,但对上层 ...

  10. 九度OJ 1142:Biorhythms(生理周期) (中国剩余定理)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:266 解决:189 题目描述: Some people believe that there are three cycles in a p ...