在一个区间上进行操作,一种操作是某个小区间都加上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. CodeForces Round #550 Div.3

    http://codeforces.com/contest/1144 A. Diverse Strings A string is called diverse if it contains cons ...

  2. 使用ThreadLocal管理Mybatis中SqlSession对象

    转自http://blog.csdn.net/qq_29227939/article/details/52029065 public class MybatisUtil { private stati ...

  3. IdentityServer4【Topic】之登陆注册

    Sign-in 登陆注册 为了让标识服务器(identity server)代表用户发出令牌,该用户必须登录到标识服务器. Cookie authentication Cookie认证 身份验证是由来 ...

  4. 994.Contiguous Array 邻近数组

    描述 Given a binary array, find the maximum length of a contiguous subarray with equal number of 0 and ...

  5. java中级——集合框架【3】-HashSet

    HashSet package cn.jse.hashset; import java.util.HashSet; public class TestCollection { public stati ...

  6. CentOS6.8 安装配置Mysql

    1.下载mysql的repo源 wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm 2.安装mysql-commun ...

  7. elasticsearch介绍,安装,安装错误解决及相应插件安装

    一.elasticsearch介绍 1.简介(使用的是nosql,更新比mongodb慢): ElasticSearch是一个基于Lucene的搜索服务器.它提供了一个分布式多用户能力的全文搜索引擎, ...

  8. ajax查看详细返回信息

    查看详细成功返回信息: success : function(data, textStatus, jqXHR) { console.log(data); console.log(textStatus) ...

  9. vscode git設置

    1.git官网https://git-scm.com/download/win 链接下载:64-bit Git for Windows Setup,不要下载Portable,体积太大了: 如果git官 ...

  10. change safari user agent

    defaults write com.apple.safari customuseragent '"mozilla/5.0 (iphone; cpu iphone os 8_1 like m ...