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. 一些实验中用过的python函数/方法(持续更新)

    衡量运行时间 很多时候你需要计算某段代码执行所需的时间,可以使用 time 模块来实现这个功能. import time startTime = time.time() # write your co ...

  2. hash和history路由的区别

    在了解路由模式前,我们先看下 什么是单页面应用,vue-router  的实现原理是怎样的,这样更容易理解路由. SPA与前端路由 SPA(单页面应用,全程为:Single-page Web appl ...

  3. 开发工具-在线计算MD5

    更新记录: 2022年6月8日 更新标题. 2022年6月1日 开始. 都记在这以后就不用到处找了. 在线计算MD5 https://www.sojson.com/md5/ http://www.ip ...

  4. dubbo容错机制

    dubbo的容错机制 Failover Cluster(默认) 失败自动切换,当出现失败,重试其它服务器.通常用于读操作,但重试会带来更长延迟. Failfast Cluster 快速失败,只发起一次 ...

  5. .Net Core 企业微信更新模版卡片消息

    1.搭建回调服务器 可参考:https://www.cnblogs.com/zspwf/p/16381643.html进行搭建 2.编写代码 2.1接口定义 应用可以发送模板卡片消息,发送之后可再通过 ...

  6. TypeScript(6)函数

    函数 函数是 JavaScript 应用程序的基础,它帮助你实现抽象层,模拟类,信息隐藏和模块.在 TypeScript 里,虽然已经支持类,命名空间和模块,但函数仍然是主要的定义行为的地方.Type ...

  7. SAP 隐式增强 Enhancement point

    1.进入编辑器:SE38/SE37/SE24 Edit-->Enhancement Operations-->Create Option 2.填写相关信息,点击对号. 3.点击Enhanc ...

  8. 用python进行加密和解密——我看刑

    加密和解密 密码术意味着更改消息的文本,以便不知道你秘密的人永远不会理解你的消息. 下面就来创建一个GUI应用程序,使用Python进行加密和解密. 在这里,我们需要编写使用无限循环的代码,代码将不断 ...

  9. P2575 高手过招 题解

    题目描述 我们考虑如何把问题转换成博弈论来求解. 我们对于每一行之前都加上一个空格. 设原来这一行的空格个数是 \(C\) ,那么此时空格个数变成 \(C + 1\) . 然后按照从左到右的顺序给每一 ...

  10. spring-security 配置简介

    1.Spring Security 简介 Spring Security 是一个能够基于 Spring 的企业应用系统提供声明式的安全访问控制解决方案的安全框架.它提供了一组可以在 Spring 应用 ...