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. [JSON].toString()

    语法:[JSON].toString() 返回:[String] 说明:获取[JSON]实例的字符串结果 示例: <% jsonString = "{div: 'hello word! ...

  2. 解析Java中final关键字的各种用法

    首先,我们可以从字面上理解一下final这个英文单词的中文含义:“最后的,最终的; 决定性的; 不可更改的:”.显然,final关键词如果用中文来解释,“不可更改的”更为合适.当你在编写程序,可能会遇 ...

  3. anaconda安装scrapy报错解决办法

    今天在用anaconda安装scrapy的时候遇见个坑,现在将解决办法发出来,供大家参考使用: 问题描述: anaconda安装scrapy,使用 conda install scrapy 命令.安装 ...

  4. facebook演讲

    任何为了更大愿景工作的人,可能会被称为疯子,即使你最终获得成功. 任何为了复杂问题工作的人,都会因为不能全面了解挑战而被指责,即使你不可能事先了解一切. 任何抓住主动权先行一步的人,都会因为步子太快而 ...

  5. Struts2中Action各种转发类型

    Struts2:Action中result的各种转发类型: 内部请求转发dispatcher(默认值) redirect.redirectAction.plainText1.redirect是重定向到 ...

  6. ZOJ 3686 A Simple Tree Problem(线段树)

    Description Given a rooted tree, each node has a boolean (0 or 1) labeled on it. Initially, all the ...

  7. Thunder团队第六周 - Scrum会议4

    Scrum会议4 小组名称:Thunder 项目名称:i阅app Scrum Master:胡佑蓉 工作照片: 苗威同学在拍照,所以不在照片内. 参会成员: 王航:http://www.cnblogs ...

  8. Java学习个人备忘录之线程间的通信

    线程间通讯多个线程在处理同一资源,但是任务却不同. class Resource { String name; String sex; } //输入 class Input implements Ru ...

  9. java — 值传递和引用传递

    在 Java 应用程序中永远不会传递对象,而只传递对象引用.因此是按引用传递对象.Java 应用程序按引用传递对象这一事实并不意味着 Java 应用程序按引用传递参数.参数可以是对象引用,而 Java ...

  10. python redis插件安装

    #tar xvzf redis-py-2.2.1.tar.gz #cd redis-py-2.2.1 #python setup.py install   附件: https://app.yinxia ...