GukiZ and GukiZiana

题意:

区间加 给出$y$查询$a_i=a_j=y$的$j-i$最大值


一开始以为和论文CC题一样...然后发现他带修改并且是给定了值

这样就更简单了....

每个块维护排好序的结果

修改暴力重构+整块打标记

查询暴力查+整块二分找数量

复杂度$O(SlogS + \frac{N}{S} + S+\frac{N}{S}logS)$

woc求了一节课导数也没求出最值来又发现一开始式子列错了不管了我就开根号了..(我才不会说是因为乱搞了一下更慢了)

貌似是因为用pair上瘾的原因吧常数比较大....感觉zyf2000的写法不科学反而更快

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
typedef long long ll;
#define pii pair<ll,int>
#define MP make_pair
#define fir first
#define sec second
const int N=5e5+,M=,INF=1e9;
inline int read(){
char c=getchar();int x=,f=;
while(c<''||c>''){if(c=='-')f=-;c=getchar();}
while(c>=''&&c<=''){x=x*+c-'';c=getchar();}
return x*f;
} int n,Q,op,x,y; ll a[N];
int block,pos[N],m;
struct _Blo{
int l,r,n;
pii a[M];
pii& operator [](int x) {return a[x];}
}b[M];
void ini(){
block=sqrt(n);
m=(n-)/block+;
for(int i=;i<=n;i++) pos[i]=(i-)/block+;
for(int i=;i<=m;i++) b[i].l=(i-)*block+, b[i].r=i*block;
b[m].r=n;
}
struct Block{
ll add[N];
void Set(int x){
_Blo &t=b[x]; t.n=;
for(int i=t.l ; i<=t.r ; i++) t[++t.n]=MP(a[i],i);
sort(t.a+ , t.a+t.n+);
}
void Add(int l,int r,int v){
int pl=pos[l],pr=pos[r];
if(pl==pr){
for(int i=l;i<=r;i++) a[i]+=v;
Set(pl);
}else{
for(int i=l ; i<=b[pl].r ; i++) a[i]+=v;
Set(pl);
for(int i=b[pr].l ; i<=r ; i++) a[i]+=v;
Set(pr);
for(int i=pl+;i<pr;i++) add[i]+=v;
}
} int Que(ll v){
int l=INF,r=;
for(int x=;x<=m;x++){
_Blo &t=b[x];
int p=lower_bound(t.a+ , t.a+t.n+ , MP(v-add[x],) ) - t.a,
q=upper_bound(t.a+ , t.a+t.n+ , MP(v-add[x],INF) ) - t.a;
if(t[p].fir==v-add[x]) l=min(l,t[p].sec), r=max(r,t[q-].sec);
}
return r-l==-INF ? - : r-l;
}
}B;
int main(){
//freopen("in","r",stdin);
n=read();Q=read(); ini();
for(int i=;i<=n;i++) a[i]=read();
for(int i=;i<=m;i++) B.Set(i);
while(Q--){
op=read();
if(op==) x=read(),y=read(),B.Add(x,y,read());
else printf("%d\n",B.Que(read()) );
}
}

CF 551E. GukiZ and GukiZiana [分块 二分]的更多相关文章

  1. Codeforces 551E - GukiZ and GukiZiana(分块)

    Problem E. GukiZ and GukiZiana Solution: 先分成N=sqrt(n)块,然后对这N块进行排序. 利用二分查找确定最前面和最后面的位置. #include < ...

  2. Codeforces 551E GukiZ and GukiZiana(分块思想)

    题目链接 GukiZ and GukiZiana 题目大意:一个数列,支持两个操作.一种是对区间$[l, r]$中的数全部加上$k$,另一种是查询数列中值为$x$的下标的最大值减最小值. $n < ...

  3. 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 ...

  4. CodeForces 551E GukiZ and GukiZiana

    GukiZ and GukiZiana Time Limit: 10000ms Memory Limit: 262144KB This problem will be judged on CodeFo ...

  5. Codeforces 307 div2 E.GukiZ and GukiZiana 分块

    time limit per test 10 seconds memory limit per test 256 megabytes input standard input output stand ...

  6. 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 ...

  7. Codeforces 551 E - GukiZ and GukiZiana

    E - GukiZ and GukiZiana 思路:分块, 块内二分 代码: #pragma GCC optimize(2) #pragma GCC optimize(3) #pragma GCC ...

  8. [codeforces551E]GukiZ and GukiZiana

    [codeforces551E]GukiZ and GukiZiana 试题描述 Professor GukiZ was playing with arrays again and accidenta ...

  9. BZOJ_3343_教主的魔法_分块+二分查找

    BZOJ_3343_教主的魔法_分块+二分查找 题意:教主最近学会了一种神奇的魔法,能够使人长高.于是他准备演示给XMYZ信息组每个英雄看.于是N个英雄们又一次聚集在了一起,这次他们排成了一列被编号为 ...

随机推荐

  1. Team Queue(STL练习题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1387 Team Queue Time Limit: 2000/1000 MS (Java/Others ...

  2. XYZZY(spfa求最长路)

    http://acm.hdu.edu.cn/showproblem.php?pid=1317 XYZZY Time Limit: 2000/1000 MS (Java/Others)    Memor ...

  3. AMD规范学习笔记

    背景 NodeJS的一套比较简洁 Moudles 规范, 使得在服务器端的模块化变得更加简单.很长一段时间,很多公司或者项目都有自己的一套模块化机制, 却未能形成一套统一的标准, NodeJS的Mou ...

  4. Oracle_基本函数查询综合

    Oracle_基本函数查询综合 --[1]查询出每各月倒数第三天受雇的所有员工 select;   --[2]找出早于30年前受雇的员工 select>; select; select;     ...

  5. APACHE服务器出现No input file specified.的完美解决方案

    转自:http://www.upupw.net/server/n53.html 启用REWRITE的伪静态功能的时候,首页可以访问,而访问内页的时候,就提示:"No input file s ...

  6. curl说明

    https://baike.baidu.com/item/curl/10098606?fr=aladdin curl是利用URL语法在命令行方式下工作的开源文件传输工具.它被广泛应用在Unix.多种L ...

  7. git只添加指定类型的文件的.gitignore规则

    #忽略根目录下的所有文件 * #忽略子目录下的所有文件 /* #包含目录 !*/ #指定不忽略的文件 !*.c !*.h #忽略根目录下的文件 /build/ /appveyor/ /pear/ /s ...

  8. PostgreSql 分页limit

    摘录自:http://jingyan.baidu.com/article/a17d528538119b8098c8f2ca.html 语法: select * from persons limit   ...

  9. mysql主从同步(3)-percona-toolkit工具(数据一致性监测、延迟监控)使用梳理

    转自:http://www.cnblogs.com/kevingrace/p/6261091.html 在mysql工作中接触最多的就是mysql replication mysql在复制方面还是会有 ...

  10. _3_form_标签

    什么是input标签? 处理输入信息 input有哪些类型? 选择: <input type="checkbox"> 多选框,选择爱好等 <input type= ...