嗯...

题目链接:https://loj.ac/problem/6279

这道题在分块的基础上用vc数组记录,然后最后分三块,两边暴力枚举找前驱,中间lower_bound找前驱。

AC代码:

 #include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector> using namespace std; const int maxn = ;
const int N = ;
const int INF = 0x3f3f3f3f; int a[maxn], belong[maxn];
int L[N], R[N], add[N];
int block, num;
vector<int> vc[N]; inline void build(int n){
block = sqrt(n);
num = ceil(n * 1.0 / block);
for(int i = ; i <= n; i++){
belong[i] = (i - ) / block + ;
vc[belong[i]].push_back(a[i]);
}
for(int i = ; i <= num; i++){
L[i] = R[i - ] + ;
R[i] = i * block;
sort(vc[i].begin(), vc[i].end());
}
R[num] = n;
} inline void update(int pos){
vc[pos].clear();
for(int i = L[pos]; i <= R[pos]; i++) vc[pos].push_back(a[i]);
sort(vc[pos].begin(), vc[pos].end());
} inline void modify(int l, int r, int c){
for(int i = l; i <= min(r, R[belong[l]]); i++) a[i] += c;
update(belong[l]);
if(belong[l] != belong[r]){
for(int i = L[belong[r]]; i <= r; i++) a[i] += c;
update(belong[r]);
}
for(int i = belong[l] + ; i < belong[r]; i++) add[i] += c;
} inline int query(int l, int r, int c){
int ans = -INF;
for(int i = l; i <= min(r, R[belong[l]]); i++)
if(a[i] + add[belong[i]] < c) ans = max(ans, a[i] + add[belong[i]]);
if(belong[l] != belong[r]){
for(int i = L[belong[r]]; i <= r; i++)
if(a[i] + add[belong[i]] < c) ans = max(ans, a[i] + add[belong[i]]);
}
for(int i = belong[l] + ; i < belong[r]; i++){
if(vc[i][] + add[i] >= c) continue;
int k = lower_bound(vc[i].begin(), vc[i].end(), c - add[i]) - vc[i].begin();
ans = max(ans, vc[i][k - ] + add[i]);
}
return ans;
} int main(){
int n;
scanf("%d", &n);
for(int i = ; i <= n; i++) scanf("%d", &a[i]);
build(n);
for(int i = ; i <= n; i++){
int opt, l, r, c;
scanf("%d%d%d%d", &opt, &l, &r, &c);
if(opt == ) modify(l, r, c);
else{
int k = query(l, r, c);
if(k == -INF) printf("-1\n");
else printf("%d\n", k);
}
}
return ;
}

AC代码

