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. 【转】一款已上市MMO手游地图同步方案总结

    转自游戏开发主席 1. 客户端地图格子的相关知识 在2.5D的MMO游戏里,角色是通过3D的方式渲染,2D的地图是通过2D的方式显示,所以在客户端一般会有三个坐标系: a) 3D坐标系:所有需要3D渲 ...

  2. python3对接聊天机器人API

    详情见http://api.qingyunke.com/智能机器人API接口说明支持功能:天气.翻译.藏头诗.笑话.歌词.计算.域名信息/备案/收录查询.IP查询.手机号码归属.人工智能聊天接口地址: ...

  3. 从零开始的Python学习Episode 6——字符串操作

    字符串操作 一.输出重复字符串 print('smile'*6) #输出6个smile 二.通过引索输出部分字符串 print('smile'[1:]) print('smile'[1:3]) #输出 ...

  4. php redis和java混用问题

    目前项目是 一个php 一个java  共用一套 redis  key  value 也都一样,  java 使用 gson 解析json   会将php 设置的json里面看  {"a&q ...

  5. python3中使用python2中cmp函数出现错误

    在python2中我们经常会使用cmp函数来比较一些东西,但是在python3中,你再来使用这个函数的时候,发现就报错了,提示找不到这个函数,这是为啥呢? 答:新版的python已经舍弃这种用法 而在 ...

  6. [Data Structures and Algorithms - 1] Introduction & Mathematics

    References: 1. Stanford University CS97SI by Jaehyun Park 2. Introduction to Algorithms 3. Kuangbin' ...

  7. Caused by: java.lang.NoClassDefFoundError: javax/el/ELManager

    出现问题的原因: 在将springboot项目部署到Linux下的Tomcat中,项目无法正常启动(本地能正常运行),Tomcat启动日志中出现: Caused by: java.lang.NoCla ...

  8. Alpha 冲刺4

    队名:日不落战队 安琪(队长) 今天完成的任务 组织第四次站立式会议. 完成40%草稿箱前端界面. 明天的计划 剩下的60%草稿箱前端界面. 如果还有时间,尝试去调用数据. 还剩下的任务 回收站前端界 ...

  9. node必学的Hello World实现--服务器实现

    node是JavaScript运行在后端的一种实现.而后端语言,不管是php,java都需要一个服务器才能跑起来,node如是. node的服务器较php而言,少了单独安装服务器的步骤,node的服务 ...

  10. fcntl函数详解

    功能描述:根据文件描述词来操作文件的特性. 文件控制函数          fcntl -- file control头文件: #include <unistd.h> #include & ...