CDQ裸题,\(x\), \(y\), \(tim\)三维偏序

#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#define R(a,b,c) for(register int a = (b); (a) <= (c); ++(a))
#define nR(a,b,c) for(register int a = (b); (a) >= (c); --(a))
#define Fill(a,b) memset(a, b, sizeof(a))
#define Swap(a,b) ((a) ^= (b) ^= (a) ^= (b))
#define ll long long
#define u32 unsigned int
#define u64 unsigned long long #define ON_DEBUGG #ifdef ON_DEBUGG #define D_e_Line printf("\n----------\n")
#define D_e(x) cout << (#x) << " : " << x << endl
#define Pause() system("pause")
#define FileOpen() freopen("in.txt", "r", stdin)
#define FileSave() freopen("out.txt", "w", stdout)
#include <ctime>
#define TIME() fprintf(stderr, "\ntime: %.3fms\n", clock() * 1000.0 / CLOCKS_PER_SEC) #else #define D_e_Line ;
#define D_e(x) ;
#define Pause() ;
#define FileOpen() ;
#define FileSave() ;
#define TIME() ;
//char buf[1 << 21], *p1 = buf, *p2 = buf;
//#define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++) #endif using namespace std;
struct ios{
template<typename ATP>inline ios& operator >> (ATP &x){
x = 0; int f = 1; char ch;
for(ch = getchar(); ch < '0' || ch > '9'; ch = getchar()) if(ch == '-') f = -1;
while(ch >= '0' && ch <= '9') x = x * 10 + (ch ^ '0'), ch = getchar();
x *= f;
return *this;
}
}io; template<typename ATP>inline ATP Max(ATP a, ATP b){
return a > b ? a : b;
}
template<typename ATP>inline ATP Min(ATP a, ATP b){
return a < b ? a : b;
}
template<typename ATP>inline ATP Abs(ATP a){
return a < 0 ? -a : a;
} const int N= 2000007;
struct Ques{
int pos, tim, x, y, val, tag;
bool operator < (const Ques &com) const{
if(x != com.x) return x < com.x;
if(y != com.y) return y < com.y;
return tag < com.tag;
}
}q[N], tmp[N];
int t[N];
int n;
inline void Updata(int x, int w){
for(; x <= n; x += x & -x) t[x] += w;
}
inline int Query(int x){
int s = 0;
for(; x; x -= x & -x) s += t[x];
return s;
}
int ans[N];
inline void CDQ(int l, int r){
if(l == r) return;
int mid = (l + r) >> 1;
R(i,l,r){
if(q[i].tim <= mid && q[i].tag == 0){
Updata(q[i].y, q[i].val);
}
if(q[i].tim > mid && q[i].tag == 1){
ans[q[i].pos] += q[i].val * Query(q[i].y);
}
}
R(i,l,r){
if(q[i].tim <= mid && q[i].tag == 0){
Updata(q[i].y, -q[i].val);
}
}
int j = l, k = mid + 1;
R(i,l,r){
if(q[i].tim <= mid)
tmp[j++] = q[i];
else
tmp[k++] = q[i];
}
R(i,l,r){
q[i] = tmp[i];
}
CDQ(l, mid), CDQ(mid + 1, r);
}
int tot;
int main(){
freopen("1176.in", "r", stdin);
freopen("1176.out", "w", stdout);
int S;
io >> S >> n;
while(1){
int opt;
io >> opt;
if(opt == 3) break;
if(opt == 1){
++tot;
io >> q[tot].x >> q[tot].y >> q[tot].val;
q[tot].tim = tot;
}
else{
int X1, X2, Y1, Y2;
io >> X1 >> Y1 >> X2 >> Y2;
int pos = ++ans[0]; // pos is the order of the querys
ans[ans[0]] = S * (X2 - X1 + 1) * (Y2 - Y1 + 1);
q[++tot] = (Ques){ pos, tot, X1 - 1, Y1 - 1, 1, 1};
q[++tot] = (Ques){ pos, tot, X2, Y2, 1, 1};
q[++tot] = (Ques){ pos, tot, X1 - 1, Y2, -1, 1};
q[++tot] = (Ques){ pos, tot, X2, Y1 - 1, -1, 1};
}
}
sort(q + 1, q + tot + 1);
CDQ(1, tot);
R(i,1,ans[0]){
printf("%d\n", ans[i]);
}
return 0;
}

