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. c语言中标识符的作用域

    1.代码块作用域(block scope) 位于一对花括号之间的所有语句称为一个代码块,在代码块的开始位置声明的标识符具有代码块作用域,表示它们可以被这个代码中的所有语句访问.函数定义的形式参数在函数 ...

  2. 大白话说Java泛型(二):深入理解通配符

    文章首发于[博客园-陈树义],点击跳转到原文<大白话说Java泛型(二):深入理解通配符> 上篇文章<大白话说Java泛型(一):入门.原理.使用>,我们讲了泛型的产生缘由以及 ...

  3. [国嵌攻略][159][SPI子系统]

    SPI 子系统架构 1.SPI core核心:用于连接SPI客户驱动和SPI主控制器驱动,并且提供了对应的注册和注销的接口. 2.SPI controller driver主控制器驱动:用来驱动SPI ...

  4. python基础2 day3

    一.上节回顾 1,while else2,格式化输出name = input('>>>')s1 = '我叫%s,今年%d岁'%(name,18)dic1name = input('& ...

  5. 十二个 ASP.NET Core 例子——中间件

    目录: 什么是中间件(IApplicationBuilder) 创建 顺序规则 Asp.Net Core 内置的中间件 1.什么是中间件 官方:中间件是组装成应用程序管道以处理请求和响应的软件.每个组 ...

  6. dedecms====phpcms 区别==[工作]

    {template "content","header"}{dede:include filename="head.htm"/} ----- ...

  7. 邓_php面试【002】——完整版

    1.用PHP打印出前一天的时间格式是2006-5-10 22:21:21(2分) $a = date("Y-m-d H:i:s", strtotime("-1 day&q ...

  8. Struts2与Ajax数据交互

    写在前面: ajax请求在项目中常常使用,今天就平时掌握的总结一下,关于使用ajax请求到Struts2中的action时,前台页面与后台action之间的数据传递交互问题. 这里我主要记录下自己所掌 ...

  9. Android-第三天

    今天开始做一个提交的页面,本来是用LinearLayout,但是这种布局要使用到多组LinearLayout,于是采用表格布局+相对布局的方式. <TableLayout> <Tab ...

  10. Java 获得Class的绝对路径方法

    Java获得class文件的绝对路径:1.e.g. Foo.class => Foo.class.getResuorce("").getFile(); 该方法在eclipse ...