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. 165. Merge Two Sorted Lists【LintCode by java】

    Description Merge two sorted (ascending) linked lists and return it as a new sorted list. The new so ...

  2. MarkDown编辑器使用

    有几款好用的MarkDown编辑器,参考: https://blog.csdn.net/bat67/article/details/72804251 我就下载的是 MarkDown 2来使用. 现用现 ...

  3. Memcache的客户端连接系列(一) Java

    声明:本文并非原创,转自华为云帮助中心的分布式缓存服务(Memcached)的用户指南. 关键词: Memcached  客户端 Java Java连接池 Java客户端示例 用户的弹性云服务器已安装 ...

  4. CryptoZombies学习笔记——Lesson4

    第四课主要介绍payable函数相关. chapter1: payable修饰函数 以太坊允许同时调用函数和eth转账.msg.value显示发送到合约的以太币数,ether是内置整型数.如果函数没有 ...

  5. BZOJ 3166 HEOI2013 ALO 可持久化trie+st表

    题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=3166(洛谷上也有) 题意概述: 给出一个序列,对于一个区间,其权值为区间中的次大值亦或区 ...

  6. “Hello world!”团队—选题展示

    本次选题展示内容: 一.视频展示 链接:http://v.youku.com/v_show/id_XMzA5Mzk5NjYwOA==.html?sharefrom=iphone 视频截图链接:http ...

  7. Thunder团队第五周 - Scrum会议7

    Scrum会议7 小组名称:Thunder 项目名称:i阅app Scrum Master:苗威 工作照片: 参会成员: 王航:http://www.cnblogs.com/wangh013/ 李传康 ...

  8. Swift as as!和as?的区别

    1.as的使用场合 1.从派生类转换为基类,向上转类型(upcasting) class Animal{} class Dog:Animal{} let cat = ANimal() let dog ...

  9. 第四章 持续集成jenkins工具使用之项目配置

    1.1   创建项目 点击“新建”,输入项目名称,选择“构建一个自由风格的软件项目”,点击ok,项目创建完成. 1.2   配置项目 点击步骤1创建的项目,进入项目页面,如图: 点击“配置”,进入配置 ...

  10. asp.net MVC4 @Html.DropDownList的使用

    在MVC4中使用Razor语法,一使用就爱上他了, 一般项目都是有一些增删改查功能,表单下拉框是经常使用的,除了用原始的<select>外,还可以用@Html.DropDownList和@ ...