Problem Description
In a galaxy far, far away, there are two integer sequence a and b of length n.
b is a static permutation of 1 to n. Initially a is filled with zeroes.
There are two kind of operations:
1. add l r: add one for al,al+1...ar

2. query l r: query ∑ri=l⌊ai/bi

 
Input
There are multiple test cases, please read till the end of input file.
For each test case, in the first line, two integers n,q, representing the length of a,b and the number of queries.
In the second line, n integers separated by spaces, representing permutation b.
In the following q lines, each line is either in the form 'add l r' or 'query l r', representing an operation.
1≤n,q≤100000

, 1≤l≤r≤n

, there're no more than 5 test cases.

 
Output
Output the answer for each 'query', each one line.
 
Sample Input
5 12
1 5 2 4 3
add 1 4
query 1 4
add 2 5
query 2 5
add 3 5
query 1 5
add 2 4
query 1 4
add 2 5
query 2 5
add 2 2
query 1 5
 
Sample Output
1
1
2
4
4
6
 
这题写不出的我不敢说话,
线段树上线段果,线段树上你和我!
我都要自挂线段树了
 求query ∑ri=l⌊ai/bi 
  这个就要转化一下模型
以为向下取整 所以一开始ai=0  
所以可以每次add操作就相当于bi--
当bi等于0的时候 sum++;然后bi变回最开始的值
构造一个线段树维护区间最小值和sum
 
 #include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 1e5 + ;
int n,m,a[maxn];
struct node {
LL val, key, lazy, sum;
} tree[maxn << ];
void pushup(int rt) {
tree[rt].sum = tree[rt << ].sum + tree[rt << | ].sum;
tree[rt].val = min(tree[rt << ].val, tree[rt << | ].val);
}
void pushdown(int rt) {
tree[rt << ].lazy += tree[rt].lazy;
tree[rt << | ].lazy += tree[rt].lazy;
tree[rt << ].val -= tree[rt].lazy;
tree[rt << | ].val -= tree[rt].lazy;
tree[rt].lazy = ;
}
void build(int l, int r, int rt) {
tree[rt].lazy = tree[rt].sum = ;
if (l == r) {
tree[rt].key = tree[rt].val = a[l];
return ;
}
int m = (l + r) >> ;
build(l, m, rt << );
build(m + , r, rt << | );
pushup(rt);
}
void update(int L, int R, int l, int r, int rt) {
if(l > r) return ;
if (tree[rt].val > && l == L && r == R) {
tree[rt].val--;
tree[rt].lazy++;
return ;
}
if (tree[rt].val == && l == r) {
tree[rt].sum++;
tree[rt].val = tree[rt].key;
tree[rt].lazy = ;
return ;
}
if (tree[rt].lazy > ) pushdown(rt);
int m = (l + r) >> ;
if (R <= m) update(L, R, l, m, rt << );
else if (L > m) update(L, R, m + , r, rt << | );
else {
update(L, m, l, m, rt << );
update(m + , R, m + , r, rt << | );
}
pushup(rt);
}
LL query(int L, int R, int l, int r, int rt) {
if(l > r) return ;
if (l == L && r == R) return tree[rt].sum;
int m = (l + r) >> ;
if (R <= m) return query(L, R, l, m, rt << );
else if (L > m) return query(L, R, m + , r, rt << | );
else return query(L, m, l, m, rt << ) + query(m + , R, m + , r, rt << | );
}
int main() {
while(scanf("%d%d", &n, &m) != EOF) {
for (int i = ; i <= n ; i++ ) scanf("%d", &a[i]);
build(, n, );
char str[];
int x, y;
while(m--) {
scanf("%s%d%d", str, &x, &y);
if (str[] == 'a') update(x, y, , n, );
else printf("%lld\n", query(x, y, , n, ));
}
}
return ;
}
 

