(有任何问题欢迎留言或私聊 && 欢迎交流讨论哦

Catalog

Problem:Portal传送门

 原题目描述在最下面。

Solution:

 每个节点用一个变量储存它所覆盖区间最少需要加多少次答案能加1.

 如果这次更新不能使答案加1,则更新到lazy标记就可以了,如果能让答案加1,就更新到叶子节点,具体看代码。

AC_Code:

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#include<cctype>
#include<string>
#include<cmath>
#define lson rt<<1
#define rson rt<<1|1
#define all(x) (x).begin(),(x).end()
#define mme(a,b) memset((a),(b),sizeof((a)))
#define fuck(x) cout<<"* "<<x<<"\n"
#define iis std::ios::sync_with_stdio(false)
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
const int MXN = 2e5 + 7;
const int MXE = 1e6 + 7;
const int INF = 0x3f3f3f3f;
int n, m;
int ar[MXN], br[MXN];
struct lp{
int l, r;
int nd, sum, lazy;
}cw[MXN<<2];
void push_up(int rt){
cw[rt].nd = min(cw[lson].nd, cw[rson].nd);
cw[rt].sum = cw[lson].sum + cw[rson].sum;
}
void build(int l,int r,int rt){
cw[rt].l = l; cw[rt].r = r;
cw[rt].sum = cw[rt].lazy = 0;
if(l == r){
cw[rt].nd = br[l];
return;
}
int mid = (l + r)>>1;
build(l,mid,lson);build(mid+1,r,rson);
push_up(rt);
}
void push_down(int rt){
if(cw[rt].lazy){
cw[lson].lazy += cw[rt].lazy;
cw[rson].lazy += cw[rt].lazy;
cw[lson].nd -= cw[rt].lazy;
cw[rson].nd -= cw[rt].lazy;
cw[rt].lazy = 0;
}
}
void update(int L,int R,int l,int r,int rt){
if(L<=l && r<= R){
if(cw[rt].nd <= 1){
if(l == r){
--cw[rt].nd;
if(cw[rt].nd <= 0){
cw[rt].nd = br[l];
cw[rt].sum++;
}
return;
}
}else{
--cw[rt].nd;
++cw[rt].lazy;
return;
}
}
if(l == r)return;
push_down(rt);
int mid = (l+r)>>1;
if(L > mid)update(L,R,mid+1,r,rson);
else if(R <= mid)update(L,R,l,mid,lson);
else {
update(L,mid,l,mid,lson);
update(mid+1,R,mid+1,r,rson);
}
push_up(rt);
}
int query(int L, int R,int l,int r,int rt){
if(L <= l&&r <= R){
return cw[rt].sum;
}
if(l == r)return 0;
push_down(rt);
int mid = (l+r)>>1, ans = 0;
if(L > mid)ans = query(L,R,mid+1,r,rson);
else if(R <= mid)ans = query(L,R,l,mid,lson);
else {
ans = query(L,mid,l,mid,lson);
ans += query(mid+1,R,mid+1,r,rson);
}
return ans;
}
int main(int argc, char const *argv[]){
while(~scanf("%d%d", &n, &m)){
for(int i = 1; i <= n; ++i){
scanf("%d", &br[i]);
}
char op[10];
int a, b;
build(1,n,1);
while(m--){
scanf("%s%d%d", op, &a, &b);
if(op[0] == 'a'){
update(a, b, 1, n, 1);
}else{
printf("%d\n", query(a, b, 1, n, 1));
}
}
}
return 0;
}

####Problem Description:
![这里写图片描述](https://img-blog.csdn.net/20180910205114800)

HDU6315 Naive Operations 线段树的更多相关文章

  1. HDU6315 Naive Operations(线段树 复杂度分析)

    题意 题目链接 Sol 这题关键是注意到题目中的\(b\)是个排列 那么最终的答案最多是\(nlogn\)(调和级数) 设\(d_i\)表示\(i\)号节点还需要加\(d_i\)次才能产生\(1\)的 ...

  2. hdu Naive Operations 线段树

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

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

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

  4. HDU - 6315(2018 Multi-University Training Contest 2) Naive Operations (线段树区间操作)

    http://acm.hdu.edu.cn/showproblem.php?pid=6315 题意 a数组初始全为0,b数组为1-n的一个排列.q次操作,一种操作add给a[l...r]加1,另一种操 ...

  5. HDU 6315 Naive Operations(线段树区间整除区间)

    Problem DescriptionIn a galaxy far, far away, there are two integer sequence a and b of length n.b i ...

  6. HDU - 6315 Naive Operations (线段树+思维) 2018 Multi-University Training Contest 2

    题意:数量为N的序列a和b,a初始全为0,b为给定的1-N的排列.有两种操作:1.将a序列区间[L,R]中的数全部+1:2.查询区间[L,R]中的 ∑⌊ai/bi⌋(向下取整) 分析:对于一个位置i, ...

  7. HDU 6315 Naive Operations(线段树+复杂度均摊)

    发现每次区间加只能加1,最多全局加\(n\)次,这样的话,最后的答案是调和级数为\(nlogn\),我们每当答案加1的时候就单点加,最多加\(nlogn\)次,复杂度可以得当保证. 然后问题就是怎么判 ...

  8. HDU-DuoXiao第二场hdu 6315 Naive Operations 线段树

    hdu 6315 题意:对于一个数列a,初始为0,每个a[ i ]对应一个b[i],只有在这个数字上加了b[i]次后,a[i]才会+1. 有q次操作,一种是个区间加1,一种是查询a的区间和. 思路:线 ...

  9. 2018HDU多校二 -F 题 Naive Operations(线段树)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6315 In a galaxy far, far away, there are two integer ...

随机推荐

  1. JS数组 Array

    1.创建数组 var array=new Array(); 2.添加数组 array.push("111"); array.push("111"); array ...

  2. python3 投票

    import urllib.request # cd C:\Python36-32\Scripts # pip install BeautifulSoup from bs4 import Beauti ...

  3. Android中父View和子view的点击事件的执行过程

    Android中的事件类型分为按键事件和屏幕触摸事件,Touch事件是屏幕触摸事件的基础事件,有必要对它进行深入的了解.  一个最简单的屏幕触摸动作触发了一系列Touch事件:ACTION_DOWN- ...

  4. [bzoj2287]消失之物 题解(背包dp)

    2287: [POJ Challenge]消失之物 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1138  Solved: 654[Submit][ ...

  5. elasticsearch5.5.2安装

     elasticsearch5.x安装中一些问题的解决办法 最近在学习elk,由于编译安装使用5.2.1版本的elasticsearch,所以遇到了很多问题,下面是一些问题及解决办法. 1.修改访问e ...

  6. Servlet源码分析

    Servlet API的核心就是javax.servlet.Servlet接口,所有的Servlet 类(抽象的或者自己写的)都必须实现这个接口.在Servlet接口中定义了5个方法,其中有3个方法是 ...

  7. 洛谷 P4173 残缺的字符串 (FFT)

    题目链接:P4173 残缺的字符串 题意 给定长度为 \(m\) 的模式串和长度为 \(n\) 的目标串,两个串都带有通配符,求所有匹配的位置. 思路 FFT 带有通配符的字符串匹配问题. 设模式串为 ...

  8. Editor REST Client

    Editor REST Client 制作一个http请求 请求行 GET https://example.com/comments/1 HTTP/1.1 POST https://example.c ...

  9. 巧用border属性

    border是常见的css2属性,大家的印象中是不是只是作为边框使用,如下所示: 事实上border,还可以当做图标去使用 我们先来看段代码 <style> .div1{ margin: ...

  10. 【牛客提高训练营5A】同余方程

    题目 吉老师的题做不动啊 首先\([l_1,r_1],[l_2,r_2]\)并不是非常好做,我们考虑将其拆成前缀信息 设\(solve(n,m)=\sum_{i=0}^n\sum_{j=0}^m[m| ...