BZOJ1176 [Balkan2007]Mokia(CDQ)的更多相关文章

  1. 2018.09.16 bzoj1176: [Balkan2007]Mokia(cdq分治)

    传送门 调了半天发现是输出优化打错了求心理阴影体积233 这题很简单啊. 一个修改操作x如果对一个询问操作y有贡献那么有. tx<ty,Xx<=Xy,Yx<=Yy" rol ...

  2. 【BZOJ1176】Mokia(CDQ分治)

    [BZOJ1176]Mokia(CDQ分治) 题面 BZOJ权限题啊,,,, dbzoj真好 Description 维护一个W*W的矩阵,初始值均为S.每次操作可以增加某格子的权值,或询问某子矩阵的 ...

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

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

  4. bzoj1176: [Balkan2007]Mokia【cdq分治】

    把询问搞成4个,cdq分治. #include <bits/stdc++.h> #define rep(i, a, b) for (int i = a;i <= b; i++) #d ...

  5. BZOJ1176 [Balkan2007]Mokia 【CDQ分治】

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

  6. [BZOJ1176][Balkan2007]Mokia cdq+树状数组

    1176: [Balkan2007]Mokia Time Limit: 30 Sec  Memory Limit: 162 MBSubmit: 3134  Solved: 1395[Submit][S ...

  7. P3374 【模板】树状数组 1(cdq)

    P3374 [模板]树状数组 1 cdq分治 刚学了cdq分治(dyf神犇强力安利下),发现可以做这种题,当然是来试水了(逃 cdq好像只能离线的样子 cdq分治(转) 以下是摘录的几句: 在合并的时 ...

  8. bzoj2683(要改一点代码)&&bzoj1176: [Balkan2007]Mokia

    仍然是一道cdq模版.. 那么对于一个询问,容斥一下分成四个,变成问(1,1)~(x,y),那么对于x,y,修改只有x'<=x&&y'<=y,才对询问有影响,那么加上读入顺 ...

  9. COGS1752 [BOI2007]摩基亚Mokia(CDQ分治 + 二维前缀和 + 线段树)

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

随机推荐

  1. 【单片机】CH32V103C8T6 ——窗口看门狗

    本章教程通过串口调试助手打印显示程序运行状态,具体现象如下: 若计数器值在上窗口值和下窗口值0X40之间的时候,进行喂狗操作,计数器重新计数,程序正常运行,串口打印显示:The program run ...

  2. MongoDB 设置用户和密码

    每日一句 Zeal without knowledge is fire without light. 没有知识的热忱犹如火之无光. 给每个数据库设置单独的管理员 我们除了可以设置数据库的超级管理员以外 ...

  3. Redis 应用只 消息队列 简单实现(生产者 消费者模式)

    运行效果:

  4. 前端2CSS

    内容概要 form表单 网络请求方式 CSS简介 CSS查找标签之基本选择器(重要) CSS查找标签之组合选择器(重要) 属性选择器 分组与嵌套 伪类选择器 内容详情 form表单 "&qu ...

  5. 【Golang】程序如何优雅的退出?

    1. 背景 项目开发过程中,随着需求的迭代,代码的发布会频繁进行,在发布过程中,如何让程序做到优雅的退出? 为什么需要优雅的退出? 你的 http 服务,监听端口没有关闭,客户的请求发过来了,但处理了 ...

  6. 理论+案例,带你掌握Angular依赖注入模式的应用

    摘要:介绍了Angular中依赖注入是如何查找依赖,如何配置提供商,如何用限定和过滤作用的装饰器拿到想要的实例,进一步通过N个案例分析如何结合依赖注入的知识点来解决开发编程中会遇到的问题. 本文分享自 ...

  7. 【python基础】第07回 运算符和流程控制 2

    本章内容概要 1.逻辑运算符补充 2.循环结构 本章内容详解 1.逻辑运算符补充 两边都不为0的情况 or 直接取前面的值 and 直接取后面的值如果存在0的情况 and 直接取0 or 直接取非0 ...

  8. Java获取显示器屏幕大小

    public static void main(String[] args) { Dimension screensize = Toolkit.getDefaultToolkit().getScree ...

  9. maven编译 出现Process terminated

    问题: 解决方案: 在Settings中配置一下maven

  10. Java中时间方法大全01(持续更新)

    下面这些方法都可以封装到一个工具类中 /** * 获取当前时间的时间戳 */ public static int getCurrentTimeIntValue() { return (int) (Sy ...