CF 551E. 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 [分块 二分]的更多相关文章
- 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 < ...
- 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 551E GukiZ and GukiZiana
GukiZ and GukiZiana Time Limit: 10000ms Memory Limit: 262144KB This problem will be judged on CodeFo ...
- Codeforces 307 div2 E.GukiZ and GukiZiana 分块
time limit per test 10 seconds memory limit per test 256 megabytes input standard input output stand ...
- 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 ...
- Codeforces 551 E - GukiZ and GukiZiana
E - GukiZ and GukiZiana 思路:分块, 块内二分 代码: #pragma GCC optimize(2) #pragma GCC optimize(3) #pragma GCC ...
- [codeforces551E]GukiZ and GukiZiana
[codeforces551E]GukiZ and GukiZiana 试题描述 Professor GukiZ was playing with arrays again and accidenta ...
- BZOJ_3343_教主的魔法_分块+二分查找
BZOJ_3343_教主的魔法_分块+二分查找 题意:教主最近学会了一种神奇的魔法,能够使人长高.于是他准备演示给XMYZ信息组每个英雄看.于是N个英雄们又一次聚集在了一起,这次他们排成了一列被编号为 ...
随机推荐
- hdu_1573 X问题(不互素的中国剩余定理)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1573 X问题 Time Limit: 1000/1000 MS (Java/Others) Me ...
- 学习Spring必学的Java基础知识(2)----动态代理
Spring AOP使用动态代理技术在运行期织入增强的代码,为了揭示Spring AOP底层的工作机理,有必要对涉及到的Java知识进行学习.Spring AOP使用了两种代理机制:一种是基于JDK的 ...
- MVC学习笔记(分享)
一.SpringMVC基础入门,创建一个HelloWorld程序 1.首先,导入SpringMVC需要的jar包. 2.添加Web.xml配置文件中关于SpringMVC的配置 <!--conf ...
- nodeJs文件系统(fs)与流(stream)
一.简介 本文将介绍node.js文件系统(fs)和流(stream)的一些API已经参数使用情况. 二.目录 文件系统将介绍以下方法: 1.fs.readFile 2.fs.writeFile 3. ...
- [国嵌攻略][136][DM9000网卡驱动深度分析]
网卡初始化 1.分配描述结构,alloc_etherdev 2.获取平台资源,platform_get_resource 2.1.在s3c_dm9k_resource中有相关的资源 2.2.add地址 ...
- C++ 默认参数(转载)
函数的默认参数值,即在定义参数的时候同时给它一个初始值.在调用函数的时候,我们可以省略含有默认值的参数.也就是说,如果用户指定了参数值,则使用用户指定的值,否则使用默认参数的值. void Func( ...
- 十二个 ASP.NET Core 例子——过滤器
目录: 过滤器介绍 过滤器类别 自定义过滤器和过滤特性 直接短路返回内容 过滤器与中间件的区别 如果要全局日志,不要用过滤器 官方文档传送门 1.过滤器介绍 没有权限直接返回,资源缓存,Action执 ...
- How to bypass Win10 logon password?
Usually we will use LiveView or VFC to "boot up" the evidence files acquired from suspect' ...
- 解除织梦dedeCMS标题/关键词/ 简略标题长度限制听语音
dedeCMS標題.關鍵詞和簡略標題長度有限制,展示不全. 三者均使用SQL修改dede_archives主表關鍵詞和簡略標題還需修改/dede/目錄中的: archives_add.php, ...
- nodejs http小爬虫
本课程用nodejs写一个http小爬虫,首先科普一下,爬虫就是把网上的网页代码给弄下来,然后纳为己用.目前最大的爬虫:百度快照等的. 下面直接上代码 示例一: var http = require( ...