思路:首先我们将问题转换一下,变成问在某个点左下角的权值和,那么每一个询问可以拆成4的这样的询问,然后

进行CDQ 分治,回溯的时候按x轴排序,然后用树状数组维护y的值。

#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define pii pair<int, int>
#define x2 skdjflsdg
#define y2 sdkfjsktge using namespace std; const int N = 2e6 + ;
const int M = 1e6 + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 +; int s, w, cnt, tot, op; LL ans[M], a[N];
struct Qus {
int x, y, idx, id;
} qus[M], tmp[M]; void modify(int x, int v) {
for(int i = x; i < N; i += i & -i) {
a[i] += v;
}
} LL sum(int x) {
LL ans = ;
for(int i = x; i; i -= i & -i) {
ans += a[i];
}
return ans;
} void cdq(int l, int r) { if(l == r) return;
int mid = l + r >> ;
cdq(l, mid); cdq(mid + , r); int p = l, q = mid + , cnt = l; for(int i = mid + ; i <= r; i++) {
while(p <= mid && qus[p].x <= qus[i].x) {
if(qus[p].idx == )
modify(qus[p].y, qus[p].id);
p++;
}
ans[qus[i].id] += qus[i].idx * sum(qus[i].y);
} for(int i = l; i < p; i++) {
if(qus[i].idx == ) {
modify(qus[i].y, -qus[i].id);
}
} p = l, q = mid + , cnt = l; while(p <= mid && q <= r) {
if(qus[p].x <= qus[q].x) {
tmp[cnt++] = qus[p++];
} else {
tmp[cnt++] = qus[q++];
}
} while(p <= mid) tmp[cnt++] = qus[p++];
while(q <= r) tmp[cnt++] = qus[q++]; for(int i = l; i <= r; i++) qus[i] = tmp[i]; } int main() {
scanf("%d%d", &s, &w);
while(scanf("%d", &op) && op < ) {
if(op == ) {
int x, y, a; scanf("%d%d%d", &x, &y, &a);
x += ; y += ;
qus[++tot].x = x;
qus[tot].y = y;
qus[tot].id = a;
qus[tot].idx = ;
} else {
int x1, y1, x2, y2;
scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
x1 += , y1 += ;
x2 += , y2 += ;
qus[++tot].x = x2;
qus[tot].y = y2;
qus[tot].id = ++cnt;
qus[tot].idx = ; qus[++tot].x = x2;
qus[tot].y = y1 - ;
qus[tot].id = cnt;
qus[tot].idx = -; qus[++tot].x = x1 - ;
qus[tot].y = y2;
qus[tot].id = cnt;
qus[tot].idx = -; qus[++tot].x = x1 - ;
qus[tot].y = y1 - ;
qus[tot].id = cnt;
qus[tot].idx = ; ans[cnt] = 1ll * (x2 - x1) * (y2 - y1) * s;
}
}
cdq(, tot);
for(int i = ; i <= cnt; i++)
printf("%lld\n", ans[i]);
return ;
}
/*
*/

