BZOJ1176 [Balkan2007]Mokia(CDQ)
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)的更多相关文章
- 2018.09.16 bzoj1176: [Balkan2007]Mokia(cdq分治)
传送门 调了半天发现是输出优化打错了求心理阴影体积233 这题很简单啊. 一个修改操作x如果对一个询问操作y有贡献那么有. tx<ty,Xx<=Xy,Yx<=Yy" rol ...
- 【BZOJ1176】Mokia(CDQ分治)
[BZOJ1176]Mokia(CDQ分治) 题面 BZOJ权限题啊,,,, dbzoj真好 Description 维护一个W*W的矩阵,初始值均为S.每次操作可以增加某格子的权值,或询问某子矩阵的 ...
- 【BZOJ】1176: [Balkan2007]Mokia(cdq分治)
http://www.lydsy.com/JudgeOnline/problem.php?id=1176 在写这题的时候思维非常逗啊........2333................... 最后 ...
- bzoj1176: [Balkan2007]Mokia【cdq分治】
把询问搞成4个,cdq分治. #include <bits/stdc++.h> #define rep(i, a, b) for (int i = a;i <= b; i++) #d ...
- BZOJ1176 [Balkan2007]Mokia 【CDQ分治】
题目 维护一个W*W的矩阵,初始值均为S.每次操作可以增加某格子的权值,或询问某子矩阵的总权值.修改操作数M<=160000,询问数Q<=10000,W<=2000000. 输入格式 ...
- [BZOJ1176][Balkan2007]Mokia cdq+树状数组
1176: [Balkan2007]Mokia Time Limit: 30 Sec Memory Limit: 162 MBSubmit: 3134 Solved: 1395[Submit][S ...
- P3374 【模板】树状数组 1(cdq)
P3374 [模板]树状数组 1 cdq分治 刚学了cdq分治(dyf神犇强力安利下),发现可以做这种题,当然是来试水了(逃 cdq好像只能离线的样子 cdq分治(转) 以下是摘录的几句: 在合并的时 ...
- bzoj2683(要改一点代码)&&bzoj1176: [Balkan2007]Mokia
仍然是一道cdq模版.. 那么对于一个询问,容斥一下分成四个,变成问(1,1)~(x,y),那么对于x,y,修改只有x'<=x&&y'<=y,才对询问有影响,那么加上读入顺 ...
- COGS1752 [BOI2007]摩基亚Mokia(CDQ分治 + 二维前缀和 + 线段树)
题目这么说的: 摩尔瓦多的移动电话公司摩基亚(Mokia)设计出了一种新的用户定位系统.和其他的定位系统一样,它能够迅速回答任何形如“用户C的位置在哪?”的问题,精确到毫米.但其真正高科技之处在于,它 ...
随机推荐
- ptorch常用代码梯度篇(梯度裁剪、梯度累积、冻结预训练层等)
梯度裁剪(Gradient Clipping) 在训练比较深或者循环神经网络模型的过程中,我们有可能发生梯度爆炸的情况,这样会导致我们模型训练无法收敛. 我们可以采取一个简单的策略来避免梯度的爆炸,那 ...
- drools决策表的简单使用
目录 一.背景 二.一个简单的决策表 1.在同一个决策表中处理多个Sheet页 2.RuleSet下方可以有哪些属性 3.RuleTable下方可以有哪些属性 4.规则属性的编写 三.需求 四.实现 ...
- Java开发学习(二)----IOC、DI入门案例
一.IOC入门案例 1.1 思路分析 (1)Spring是使用容器来管理bean对象的,那么管什么? 主要管理项目中所使用到的类对象,比如(Service和Dao) (2)如何将被管理的对象告知IOC ...
- FlinkSQL源码阅读-schema管理
在Flink SQL中, 元数据的管理分为三层: catalog-> database-> table, 我们知道Flink SQL是依托calcite框架来进行SQL执行树生产,校验,优 ...
- 基于camunda开源流程引擎如何实现会签及会签原理解析
一.背景 市场上比较有名的开源流程引擎有osworkflow.jbpm.activiti.flowable.camunda.由于jbpm.activiti.flowable这几个流程引擎出现的比较早, ...
- BUUCTF-webshell后门
webshell后门 老方法,D盾直接查杀. flag{ba8e6c6f35a53933b871480bb9a9545c}
- 从0到1搭建一款Vue可配置视频播放器组件(Npm已发布)
前言 话不多说,这篇文章主要讲述如何从0到1搭建一款适用于Vue.js的自定义配置视频播放器.我们平时在PC端网站上观看视频时,会看到有很多丰富样式的视频播放器,而我们自己写的video标签样式却是那 ...
- JS中通过id或者class获取文本内容
一.JS通过id获取文本内容 二.JS通过class获取文本内容
- MySQL查询为什么没走索引?这篇文章带你全面解析
工作中,经常遇到这样的问题,我明明在MySQL表上面加了索引,为什么执行SQL查询的时候却没有用到索引? 同一条SQL有时候查询用到了索引,有时候却没用到索引,这是咋回事? 原因可能是索引失效了,失效 ...
- IO流思维导图
IO思维导图总结 总览: 1.文件 <目标:File类的创建和删除的方法 > public boolean createNewFile() :当且仅当具有该名称的文件尚不存在时, 创建一个 ...