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 ...
随机推荐
- UI设计--->全心全意为人民服务的宗旨---->注重客户体验--->软件持久的生命力
UI即User Interface(用户界面)的简称. UI设计是指对软件的人机交互.操作逻辑.界面美观的总体设计. 好的UI设计不仅是让软件变得有个性有品味,还要让软件的操作变得舒适简单.自由.充分 ...
- React Native布局实践:开发京东client首页(三)——轮播图的实现
上篇文章中,我们一起构建了京东client的TabBar.在本文中.将继续向大家介绍京东client首页轮播图及其下发功能button的开发方法,如今就让我们開始吧! 1.相关控件调研 眼下在Gith ...
- linux下dd命令详解【转】
本文转载自:http://www.cnblogs.com/licheng/articles/1116492.html 名称: dd 使用权限: 所有使用者dd 这个指令在 manual 里的定义是 ...
- codeforces round #424 div2
A 暴力查询,分三段查就可以了 #include<bits/stdc++.h> using namespace std; ; int n, pos; int a[N]; int main( ...
- Python 33(2)进程理论
一:什么是进程 进程指的是一个正在进行 / 运行的程序,进程是用来描述程序执行过程的虚拟概念 进程vs程序 程序:一堆代码 进程:程序的执行的过程 进程的概念起源于操作系统,进程是操作 ...
- android 提纲挈领
之后的android学习将侧重三方面: 1.基础内容例如xml属性.sharedpreference.数据库必须能够熟记于心. 2.开源library熟练应用,能够了解如何更好地使用各种开源libra ...
- android黑科技系列——修改锁屏密码和恶意锁机样本原理分析
一.Android中加密算法 上一篇文章已经介绍了Android中系统锁屏密码算法原理,这里在来总结说一下: 第一种:输入密码算法 将输入的明文密码+设备的salt值,然后操作MD5和SHA1之后在转 ...
- 解决无法移除tomcat中的项目
问题:启动myeclipse,tomcat提示报错,blind,但是你移除的时候无法移除,只会显示一个黄色的感叹号,此时你直接在webapp中删除时,也提示呗占用无法删除. 办法:关掉myeclips ...
- weblogic详解
一.简介 WebLogic是美国Oracle公司出品的一个application server,确切的说是一个基于JAVAEE架构的中间件,WebLogic是用于开发.集成.部署和管理大型分布式Web ...
- vue使用插槽分发内容slot的用法
将父组件的内容放到子组件指定的位置叫做内容分发 //在父组件里使用子组件 <son-tmp> <div>我是文字,我需要放到son-tmp组件里面制定的位置</div&g ...