bzoj 1176 CDQ分治的更多相关文章

  1. bzoj 1176 cdq分治套树状数组

    题面: 维护一个W*W的矩阵,初始值均为S.每次操作可以增加某格子的权值,或询问某子矩阵的总权值.修改操作数M<=160000,询问数Q<=10000,W<=2000000. Inp ...

  2. BZOJ 1537 cdq分治

    思路: 我只是想写一下cdq-- 二维偏序 一维排序 一维cdq分治 (我忘了归并排序怎么写了,,,) 写了个sort- 复杂度是O(nlog^2n) //By SiriusRen #include ...

  3. BZOJ 3262 cdq分治 OR 树套树

    注意判断 三个条件都一样的-- (CDQ分治 其实并不是很难理解 只是想不到--) CDQ分治: //By SiriusRen #include <cstdio> #include < ...

  4. bzoj 2683 CDQ分治

    题目描述 你有一个N*N的棋盘,每个格子内有一个整数,初始时的时候全部为0,现在需要维护两种操作: 命令 参数限制 内容 1 x y A 1<=x,y<=N,A是正整数 将格子x,y里的数 ...

  5. BZOJ - 1935 / 1176 cdq分治 三维偏序

    题意:给定n*m的网格,且给出n个(x,y)表示该网格已被占有,q次询问(x1,y1)到(x2,y2)的网格中有多少个被占有,n,m范围1e7,q范围5e5 cdq按x轴排序,树状数组维护y轴 #in ...

  6. 【BZOJ4237】稻草人(CDQ分治,单调栈)

    [BZOJ4237]稻草人(CDQ分治,单调栈) 题面 BZOJ 题解 \(CDQ\)分治好题呀 假设固定一个左下角的点 那么,我们可以找到的右下角长什么样子??? 发现什么? 在右侧是一个单调递减的 ...

  7. BZOJ 1176: [Balkan2007]Mokia( CDQ分治 + 树状数组 )

    考虑cdq分治, 对于[l, r)递归[l, m), [m, r); 然后计算[l, m)的操作对[m, r)中询问的影响就可以了. 具体就是差分答案+排序+离散化然后树状数组维护.操作数为M的话时间 ...

  8. BZOJ 1176 Mokia CDQ分治+树状数组

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

  9. 【BZOJ】1176: [Balkan2007]Mokia(cdq分治)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1176 在写这题的时候思维非常逗啊........2333................... 最后 ...

随机推荐

  1. java面试之闭包(closure)

    今天在学习Openresty的时候回顾了下闭包这个问题,感觉很久没有深入的了解这块的内容的,只是之前js的时候学习过闭包,突然一问,感觉不记得闭包了: 看了一个比较有趣的答案: 闭包,顾名思义,就是把 ...

  2. Netfilter之连接跟踪实现机制初步分析

    Netfilter之连接跟踪实现机制初步分析 原文: http://blog.chinaunix.net/uid-22227409-id-2656910.html 什么是连接跟踪 连接跟踪(CONNT ...

  3. 调整的R方_如何选择回归模型

    sklearn实战-乳腺癌细胞数据挖掘(博客主亲自录制视频教程) https://study.163.com/course/introduction.htm?courseId=1005269003&a ...

  4. [DeeplearningAI笔记]序列模型1.5-1.6不同类型的循环神经网络/语言模型与序列生成

    5.1循环序列模型 觉得有用的话,欢迎一起讨论相互学习~Follow Me 1.5不同类型的循环神经网络 上节中介绍的是 具有相同长度输入序列和输出序列的循环神经网络,但是对于很多应用\(T_{x}和 ...

  5. CF745 C 并查集

    并查集由于政府不能连通我们可以先按给出的边建立连通块,再将不含有政府的点全部作为一个连通块,边数为(n-1)*n/2然后 贪心地将该连通块与[含政府的.且包含点数最多的]连通块相连,然后由于新增了一些 ...

  6. hadoop之安全篇

    ---------------持续更新中------------------- hadoop集群安全架构 如下图所示: --------------------------未完待续---------- ...

  7. IDEA不显示更新、提交按钮

    问题描述: IDEA右上角不显示版本管理的“更新”.“提交”等按钮,左侧代码树中,也没有文件的状态 解决办法: 点击VCS-->Enable Version Control Integratio ...

  8. UVA - 10494 If We Were a Child Again

    用java写的大数基本操作,java要求的格式比较严谨. import java.util.*; import java.math.*; public class Main { public stat ...

  9. 【BZOJ 1001】[BJOI2006]狼抓兔子(最大流)

    题目链接 最大流裸题,没什么好说吧,恰好点数多,考验网络流的效率,正好练\(Dinic\). #include <cstdio> #include <queue> #inclu ...

  10. javaScript语法和风格的检查工具

    一.JSLint. JSHint. JSCS. ESLint 1.JSLint是由Douglas Crockford开发的,可能是最早的JavaScript Lint工具.JSLint定义了一组编码约 ...