在一个区间上进行操作,一种操作是某个小区间都加上c,另一个查找这个区间内大于c*c的数

我们可以另外开一个数组在保存a中的每个分块内的相对值,然后每次对a加值,并把a的值赋给b,不同的是b内的各个分块需要进行排序,然后通过二分找区间的整块内的小于c*c的值,如果是在区间的边上,不是一个整块,那就直接暴力搜一下

#include<map>
#include<set>
#include<ctime>
#include<cmath>
#include<stack>
#include<queue>
#include<string>
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define first fi
#define second se
#define lowbit(x) (x & (-x)) typedef unsigned long long int ull;
typedef long long int ll;
const double pi = 4.0*atan(1.0);
const int inf = 0x3f3f3f3f;
const int maxn = ;
const int maxm = ;
using namespace std; int n, m, tol, T;
int block;
int bel[maxn];
int a[maxn];
int b[maxn];
int add[maxn]; void init() {
memset(a, , sizeof a);
memset(add, , sizeof add);
memset(bel, , sizeof bel);
} void sor(int x) {
for(int i=(x-)*block+; i<=min(x * block, n); i++) {
a[i] += add[x];
b[i] = a[i];
}
// printf("%d %d\n", (x-1)*block+1, b+min(x * block, n)+1);
sort(b+(x-)*block+, b+min(x * block, n)+);
add[x] = ;
} void update(int l, int r, int c) {
for(int i=l; i<=min(r, bel[l]*block); i++) a[i] += c;
sor(bel[l]);
if(bel[l] == bel[r]) return ;
if(bel[l] != bel[r]) {
for(int i=(bel[r]-) * block+; i<=r; i++) a[i] += c;
sor(bel[r]);
}
for(int i=bel[l]+; i<bel[r]; i++) add[i] += c;
} int query(int l, int r, int c) {
int ans = ;
for(int i=l; i<=min(r, bel[l] * block); i++)
if(a[i] + add[bel[i]] < c) ans++;
if(bel[l] == bel[r]) return ans;
if(bel[l] != bel[r])
for(int i=(bel[r]-)*block+; i<=r; i++)
if(a[i] + add[bel[i]] < c) ans++;
for(int i=bel[l]+; i<bel[r]; i++)
ans += lower_bound(b+(i-)*block+, b+min(n, i*block+), c - add[i]) - (b + (i-)*block+);
return ans;
} int main() {
while(~scanf("%d", &n)) {
init();
block = sqrt(n);
int num = n / block;
if(n % block) num++;
for(int i=; i<=n; i++) {
scanf("%d", &a[i]);
bel[i] = (i-) / block + ;
}
for(int i=; i<=num; i++)
sor(i);
// for(int i=1; i<=n; i++) printf("%d%c", a[i], i==n ? '\n' : ' ');
m = n;
while(m--) {
int op, l, r, c;
scanf("%d%d%d%d", &op, &l, &r, &c);
if(op == ) {
update(l, r, c);
// for(int i=1; i<=n; i++) printf("%d%c", a[i], i==n ? '\n' : ' ');
} else {
int ans = query(l, r, c*c);
printf("%d\n", ans);
}
}
}
return ;
}

LOJ#6278. 数列分块入门 2的更多相关文章

  1. LOJ #6278. 数列分块入门 2-分块(区间加法、查询区间内小于某个值x的元素个数)

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

  2. LOJ 6278 数列分块入门2

    [题解] 分块.块内排序.块内二分出第一个大于等于c的数. #include<cstdio> #include<algorithm> #include<cmath> ...

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

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

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

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

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

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

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

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

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

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

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

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

  9. LOJ #6280. 数列分块入门 4-分块(区间加法、区间求和)

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

随机推荐

  1. nginx 1.4.3能直接升到1.8.1吗

    nginx 1.4.3能直接升到1.8.1吗_百度知道https://zhidao.baidu.com/question/564529441847261484.html nginx-1.6.3平滑升级 ...

  2. opencv2\flann\matrix.h(69): error C2059: 语法错误:“,”

    在提示错误的matrix.h头文件中,修改一下,在free前加上_ ,即FLANN_DEPRECATED void _free() .

  3. C#设计模式之8:外观模式

    外观模式 外观模式和适配器模式一样,都实现了接口改变,适配器模式是让一个接口转化成另外一个接口,而外观模式是让接口变得更简单. 先来看一下需求: 外观模式没有封装子系统的类,外观只是提供一个统一的接口 ...

  4. [转帖]前端-chromeF12 谷歌开发者工具详解 Console篇

    前端-chromeF12 谷歌开发者工具详解 Console篇 https://blog.csdn.net/qq_39892932/article/details/82655866 趁着搞 cloud ...

  5. [转帖]NUMA

    作者:ibless 来源:CSDN 原文:https://blog.csdn.net/ibless/article/details/80114009 其实 很早之前对这一块有了解 比较多的的是 CCN ...

  6. 日期选择器date、week、time、datetime、datetime-local类型

    下面只写两个类型的代码案例,其他都大同小异 date类型: <!DOCTYPE html> <html> <head> <meta charset=" ...

  7. MySqlHelper的封装

    其实MySqlHelper和SqlHelper是一样的,只是使用的驱动不一样而已. public class MySQLHelper { public static final String url ...

  8. Java 线程的生命周期

    当线程被创建并启动以后,它既不是一启动就进入了执行状态,也不是一直处于执行状态,在线程的生命周期中,它要经过新建(New).就绪(Runnable).运行(Running).阻塞(Blocked)和死 ...

  9. python爬虫scrapy的LinkExtractor

    使用背景: 我们通常在爬去某个网站的时候都是爬去每个标签下的某些内容,往往一个网站的主页后面会包含很多物品或者信息的详细的内容,我们只提取某个大标签下的某些内容的话,会显的效率较低,大部分网站的都是按 ...

  10. git连接到github

    基本流程如图 如何配置SSH key:在gitBash里执行. 1.检查电脑上是否生成过了,如果已经生成了,则需要删除后再操作 cd ~ cd .ssh 提示:No such file or dire ...