题目链接

题面

题意

把每个位置的点都看成是一个二维坐标系中的点。比如第\(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. 数据库CRUD操作以及MyBatis的配置使用

    • 业务字段设计 • 数据库创建 • CRUD操作 • MyBatis集成 • 注解和XML定义 • ViewObject和DateTool • 首页开发     • 业务字段设计 实体: name: ...

  2. Spring MVC中用@ResponseBody转json,对json进行处理方法汇总

    <mvc:annotation-driven> <mvc:message-converters register-defaults="true"> < ...

  3. 生成Csv格式的字符串

    using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using Sy ...

  4. Linux shell编写脚本部署pxe网络装机

    Linux shell编写脚本部署pxe网络装机 人工安装配置,Linux PXE无人值守网络装机  https://www.cnblogs.com/yuzly/p/10582254.html 脚本实 ...

  5. 进程命令(tasklist)

    TaskList命令: // 描述: 显示本地或远程计算机上正在运行的进程列表信息. // 语法: tasklist [/s <computer> [ /u [<domain> ...

  6. 批处理基础知识-EXIT

    本文主要介绍批处理EXIT命令的使用. 阅读须知: 在开始阅读本文之前,您需要知道批处理CALL命令和ERRORLEVEL相关知识,若您没有接触过类似信息,建议goole或baidu. EXIT命令格 ...

  7. Windows 版 SourceTree 免登录跳过初始设置的方法

    首先去官网下载最新的sourcetree安装包,点击打开下载地址. 下载完成后安装,等到他自启动开始提示你登录的时候,打开“我的电脑(此电脑)”,在最上边的输入栏输入%LocalAppData%\At ...

  8. redis Lua学习与坑

    1.在写lua脚本往redis中添加zadd 有序集合的时候一直报 "value is not a valid float"的错误,经过查询相关资料,最后发现,是顺序写反了. 相关 ...

  9. c++11の数据竞争和互斥对象

    一.数据竞争的产生 在下面例子中: void function_1() { ; i < ; i++) { std::cout << "from function 1:&qu ...

  10. python之函数对象、函数嵌套、名称空间与作用域、装饰器

    一 函数对象 一 函数是第一类对象,即函数可以当作数据传递 #1 可以被引用 #2 可以当作参数传递 #3 返回值可以是函数 #3 可以当作容器类型的元素 二 利用该特性,优雅的取代多分支的if de ...