bzoj4170 极光
题面

题意
把每个位置的点都看成是一个二维坐标系中的点。比如第\(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 极光的更多相关文章
- 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 ...
- BZOJ4170:极光(CDQ分治)
Description "若是万一琪露诺(俗称rhl)进行攻击,什么都好,冷静地回答她的问题来吸引她.对方表现出兴趣的话,那就慢慢地反问.在她考虑答案的时候,趁机逃吧.就算是很简单的问题,她 ...
- BZOJ4170:极光
浅谈离线分治算法:https://www.cnblogs.com/AKMer/p/10415556.html 题目传送门:https://lydsy.com/JudgeOnline/problem.p ...
- 使用极光推送(www.jpush.cn)向安卓手机推送消息【服务端向客户端主送推送】C#语言
在VisualStudio2010中新建网站JPushAndroid.添加引用json帮助类库Newtonsoft.Json.dll. 在web.config增加appkey和mastersecret ...
- 使用极光/友盟推送,APP进程杀死后为什么收不到推送(转)
为什么会存在这样的 问题,刚开始的时候我也搞不清楚,之前用极光的时候杀死程序后也会收到推送,但最近重新再去集成时就完全不好使了,这我就纳闷了,虽然Google在高版本上的android上面不建议线程守 ...
- 用JPUSH极光推送实现服务端向安装了APP应用的手机推送消息(C#服务端接口)
这次公司要我们做一个功能,就是当用户成功注册以后,他登录以后要收到消息,当然这个消息是安装了我们的手机APP应用的手机咯. 极光推送的网站的网址是:https://www.jpush.cn/ 极光推送 ...
- 极光推送-适配 iOS10
//************************ iOS10 适配 **************************// //************************ 11/02/20 ...
- iOS推送(利用极光推送)
本文主要是基于极光推送的SDK封装的一个快速集成极光推送的类的封装(不喜勿喷) (1)首先说一下推送的一些原理: Push的原理: Push 的工作机制可以简单的概括为下图 图中,Provider是指 ...
- 极光推送JPush的快速集成
首先到极光推送的官网上创建一个应用,填写对应的应用名和包名. 创建好之后下载Demo 提取Sdk里面的图片和xml等资源文件放自己项目的相应位置,然后要注意的是.so文件的放置位置: 在main目录下 ...
随机推荐
- Nodejs 操作 Sql Server
Nodejs 操作 Sql Server Intro 最近项目需要爬取一些数据,数据有加密,前端的js又被混淆了,ajax请求被 hook 了,有些复杂,最后打算使用 puppeteer 来爬取数据. ...
- ssh服务突然连接不了案例总结
ssh服务突然连接不了案例总结 一台Oracle数据库服务器(Linux版本为Oracle Linux Server release 5.7)今天中午突然出现短暂的ssh连接不上的情况,ssh连接 ...
- c/c++ 重载运算符 类型转换运算符
重载运算符 类型转换运算符 问题:能不能把一个类型A的对象a,转换成另一个类型B的对象b呢?? 是可以的.这就必须要用类型A的类型转换运算符(conversion operator) 下面的opera ...
- 电信中兴F460光猫sendcmd命令
1.安装xshell后,使用命令行登陆root用户,root用户密码Zte521(湖北地区) 2.查看所有用户密码 sendcmd 1 DB p DevAuthInfo 3.打开网页登陆teleco ...
- Ubuntu 16.04 使用校园网客户端上网
对于使用校园网的学生来说,安装好Ubuntu之后,很多人需要用 DrClient 客户端来上网,那么怎么操作呢, 这里介绍 DrClient 客户端在Ubuntu上的使用方法, 首先下载 对应版本的软 ...
- topjui中datagrid增删改查
1.掌握datagrid的创建方式在html中直接定义与在js中定义 可参考easyui的官方文档:http://www.jeasyui.net/plugins/183.html 2.实现代码如下:重 ...
- 有效的字母异位词的golang实现
给定两个字符串 s 和 t ,编写一个函数来判断 t 是否是 s 的一个字母异位词. 输入: s = "anagram", t = "nagaram" 输出: ...
- mysql的分组
以下是根据老师的视屏写的总结,要自己实际操作以下. 首先老师一顿操作猛如虎,得到以下的表. 然后进行以下的操作: 发现筛选时报错了,老师的解释实说,分组是因为mysql不知道选择谁而出现报错,因为pa ...
- 生成文件的MD5值
import hashlib #########测试################# m = hashlib.md5() m.update(b"hello") m.update( ...
- 【English】20190415
approximately大约 [əˈprɑ:ksɪmətli] This install will take + minutes and requires the download of appro ...