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 ...
随机推荐
- Ubuntu下python安装mysqldb(驱动)
最近在学习Django框架,需要使用到数据库,我使用的是mysql,跟java一样,需要安装驱动,这是驱动的下载网址http://sourceforge.net/projects/mysql-pyth ...
- JVM内存结构 VS Java内存模型 VS Java对象模型
前面几篇文章中, 系统的学习了下JVM内存结构.Java内存模型.Java对象模型, 但是发现自己还是对这三者的概念和区别比较模糊, 傻傻分不清楚.所以就有了这篇文章, 本文主要是对这三个技术点再做一 ...
- 关于FFT分析音频的学习
本文部分知识从以下文章学习: https://zhuanlan.zhihu.com/p/19763358 傅里叶变换的知识 https://www.cnblogs.com/RabbitHu/p/FFT ...
- oracle 删除用户,提示“无法删除当前已连接的用户”
1. 首先查询出该用户的登录情况,注意用户名必须是大写 SQL> select username,sid,serial# from v$session where username = 'XST ...
- IntelliJ IDEA + Maven + Jetty + Jersey搭建RESTful服务
这次参考的是这个博客,完全按照这个我这里会出一些问题,一会再说就是了. https://www.cnblogs.com/puyangsky/p/5368132.html 一.首先新建一个项目,选择Ja ...
- 【0807 | Day 10】字符编码以及Python2/3编码的区别
一.计算机基础 计算机组成:CPU.内存.硬盘 CPU:控制程序运行(从内存中取出文本编辑器的数据存入内存) 内存:运行程序 硬件:存储数据 二.文本编辑器存取文件的原理 比如计算机只能识别0和1,文 ...
- 【0730 | Day 4】Python基础(二)
Part 7 数据类型基础 一.什么是数据类型? 我们要和计算机进行交流,那么彼此肯定需要进行信息交互.我们想要让计算机认识我们,需要提供我们的身高.体重以及爱好等等.那么,不同的数据分别对应不同的数 ...
- 把Python项目打包成exe文件
我们很多时候,写好的程序需要打包成.exe文件才可以发给客户,那么今天我就来谈一谈,如何将一个写好的Python程序打包成exe文件! 首先,我们我们使用到的工具是python 3.7 和 Pyins ...
- Linux--shell重定向与文件处理命令--02
一.IO重定向 1.数据输入:键盘---标准输入,但并不是唯一输入方式 ” | passwd –stdin username #同时添加用户和密码 while line;do 循环体...$line ...
- c#引用本地dll发布后运行exe错误
在config 文件夹 configuration 配置节点下面 添加 <runtime> <gcConcurrent enabled="true" /> ...