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的位置在哪?”的问题,精确到毫米.但其真正高科技之处在于,它 ...
随机推荐
- 理解RESTful Api设计
REST REST(REpresentational State Transfer)是 Roy Fielding 博士于 2000 年在他的博士论文中提出来的一种软件架构风格(一组架构约束条件和原则) ...
- 关于SpringBoot Admin server 监控注意事项
当你导入了依赖 <dependency> <groupId>de.codecentric</groupId> <artifactId>spring-bo ...
- CXP 协议中upconnection 与downconnection的说明及其区别
概述 CXP定义了一个DEVICE和HOST之间点对点的连接协议.CXP的一个连接包含了一个MASTER物理连接和若干可选的SLAVE连接,每一个连接都定义了一组逻辑通道用于传输图像数据.实时触发.设 ...
- Kafka 负载均衡在 vivo 的落地实践
vivo 互联网服务器团队-You Shuo 副本迁移是Kafka最高频的操作,对于一个拥有几十万个副本的集群,通过人工去完成副本迁移是一件很困难的事情.Cruise Control作为Kafka的 ...
- net core天马行空系列-可用于依赖注入的,数据库表和c#实体类互相转换的接口实现
1.前言 hi,大家好,我是三合.作为一名程序猿,日常开发中,我们在接到需求以后,一般都会先构思一个模型,然后根据模型写实体类,写完实体类后在数据库里建表,接着进行增删改查, 也有第二种情况,就是有些 ...
- Java开发学习(三)----Bean基础配置及其作用范围
一.bean基础配置 对于bean的基础配置如下 <bean id="" class=""/> 其中,bean标签的功能.使用方式以及id和clas ...
- 【C#/VB.NET】 将PDF转为SVG/Image, SVG/Image转PDF
SVG是一种图形文件格式,它的英文全称为Scalable Vector Graphics,意思为可缩放的矢量图形.它在放大或者改变尺寸的情况下其图形质量不会有所损失,且与 JPG 和 GIF 图像比起 ...
- 多台云服务器的 Kubernetes 集群搭建
环境 两台或多台腾讯云服务器(本人搭建用了两台),都是 CentOs 7.6, master 节点:服务器为 4C8G,公网 IP:124.222.61.xxx node1节点:服务器为 4C4G,公 ...
- Linux系统安全配置
1.物理安全 硬件服务器,关闭从CD/DVD等这些方面的软启动方式.同时也可以设置BIOS密码,并且要有限制访问的策略与各类流程管控. 还可以禁用USB设备来达到安全的目的: centos7x 安装d ...
- Banner自定义图案
Banner大全https://www.bootschool.net/ascii