LOJ 6279 数列分块入门3的更多相关文章

  1. LOJ #6279. 数列分块入门 3-分块(区间加法、查询区间内小于某个值x的前驱(比其小的最大元素))

    #6279. 数列分块入门 3 内存限制:256 MiB时间限制:1500 ms标准输入输出 题目类型:传统评测方式:文本比较 上传者: hzwer 提交提交记录统计测试数据讨论 3   题目描述 给 ...

  2. LOJ#6279. 数列分块入门 3

    区间加值还是正常的操作,查找前驱的时候用lower_bound查找,然后范围所在位置的值 #include<map> #include<set> #include<cti ...

  3. LOJ——#6277. 数列分块入门 1

    ~~推荐播客~~ 「分块」数列分块入门1 – 9 by hzwer 浅谈基础根号算法——分块 博主蒟蒻,有缘人可直接观摩以上大佬的博客... #6277. 数列分块入门 1 题目大意: 给出一个长为 ...

  4. loj 6278 6279 数列分块入门 2 3

    参考:「分块」数列分块入门1 – 9 by hzwer 2 Description 给出一个长为\(n\)的数列,以及\(n\)个操作,操作涉及区间加法,询问区间内小于某个值\(x\)的元素个数. 思 ...

  5. LOJ #6285. 数列分块入门 9-分块(查询区间的最小众数)

    #6285. 数列分块入门 9 内存限制:256 MiB时间限制:1500 ms标准输入输出 题目类型:传统评测方式:文本比较 上传者: hzwer 提交提交记录统计测试数据讨论 2   题目描述 给 ...

  6. LOJ #6284. 数列分块入门 8-分块(区间查询等于一个数c的元素,并将这个区间的所有元素改为c)

    #6284. 数列分块入门 8 内存限制:256 MiB时间限制:500 ms标准输入输出 题目类型:传统评测方式:文本比较 上传者: hzwer 提交提交记录统计测试数据讨论 2   题目描述 给出 ...

  7. LOJ #6283. 数列分块入门 7-分块(区间乘法、区间加法、单点查询)

    #6283. 数列分块入门 7 内存限制:256 MiB时间限制:500 ms标准输入输出 题目类型:传统评测方式:文本比较 上传者: hzwer 提交提交记录统计测试数据讨论 2   题目描述 给出 ...

  8. LOJ #6282. 数列分块入门 6-分块(单点插入、单点查询、数据随机生成)

    #6282. 数列分块入门 6 内存限制:256 MiB时间限制:500 ms标准输入输出 题目类型:传统评测方式:文本比较 上传者: hzwer 提交提交记录统计测试数据讨论 1   题目描述 给出 ...

  9. LOJ #6281. 数列分块入门 5-分块(区间开方、区间求和)

    #6281. 数列分块入门 5 内存限制:256 MiB时间限制:500 ms标准输入输出 题目类型:传统评测方式:文本比较 上传者: hzwer 提交提交记录统计测试数据讨论 5   题目描述 给出 ...

随机推荐

  1. C++——类与对象

    1.抽象: 是对具体对象(问题)进行概括,抽出这一类对象的公共性质并加以描述的过程. 1.1 先注意问题的本质描述,其次是实现过程和细节: 1.2 数据抽象:描述某类对象的属性或状态(对象相互区别的物 ...

  2. linux异常 - 无法分配内存

    解决方案: 删除虚拟机上不必要的东西 重启开虚拟机的电脑

  3. Wooden Sticks(贪心)

    Wooden Sticks. win the wooden spoon:成为末名. 题目地址:http://poj.org/problem?id=1065 There is a pile of n w ...

  4. C++ 跨dll传递string类型参数执行出错问题

    今天遇到一个问题,在一个dll工程中定义了一个返回值为string,参数为string的函数,然后在一个测试工程中调用,Release模式下一切正常Debug模式下整个函数的执行到return之前都毫 ...

  5. Codeforces Round #610 (Div. 2) A-E简要题解

    contest链接: https://codeforces.com/contest/1282 A. Temporarily unavailable 题意: 给一个区间L,R通有网络,有个点x,在x+r ...

  6. JS高级---总结apply和call方法的使用

    apply和call的使用方法 apply的使用语法   函数名字.apply(对象,[参数1,参数2,...]); 方法名字.apply(对象,[参数1,参数2,...]);   call的使用语法 ...

  7. Tomcat 端口配置,及原理详解

    1 tomcat 文件配置详细说明 tomcat服务器需配置三个端口才能启动,安装时默认启用了这三个端口,当要运行多个tomcat服务时需要修改这三个端口,不能相同.端口配置路径为tomcat\ co ...

  8. appium---webview(H5)元素定位

    我们在做UI自动化的时候,肯定需要元素定位,那么webview(H5)的元素怎么定位呢? webview定位方法 方法一: 1.打开chrome浏览器,输入chrome://inspect 2.连接手 ...

  9. 1.rest之@Get和@Post请求的区别:

    区别: (1)@Get 一般用于查询或获取资源信息, @Post一般是用于更新资源信息. (2)Url不同, @Get 请求的url: http://localhost:8080/imeter-cms ...

  10. 马俊龙ansible教程分享

    ansible详细介绍和教程链接:https://www.cnblogs.com/f-ck-need-u/p/7576137.html#ansible