CodeForces 551E GukiZ and GukiZiana
GukiZ and GukiZiana
This problem will be judged on CodeForces. Original ID: 551E
64-bit integer IO format: %I64d Java class name: (Any)
Professor GukiZ was playing with arrays again and accidentally discovered new function, which he called GukiZiana. For given array a, indexed with integers from 1 to n, and numbery, GukiZiana(a, y) represents maximum value of j - i, such that aj = ai = y. If there is no y as an element in a, then GukiZiana(a, y) is equal to - 1. GukiZ also prepared a problem for you. This time, you have two types of queries:
- First type has form 1 l r x and asks you to increase values of all ai such that l ≤ i ≤ r by the non-negative integer x.
- Second type has form 2 y and asks you to find value of GukiZiana(a, y).
For each query of type 2, print the answer and make GukiZ happy!
Input
The first line contains two integers n, q (1 ≤ n ≤ 5 * 105, 1 ≤ q ≤ 5 * 104), size of array a, and the number of queries.
The second line contains n integers a1, a2, ... an (1 ≤ ai ≤ 109), forming an array a.
Each of next q lines contain either four or two numbers, as described in statement:
If line starts with 1, then the query looks like 1 l r x (1 ≤ l ≤ r ≤ n, 0 ≤ x ≤ 109), first type query.
If line starts with 2, then th query looks like 2 y (1 ≤ y ≤ 109), second type query.
Output
For each query of type 2, print the value of GukiZiana(a, y), for y value for that query.
Sample Input
4 3
1 2 3 4
1 1 2 1
1 1 1 1
2 3
2
2 3
1 2
1 2 2 1
2 3
2 4
0
-1
Source
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = ;
LL a[maxn*maxn],lazy[maxn],x;
vector<int>block[maxn];
int b_size,N,pos[maxn*maxn],n,q,cmd,L,R;
bool cmp(const int x,const int y) {
if(a[x] == a[y]) return x < y;
return a[x] < a[y];
}
void update(int L,int R,LL x) {
int k = pos[L],t = pos[R];
if(k == t) {
for(int i = L; i <= R; ++i) a[i] += x;
sort(block[k].begin(),block[k].end(),cmp);
return;
}
for(int i = k + (pos[L-] == k); i <= t - (pos[R + ] == t); ++i) lazy[i] += x;
if(pos[L-] == k) {
for(int i = L; pos[i] == k; ++i) a[i] += x;
sort(block[k].begin(),block[k].end(),cmp);
}
if(pos[R+] == t) {
for(int i = R; pos[i] == t; --i) a[i] += x;
sort(block[t].begin(),block[t].end(),cmp);
}
}
LL query(LL x) {
int L = -,R = -,i;
for(i = ; i <= N; ++i){
a[] = x - lazy[i];
vector<int>::iterator it = lower_bound(block[i].begin(),block[i].end(),,cmp);
if(it == block[i].end()) continue;
if(a[*it] + lazy[i] == x){
L = *it;
break;
}
}
if(L == -) return -;
for(int j = N; j >= i; --j){
a[n+] = x - lazy[j];
vector<int>::iterator it = lower_bound(block[j].begin(),block[j].end(),n+,cmp);
if(it == block[j].begin()) continue;
--it;
if(a[*it] + lazy[j] == x){
R = *it;
break;
}
}
return R - L;
}
int main() {
ios::sync_with_stdio(false);
cin.tie();
cin>>n>>q;
b_size = ceil(sqrt(n*1.0));
for(int i = ; i <= n; ++i) {
cin>>a[i];
pos[i] = (i - )/b_size + ;
block[pos[i]].push_back(i);
}
N = (n - )/b_size + ;
for(int i = ; i <= N; ++i) sort(block[i].begin(),block[i].end(),cmp);
while(q--) {
cin>>cmd;
if(cmd == ) {
cin>>L>>R>>x;
update(L,R,x);
} else {
cin>>x;
cout<<query(x)<<endl;
}
}
return ;
}
CodeForces 551E GukiZ and GukiZiana的更多相关文章
- Codeforces 551E - GukiZ and GukiZiana(分块)
Problem E. GukiZ and GukiZiana Solution: 先分成N=sqrt(n)块,然后对这N块进行排序. 利用二分查找确定最前面和最后面的位置. #include < ...
- Codeforces 551E GukiZ and GukiZiana(分块思想)
题目链接 GukiZ and GukiZiana 题目大意:一个数列,支持两个操作.一种是对区间$[l, r]$中的数全部加上$k$,另一种是查询数列中值为$x$的下标的最大值减最小值. $n < ...
- CF 551E. GukiZ and GukiZiana [分块 二分]
GukiZ and GukiZiana 题意: 区间加 给出$y$查询$a_i=a_j=y$的$j-i$最大值 一开始以为和论文CC题一样...然后发现他带修改并且是给定了值 这样就更简单了.... ...
- Codeforces Round #307 (Div. 2) E. GukiZ and GukiZiana 分块
E. GukiZ and GukiZiana Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/55 ...
- Codeforces 551 E - GukiZ and GukiZiana
E - GukiZ and GukiZiana 思路:分块, 块内二分 代码: #pragma GCC optimize(2) #pragma GCC optimize(3) #pragma GCC ...
- Codeforces Round #307 (Div. 2) E. GukiZ and GukiZiana(分块)
E. GukiZ and GukiZiana time limit per test 10 seconds memory limit per test 256 megabytes input stan ...
- [codeforces551E]GukiZ and GukiZiana
[codeforces551E]GukiZ and GukiZiana 试题描述 Professor GukiZ was playing with arrays again and accidenta ...
- (分块)GukiZ and GukiZiana CodeForces - 551E
题意: 给你一段序列,并且有两种操作 操作①:将序列中从l-r每个元素加上x 操作②:在序列中找到ai=aj=y,j-i的最大值,如果找不到则输出-1 思路: 直接分块暴力即可 对于区间加,普通标记加 ...
- Codeforces 307 div2 E.GukiZ and GukiZiana 分块
time limit per test 10 seconds memory limit per test 256 megabytes input standard input output stand ...
随机推荐
- 加密学教程(Cryptography Tuturials)文件夹
加密学教程(Cryptography Tuturials) 太阳火神的漂亮人生 (http://blog.csdn.net/opengl_es) 本文遵循"署名-非商业用途-保持一致&quo ...
- Codeforces Round #332 (Div. 2)D. Spongebob and Squares 数学
D. Spongebob and Squares Spongebob is already tired trying to reason his weird actions and calcula ...
- C++顺序表(模板总结)
C++顺序表(模板总结) 总结: 1.模板类的实质是什么:让程序员写出和类型无关的代码 2.模板的对象时什么:方法或者类 3.是对类中的一系列操作,提供一个不固定数据类型的方法 用模板做的类的时候要指 ...
- DNS隐蔽通道 是可以通过dig 子域名来追踪其真实IP的
比如a.friendskaka.com 是我的外发子域名,那么可以按照下面两个命令来追踪IP: bonelee@bonelee-VirtualBox:~/桌面$ dig auth.a.friendsk ...
- 【BZOJ 1598】 牛跑步
[题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=1598 [算法] A*求k短路 [代码] #include<bits/stdc+ ...
- NOIP2013--火柴排队(树状数组)
转载: 树状数组,具体的说是 离散化+树状数组.这也是学习树状数组的第一题. 算法的大体流程就是: 1.先对输入的数组离散化,使得各个元素比较接近,而不是离散的, 2.接着,运用树状数组的标准操作来累 ...
- bzoj2503 相框——思路
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2503 思路题: 首先,这种问题应该注意到答案只跟度数有关,跟其他什么连接方法之类的完全无关: ...
- html5小知识点
1.兼容性问题: 对于不支持H5标签的浏览器,可以使用javascript来解决他们.然后在样式表中对这些标签定义一下默认的display:block. 采用第三方库:html5shiv.js < ...
- [Apple开发者帐户帮助]二、管理你的团队(2)更改团队成员角色
如果您已加入Apple开发者计划,您将在App Store Connect中管理团队成员.有关详细信息,请转到App Store Connect帮助中的添加和编辑用户. 如果您已加入Apple Dev ...
- jmeter 参数化学习笔记
上次写了在接口的交互过程中,系统返回的内容,需要在接下来的交互中用到,从而把参数进行参数化的关联,这次写一下在压测过程中,如果每次发起请求参数名相同,单参数值需要替换的,我们需要进行的参数化. 在使用 ...