题目链接

题面

题意

把每个位置的点都看成是一个二维坐标系中的点。比如第\(i\)个点就是\((i,a[i])\)。

有两种操作

询问:然后每次询问的就是与当前点坐标的曼哈顿距离小于等于\(k\)的点。

修改:修改第i个点的纵坐标。保留历史点。

思路

旋转坐标系。然后就变成了添加一个点和询问一个子矩阵内点的个数。用\(CDQ\)分治或者其他数据结构做就行了

代码

/*
* @Author: wxyww
* @Date: 2019-02-15 08:38:47
* @Last Modified time: 2019-02-15 10:16:11
*/
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<queue>
#include<vector>
#include<ctime>
using namespace std;
typedef long long ll;
const int N = 4000010,M = 3000003,BL = 1000000;
#define pi pair<int,int>
ll read() {
ll x=0,f=1;char c=getchar();
while(c<'0'||c>'9') {
if(c=='-') f=-1;
c=getchar();
}
while(c>='0'&&c<='9') {
x=x*10+c-'0';
c=getchar();
}
return x*f;
}
struct node {
int x,y,opt,pos,val;
}a[M];
char s[10];
int tt[N],tot;
int tree[M],mx,ans[N];
vector<pi>v;
void update(int pos,int c) {
while(pos <= BL*3) {
tree[pos] += c;
pos += pos & -pos;
}
}
int query(int pos) {
int ret = 0;
while(pos) {
ret += tree[pos];
pos -= pos & -pos;
}
return ret;
}
node tmp[N];
void cdq(int l,int r) {
if(r <= l) return;
int mid = (l + r) >> 1;
cdq(l,mid);cdq(mid + 1,r);
int now = l,L = l,R = mid + 1;
while(L <= mid && R <= r) {
if(a[L].x <= a[R].x) {
if(a[L].opt == 1) {
update(a[L].y,a[L].val);
v.push_back(make_pair(a[L].y,a[L].val));
}
tmp[now++] = a[L++];
}
else {
if(a[R].opt == 2) ans[a[R].pos] += query(a[R].y);
else if(a[R].opt == 3) ans[a[R].pos] -= query(a[R].y);
tmp[now++] = a[R++];
}
}
while(L <= mid) tmp[now++] = a[L++];
while(R <= r) {
if(a[R].opt == 2) ans[a[R].pos] += query(a[R].y);
else if(a[R].opt == 3) ans[a[R].pos] -= query(a[R].y);
tmp[now++] = a[R++];
}
for(int i = l;i <= r;++i) a[i] = tmp[i];
int k = v.size();
for(int i = 0;i < k;++i) update(v[i].first,-v[i].second);
v.clear();
}
int main() {
int n = read(),Q = read(),now = 0;
for(int i = 1;i <= n;++i) {
tt[i] = read();
a[++tot].x = i + tt[i],a[tot].y = i - tt[i] + BL;
a[tot].opt = 1;a[tot].val = 1;
mx = max(mx,max(a[tot].x,a[tot].y));
}
for(int i = 1;i <= Q;++i) {
scanf("%s",s + 1);
int x = read(),y = read();
if(s[1] == 'Q') {
int x1 = x + tt[x] - y,x2 = x + tt[x] + y,y1 = x - tt[x] + BL - y,y2 = x - tt[x] + BL + y;
a[++tot].pos = ++now;a[tot].x = x2;a[tot].y = y2;a[tot].opt = 2;
a[++tot].pos = now;a[tot].x = x1 - 1;a[tot].y = y1 - 1;a[tot].opt = 2;
a[++tot].pos = now;a[tot].x = x1 - 1;a[tot].y = y2;a[tot].opt = 3;
a[++tot].pos = now;a[tot].x = x2;a[tot].y = y1 - 1;a[tot].opt = 3;
}
else {tt[x] = y;
a[++tot].opt = 1;
a[tot].x = x + tt[x];a[tot].y = x - tt[x] + BL;a[tot].val = 1;
mx = max(mx,max(a[tot].x,a[tot].y));
}
} cdq(1,tot);
for(int i = 1;i <= now;++i) printf("%d\n",ans[i]);
return 0;
}

