CF 551 E GukiZ and GukiZiana
https://codeforces.com/contest/551/problem/E
分块真强。
题意就是1、区间加,2、询问整个区间中,最远的两个x的距离。
分块,然后,每次找位子用二分找即可。
#include <algorithm>
#include <iterator>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <iomanip>
#include <bitset>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <stack>
#include <cmath>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <cassert> using namespace std;
#define lson (l , mid , rt << 1)
#define rson (mid + 1 , r , rt << 1 | 1)
#define debug(x) cerr << #x << " = " << x << "\n";
#define pb push_back
#define pq priority_queue typedef long long ll;
typedef unsigned long long ull;
//typedef __int128 bll;
typedef pair<ll ,ll > pll;
typedef pair<int ,int > pii;
typedef pair<int,pii> p3;
typedef pair<ll,int>pli;
//priority_queue<int> q;//这是一个大根堆q
//priority_queue<int,vector<int>,greater<int> >q;//这是一个小根堆q
#define fi first
#define se second
//#define endl '\n'
//#define R register
#define OKC ios::sync_with_stdio(false);cin.tie(0)
#define FT(A,B,C) for(int A=B;A <= C;++A) //用来压行
#define REP(i , j , k) for(int i = j ; i < k ; ++i)
#define max3(a,b,c) max(max(a,b), c);
#define min3(a,b,c) min(min(a,b), c);
//priority_queue<int ,vector<int>, greater<int> >que; const ll mos = 0x7FFFFFFF; //
const ll nmos = 0x80000000; //-2147483648
const int inf = 0x3f3f3f3f;
const ll inff = 0x3f3f3f3f3f3f3f3f; //
const int mod = 1e9+;
const double esp = 1e-;
const double PI=acos(-1.0);
const double PHI=0.61803399; //黄金分割点
const double tPHI=0.38196601; template<typename T>
inline T read(T&x){
x=;int f=;char ch=getchar();
while (ch<''||ch>'') f|=(ch=='-'),ch=getchar();
while (ch>=''&&ch<='') x=x*+ch-'',ch=getchar();
return x=f?-x:x;
} /*-----------------------showtime----------------------*/ const int maxn = 5e5+;
ll a[maxn];
int be[maxn];
int blo;
ll add[maxn];
vector<pli>v[maxn];
int n,m;
void rebuild(int id){
v[id].clear(); for(int i=(id-)*blo + ; i<= min(n,id*blo); i++){
a[i] += add[id];
v[id].pb(pli(a[i],i));
}
sort(v[id].begin(),v[id].end());
add[id] = ;
}
int main(){
scanf("%d%d", &n, &m);
for(int i=; i<=n; i++) scanf("%lld", &a[i]);
// blo = (int)sqrt(n);
blo = ;
for(int i=; i<=n; i++){
be[i] = (i-)/blo + ;
v[be[i]].pb(pli(a[i],i));
}
for(int i=; i<=be[n]; i++){
sort(v[i].begin(),v[i].end());
} while(m--){
int op; scanf("%d", &op);
if(op == ){
int l,r,x;
scanf("%d%d%d", &l, &r, &x);
for(int i=l; i<= min(r, be[l]*blo); i++){
a[i] += x;
}
rebuild(be[l]); if(be[l] < be[r]){
for(int i=be[l]+; i<=be[r]-; i++){
add[i] += x;
} for(int i=(be[r]-)*blo+; i<= r; i++){
a[i] += x;
}
rebuild(be[r]);
}
}
else {
int x; scanf("%d", &x);
int le=n+,ri=-;
for(int i=; i<=be[n]; i++){
int tmp = lower_bound(v[i].begin(),v[i].end(),pli(1ll*(x-add[i]),)) - v[i].begin(); if(v[i][tmp].fi == x-add[i]){
le = min(le, v[i][tmp].se);
}
tmp = upper_bound(v[i].begin(), v[i].end(), pli(1ll*(x-add[i]),n+)) - v[i].begin() - ;
if(tmp>= && v[i][tmp].fi == x-add[i]){
ri = max(ri, v[i][tmp].se);
}
}
if(le <= ri){
printf("%d\n", ri - le);
}
else puts("-1"); }
}
return ;
}
自己一开始把 块的id 和 i 搞混了...
CF 551 E GukiZ and GukiZiana的更多相关文章
- Codeforces 551 E - GukiZ and GukiZiana
E - GukiZ and GukiZiana 思路:分块, 块内二分 代码: #pragma GCC optimize(2) #pragma GCC optimize(3) #pragma GCC ...
- CF 551E. GukiZ and GukiZiana [分块 二分]
GukiZ and GukiZiana 题意: 区间加 给出$y$查询$a_i=a_j=y$的$j-i$最大值 一开始以为和论文CC题一样...然后发现他带修改并且是给定了值 这样就更简单了.... ...
- 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(分块)
Problem E. GukiZ and GukiZiana Solution: 先分成N=sqrt(n)块,然后对这N块进行排序. 利用二分查找确定最前面和最后面的位置. #include < ...
- 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 D. GukiZ and Binary Operations
\(>Codeforces \space 551 D. GukiZ and Binary Operations<\) 题目大意 :给出 \(n, \ k\) 求有多少个长度为 \(n\) ...
- Codeforces 551E GukiZ and GukiZiana(分块思想)
题目链接 GukiZ and GukiZiana 题目大意:一个数列,支持两个操作.一种是对区间$[l, r]$中的数全部加上$k$,另一种是查询数列中值为$x$的下标的最大值减最小值. $n < ...
- [codeforces551E]GukiZ and GukiZiana
[codeforces551E]GukiZ and GukiZiana 试题描述 Professor GukiZ was playing with arrays again and accidenta ...
- CodeForces 551E GukiZ and GukiZiana
GukiZ and GukiZiana Time Limit: 10000ms Memory Limit: 262144KB This problem will be judged on CodeFo ...
随机推荐
- OOM和JVM配置优化
OOM这个缩写就是Java程序开发过程中让人最头痛的问题:Out of Memory.在很多开发人员的开发过程中,或多或少的都会遇到这类问题,这类问题定位比较困难,往往需要根据经验来判断可能出现问题的 ...
- Appium+python自动化(二十八)- 滑呀滑,滑到奈何桥喝碗孟婆汤 - 高级滑动(超详解)
简介 奈何桥上叹奈何,三生石前憾三生,彼岸花下非彼岸,奈何三生彼岸人. 相传过了鬼门关便上一条路叫黄泉路,路上盛开着只见花,不见叶的彼岸花.花叶生生两不见,相念相惜永相失,路尽头有一条河叫忘川河,河上 ...
- 【游记】NOIP2019前传
声明 我的游记是一个完整的体系,如果没有阅读过往届文章,阅读可能会受到障碍. ~~~上一篇游记的传送门~~~ 前言 比完赛后,我沉浸在胜利中长达半个月,而后才清醒过来,意识到自己需要为NOIP2019 ...
- 一文读懂tomcat组件--一个web服务器的架构演化史
1. tomcat是谁? 2. tomcat可以做什么? tomcat是一个web容器,可以将web应用部署到tomcat,由它提供web服务,一个web容器中可以部署多个web应用,这些we ...
- 前后端分离后台api接口框架探索
前言 很久没写文章了,今天有时间,把自己一直以来想说的,写出来,算是一种总结吧! 这篇文章主要说前后端分离模式下(也包括app开发),自己对后台框架和与前端交互的一些理解和看法. 前后端分离 ...
- Android 使用 DiffUtil 处理 RecyclerView 数据更新问题
背景 RecyclerView.Adapter#notifyDataSetChanged() 会每次刷新整个布局: 每次手动调用 RecyclerView.Adapter#notifyItemXx 系 ...
- myeclipse源码相关操作
做web开发经常要看别人的jar里的源码才能搞懂别人的想法,但是源码有的时候需要单独下载很麻烦,甚至有的新的jar根本就是没有源码的,那么我们能不能自己制作源码呢. 从jar中提取源码 说白了,提取源 ...
- h5微信分享
h5分享的步骤(前端需要完成的部分) 1.绑定域名 登录微信公众平台进入“公众号设置”的“功能设置”里填写“JS接口安全域名”. 2.引入Js文件 在需要调用JS接口的页面引入如下JS文件,(支持ht ...
- Oracle - SPM固定执行计划(一)
一.前言 生产中偶尔会碰到一些sql,有多种执行计划,其中部分情况是统计信息过旧造成的,重新收集下统计信息就行了.但是有些时候重新收集统计信息也解决不了问题,而开发又在嗷嗷叫,没时间让你去慢慢分析原因 ...
- html页面中关于按钮type的要求
重要事项:如果在 HTML 表单中使用 button 元素,不同的浏览器会提交不同的值.Internet Explorer 将提交 <button> 与 </button> 之 ...