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. Educational Codeforces Round 2_B. Queries about less or equal elements

    B. Queries about less or equal elements time limit per test 2 seconds memory limit per test 256 mega ...

  2. 最新版Sublime Text Build 3156 x64 的下载 + 注册码 + Install Package Control + 汉化教程

    一.Sublime Text  下载 神器 Sublime Text 最近开始更新到开发版本 Build 3156,本身英语不是太6,汉化党自然各种百度汉化教程,网上不是一堆绿色汉化包,就是让你下载汉 ...

  3. 构建LVS-DR+Keepalive高可用集群

    ------client----------主LVS----------从LVS------------WEB1-------------WEB2--------- 2.2.2.250  2.2.2. ...

  4. 教你理解微信小程序的生命周期和运行原理

    转自:http://blog.csdn.net/tsr106/article/details/53052879  写微信小程序,他的生命周期不能不知道,不知道小程序就会出现各种bug而无法解决.小助君 ...

  5. cookie 和 session的区别

    一.总结: 1.cookie数据存放在客户的浏览器上,session数据放在服务器上. 2.cookie不是很安全,别人可以分析存放在本地的COOKIE并进行COOKIE欺骗 考虑到安全应当使用ses ...

  6. JavaScript八张思维导图—操作符

    JS基本概念 JS操作符 JS基本语句 JS数组用法 Date用法 JS字符串用法 JS编程风格 JS编程实践 不知不觉做前端已经五年多了,无论是从最初的jQuery还是现在火热的Angular,Vu ...

  7. YUI 和路径相关的参数与module加载之间的关系

    相关参数默认值 使用YUI, 我们可以配置一些和路径相关参数,如base.root.comboBase.cdn, combine.path.fullpath等属性的配置均会影响到YUI的module加 ...

  8. tomcat实现热部署的配置

    p { margin-bottom: 0.25cm; direction: ltr; color: rgb(0, 0, 0); line-height: 120%; text-align: justi ...

  9. win7下IIS的安装和配置

    win7下IIS的安装和配置 图文教程,需要的朋友可以参考下 http://www.jb51.net/article/29787.htm 最近工作需要IIS,自己的电脑又是Windows7系统,找了下 ...

  10. [field:softlinks/]逻辑过程

    在plus/download.php 在dededln\include\taglib\channel\softlinks.lib.php