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. See you~(二维树状数组)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1892 See you~ Time Limit: 5000/3000 MS (Java/Others)  ...

  2. Equals()和GetHashCode()方法深入了解

    最近在看Jeffrey Richter的CLR Via C#,在看到GetHashCode()方法的时候,有一个地方不是特别明白,就是重写Equals()方法时为什么要把GetHashCode()方法 ...

  3. Logback日志配置的简单使用

    Logback介绍 Logback是由log4j创始人设计的又一个开源日志组件.logback当前分成三个模块:logback-core,logback- classic和logback-access ...

  4. PHP中的GetType和SetType

    大部分的可变函数都是用来测试一个函数的类型的.PHP中有两个最常见的函数,分别是gettype()和settype().这两个函数具有如下所示的函数原型,通过他们可以获得要传递的参数和返回的结果. s ...

  5. nginx 防火墙、权限问题

      1.nginx安装,配置完成之后,尝试访问没有响应,主机可以ping通,/var/log/nginx/access.log日志没有查到任何记录 解决方法:查看linux防火墙,关闭 命令:ipta ...

  6. WdatePicker时间插件

    next_door_boy CnBlogs Home New Post Contact Admin Rss Posts - 14  Articles - 5  Comments - 0  WdateP ...

  7. zabbix入门知识

    zabbix入门知识 zabbix中文手册 https://www.zabbix.com/documentation/3.4/manual/ 1.zabbix介绍 Zabbix 是一个企业级的分布式开 ...

  8. cuda纹理内存的使用

    CUDA纹理内存的访问速度比全局内存要快,因此处理图像数据时,使用纹理内存是一个提升性能的好方法. 贴一段自己写的简单的实现两幅图像加权和的代码,使用纹理内存实现. 输入:两幅图 lena, moon ...

  9. Django_注册全局消息

    需求: 对于登录用户,无论他在哪个页面,我都需要给他全局发送一个消息提示,Django中request就是一个全局变量 那,如何做? 在models 中urser表,继承user的表类中写上一个函数, ...

  10. Servlet--转发和重定向

    Servlet的跳转有2种,一种是转发,一种是重定向. 重定向: <strong><span style="font-size:14px;"></sp ...