Naive Operations HDU多校(线段树上线段果)的更多相关文章

  1. HDU6315 Naive Operations(多校第二场1007)(线段树)

    Naive Operations Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 502768/502768 K (Java/Other ...

  2. HDU-6315 Naive Operations//2018 Multi-University Training Contest 2___1007 (线段树,区间除法)

    原题地址 Naive Operations Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 502768/502768 K (Java/ ...

  3. CodeForces121E 线段树上线段果

    http://codeforces.com/problemset/problem/121/E 题意: Petya 喜欢幸运数,幸运数只包含 4 和 7 这两个数字.例如 47,744,4 都是幸运数字 ...

  4. HDU6602 Longest Subarray hdu多校第二场 线段树

    HDU6602 Longest Subarray 线段树 传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6602 题意: 给你一段区间,让你求最长的区间使 ...

  5. 杭电多校第二场 hdu 6315 Naive Operations 线段树变形

    Naive Operations Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 502768/502768 K (Java/Other ...

  6. HDU 6351 Naive Operations(线段树)

    题目: http://acm.hdu.edu.cn/showproblem.php?pid=6315 Naive Operations Time Limit: 6000/3000 MS (Java/O ...

  7. hdu Naive Operations 线段树

    题目大意 题目链接Naive Operations 题目大意: 区间加1(在a数组中) 区间求ai/bi的和 ai初值全部为0,bi给出,且为n的排列,多组数据(<=5),n,q<=1e5 ...

  8. HDU 多校对抗 F Naive Operations

    Naive Operations Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 502768/502768 K (Java/Other ...

  9. hdu 5930 GCD 线段树上二分/ 强行合并维护信息

    from NOIP2016模拟题28 题目大意 n个点的序列,权值\(<=10^6\) q个操作 1.单点修改 2.求所有区间gcd中,不同数个数 分析 1.以一个点为端点,向左或向右的gcd种 ...

随机推荐

  1. JAVA基础学习之路(四)定义简单java类

    简单java类开发一般原则: 类名称必须有意义,再怎么说,要让人家看的明白吧 类之中所有属性必须使用private封装,并提供setter,getter方法 类之中可以有多个构造方法,但是必须保留有一 ...

  2. 数据库Mysql的学习(一)-启动和进入

    数据库:按照数据结构来组织储存和管理数据的仓库. Mysql是关系型数据库管理系统 Mysql安装好之后... mysql的启动 1:通过控制面板里的”服务“找到mysql右键启动即可 2:开始菜单搜 ...

  3. JavaScript 之 对象/JSON/数组

    对象 简单说,所谓对象,就是一种无序的数据集合,由若干个“键值对”(key-value)构成. var obj = { p: 'Hello World' }; 上面代码中,大括号就定义了一个对象,它被 ...

  4. Python入门(3)

    一.列表 列表是用来储存和处理多个数据的数据类型,我们可以像下面这样来创建一个列表: my_list = [1, 2, 3] 列表和数学中的集合很像,但是,列表中的数据是可以重复,并且他们是有序的,列 ...

  5. 洛谷 P1706 全排列问题 :STL / dfs

    题目描述 输出自然数1到n所有不重复的排列,即n的全排列,要求所产生的任一数字序列中不允许出现重复的数字. 输入输出格式 输入格式: n(1≤n≤9) 输出格式: 由1-n组成的所有不重复的数字序列, ...

  6. LeetCode - 566. Reshape the Matrix (C++) O(n)

    1. 题目大意 根据给定矩阵,重塑一个矩阵,r是所求矩阵的行数,c是所求矩阵的列数.如果给定矩阵和所求矩阵的数据个数不一样,那么返回原矩阵.否则,重塑矩阵.其中两个矩阵中的数据顺序不变(先行后列). ...

  7. leetcode个人题解——#20 Valid Parentheses

    class Solution { public: bool isValid(string s) { stack<char> brackts; ; i < s.size(); i++) ...

  8. 【web前端开发】浏览器兼容性处理大全

    1.居中问题 div里的内容,IE默认为居中,而FF默认为左对齐,可以尝试增加代码margin: 0 auto; 2.高度问题 两上下排列或嵌套的div,上面的div设置高度(height),如果di ...

  9. NFS服务搭建使用

    需求:由于线上业务有一些数据存在了Redis数据库和mysql数据库中了,导致了数据较大迁移起来比较麻烦,所以准备搭建NFS来做WEB的共享磁盘,存储这些数据. 服务端搭建: 查看本机关于nfs的包 ...

  10. javaIO--字节流

    流---是指的一组有序的.有气垫和重点的字节集合,是对的护具传输的总称或者抽象. 流采用缓冲区技术,当写一个数据时,系统将数据发送到缓冲区而不是外部设备(如硬盘),当读一个数据时,系统实际是从缓冲区读 ...