bzoj4170 极光的更多相关文章

  1. BZOJ4170 极光(CDQ分治 或 树套树)

    传送门 BZOJ上的题目没有题面-- [样例输入] 3 5 2 4 3 Query 2 2 Modify 1 3 Query 2 2 Modify 1 2 Query 1 1 [样例输出] 2 3 3 ...

  2. BZOJ4170:极光(CDQ分治)

    Description "若是万一琪露诺(俗称rhl)进行攻击,什么都好,冷静地回答她的问题来吸引她.对方表现出兴趣的话,那就慢慢地反问.在她考虑答案的时候,趁机逃吧.就算是很简单的问题,她 ...

  3. BZOJ4170:极光

    浅谈离线分治算法:https://www.cnblogs.com/AKMer/p/10415556.html 题目传送门:https://lydsy.com/JudgeOnline/problem.p ...

  4. 使用极光推送(www.jpush.cn)向安卓手机推送消息【服务端向客户端主送推送】C#语言

    在VisualStudio2010中新建网站JPushAndroid.添加引用json帮助类库Newtonsoft.Json.dll. 在web.config增加appkey和mastersecret ...

  5. 使用极光/友盟推送,APP进程杀死后为什么收不到推送(转)

    为什么会存在这样的 问题,刚开始的时候我也搞不清楚,之前用极光的时候杀死程序后也会收到推送,但最近重新再去集成时就完全不好使了,这我就纳闷了,虽然Google在高版本上的android上面不建议线程守 ...

  6. 用JPUSH极光推送实现服务端向安装了APP应用的手机推送消息(C#服务端接口)

    这次公司要我们做一个功能,就是当用户成功注册以后,他登录以后要收到消息,当然这个消息是安装了我们的手机APP应用的手机咯. 极光推送的网站的网址是:https://www.jpush.cn/ 极光推送 ...

  7. 极光推送-适配 iOS10

    //************************ iOS10 适配 **************************// //************************ 11/02/20 ...

  8. iOS推送(利用极光推送)

    本文主要是基于极光推送的SDK封装的一个快速集成极光推送的类的封装(不喜勿喷) (1)首先说一下推送的一些原理: Push的原理: Push 的工作机制可以简单的概括为下图 图中,Provider是指 ...

  9. 极光推送JPush的快速集成

    首先到极光推送的官网上创建一个应用,填写对应的应用名和包名. 创建好之后下载Demo 提取Sdk里面的图片和xml等资源文件放自己项目的相应位置,然后要注意的是.so文件的放置位置: 在main目录下 ...

随机推荐

  1. 安卓开发:UI组件-Button和EditText

    2.3Button Button继承自TextView,除了通过属性设置按钮样式,还可以通过绑定drawable文件的方式来实现不同样式. 2.3.1按钮样式 新建Activity:ButtonAct ...

  2. Setup script exited with error: command 'x86_64-linux-gnu-gcc' failed with exit status 1 解决办法

    今天在Ubuntu16.04 上安装python包的时候,出现了这个坑爹的问题: 解决办法,内容总结如下 情况是这样,报错是因为没有把依赖包安装全,报错情况如下图: 解决办法,先安装一些必须的依赖: ...

  3. Go-Ethereum 1.7.2 结合 Mist 0.9.2 实现众筹合约的实例

    目录 目录 1.什么是ICO? 2.众筹的奖励-代币 3.众筹合约的完善 3.1.设置众筹合约中使用的代币 3.2.众筹合约的基本设置 3.3.让众筹合约接收以太币 3.4.检测众筹合约是否完成 3. ...

  4. window下 mongodb快速安装

    下载地址 https://www.mongodb.org/dl/win32/x86_64-2008plus-ssl 建立文件夹和文件 #数据库路径 dbpath=G:\mongodb3.4.12\da ...

  5. 【原】Java学习笔记015 - 面向对象

    package cn.temptation; public class Sample01 { public static void main(String[] args) { // 传递 值类型参数 ...

  6. windows下scrapy安装问题,以及Twisted安装报错(error: Microsoft Visual C++ 14.0 is required.)完美解决办法

    方法1(通常是失败的) 1. 命令行执行: pip3 install scrapy 不管是网络问题也好,缺少相关的包也好,用这条命令安装scrapy我就没成功过...难受 方法2(成功) 手动安装相关 ...

  7. python文件上传

    1.前端代码 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UT ...

  8. MongoDB的导入与导出

    一.导入与导出可以操作本地的mongodb也可以是远程的mongodb,通用选项: -h host 主机 --port port 端口 -u username 用户名 -p password 密码 如 ...

  9. LeetCode算法题-Minimum Moves to Equal Array Elements(Java实现)

    这是悦乐书的第233次更新,第246篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第100题(顺位题号是453).给定大小为n的非空整数数组,找到使所有数组元素相等所需的 ...

  10. Linux操作系统上要慎用的6个命令及防范方法

    Linux操作系统上要慎用的6个命令及防范方法 基于Linux平台工作的童鞋都知道Linux命令行使用起来非常高效和快捷,但有时候也很危险,尤其是在你不确定你自己在正在做什么时候(别笑,别以为自己真的 ...