传送门

线段树基本操作。

给出一个排列b,有一个初始值都为0的数组a,维护区间加1,区间统计区间∑(ai/bi)" role="presentation" style="position: relative;">(ai/bi)(ai/bi)。

我们维护当前所有的ai" role="presentation" style="position: relative;">aiai%bi" role="presentation" style="position: relative;">bibi与bi" role="presentation" style="position: relative;">bibi差量的最小值,这样就把第一个操作变成了区间减法。

如果当前区间的差量最小值是大于1" role="presentation" style="position: relative;">11的,说明在这次减法过后整个区间对答案不会有新的贡献,直接打上标记。

否则我们递归到叶子结点,重新赋值差量并统计对答案的贡献,整个东西开个树状数组记录就好。

代码:

#include<bits/stdc++.h>
#define lc (p<<1)
#define rc (p<<1|1)
#define mid (T[p].l+T[p].r>>1)
#define N 100005
using namespace std;
int n,m,b[N],bit[N],ll,rr;
struct Node{int l,r,mn,add;}T[N<<2];
inline int min(int a,int b){return a<b?a:b;}
inline void pushup(int p){T[p].mn=min(T[lc].mn,T[rc].mn);}
inline void pushnow(int p,int v){T[p].mn-=v,T[p].add+=v;}
inline void pushdown(int p){pushnow(lc,T[p].add),pushnow(rc,T[p].add),T[p].add=0;}
inline int lowbit(int x){return x&-x;}
inline void modify(int p){for(int i=p;i<=n;i+=lowbit(i))++bit[i];}
inline void build(int p,int l,int r){
    T[p].l=l,T[p].r=r,T[p].add=0;
    if(l==r){scanf("%d",&b[l]),T[p].mn=b[l];return;}
    build(lc,l,mid),build(rc,mid+1,r),pushup(p);
}
inline void update(int p,int ql,int qr){
    if(ql>T[p].r||qr<T[p].l)return;
    if(ql<=T[p].l&&T[p].r<=qr&&T[p].mn>1)return pushnow(p,1);
    if(T[p].l==T[p].r){T[p].mn=b[T[p].l];return modify(T[p].l);}
    pushdown(p);
    if(qr<=mid)update(lc,ql,qr);
    else if(ql>mid)update(rc,ql,qr);
    else update(lc,ql,mid),update(rc,mid+1,qr);
    pushup(p);
}
inline int query(int p){int ans=0;for(int i=p;i;i-=lowbit(i))ans+=bit[i];return ans;}
int main(){
    freopen("eta.in","r",stdin),freopen("eta.out","w",stdout),scanf("%d%d",&n,&m),build(1,1,n);
    while(m--){
        char s[10];
        scanf("%s%d%d",s,&ll,&rr);
        if(s[0]=='a')update(1,ll,rr);
        else printf("%d\n",query(rr)-query(ll-1));
    }
    return 0;
}

2018.07.31cogs2964. 数列操作η(线段树)的更多相关文章

  1. COGS 2638. 数列操作ψ 线段树

    传送门 : COGS 2638. 数列操作ψ 线段树 这道题让我们维护区间最大值,以及维护区间and,or一个数 我们考虑用线段树进行维护,这时候我们就要用到吉司机线段树啦 QAQ 由于发现若干次an ...

  2. 2018.07.22 codeforces750E(线段树维护状态转移)

    传送门 给出一个数字字串,给出若干个询问,询问在字串的一段区间保证出现2017" role="presentation" style="position: re ...

  3. 【COGS-2638】数列操作ψ 线段树

    题目链接: http://cogs.pro/cogs/problem/problem.php?pid=2638 Solution 用jry推荐的写法即可做到单次$O(log^{2}N)$,不过随机数据 ...

  4. BZOJ_4636_蒟蒻的数列_线段树+动态开点

    BZOJ_4636_蒟蒻的数列_线段树+动态开点 Description 蒟蒻DCrusher不仅喜欢玩扑克,还喜欢研究数列 题目描述 DCrusher有一个数列,初始值均为0,他进行N次操作,每次将 ...

  5. 【题解】P4247 [清华集训]序列操作(线段树修改DP)

    [题解]P4247 [清华集训]序列操作(线段树修改DP) 一道神仙数据结构(DP)题. 题目大意 给定你一个序列,会区间加和区间变相反数,要你支持查询一段区间内任意选择\(c\)个数乘起来的和.对1 ...

  6. 2018.07.28 uoj#169. 【UR #11】元旦老人与数列(线段树)

    传送门 线段树好题. 维护区间加,区间取最大值,维护区间最小值,历史区间最小值. 同样先考虑不用维护历史区间最小值的情况,这个可以参考这道题的解法,维护区间最小和次小值可以解决前两个操作,然后使用历史 ...

  7. 洛谷P1438 无聊的数列 [zkw线段树]

    题目传送门 无聊的数列 题目背景 无聊的YYB总喜欢搞出一些正常人无法搞出的东西.有一天,无聊的YYB想出了一道无聊的题:无聊的数列...(K峰:这题不是傻X题吗) 题目描述 维护一个数列{a[i]} ...

  8. 【bzoj4636】蒟蒻的数列 离散化+线段树

    原文地址:http://www.cnblogs.com/GXZlegend/p/6801379.html 题目描述 蒟蒻DCrusher不仅喜欢玩扑克,还喜欢研究数列 题目描述 DCrusher有一个 ...

  9. [bzoj4636]蒟蒻的数列_线段树

    蒟蒻的数列 bzoj-4636 题目大意:给定一个序列,初始均为0.n次操作:每次讲一段区间中小于k的数都变成k.操作的最后询问全局和. 注释:$1\le n\le 4\cdot 10^4$. 想法: ...

随机推荐

  1. RAD 10 C++Builder的bug

    C++Builder的bug 修改一行代码,F9会报错.要clear工程重新完整编译才可以. 新建空白工程是好的. restart computer ok!!! 2)fdquery like this ...

  2. VBA 浏览文件夹

    Private Function SelectFolder() As String        With Application.FileDialog(msoFileDialogFolderPick ...

  3. linux中与Oracle有关的内核参数详解

    工作当中遇到oracle运行时CPU占用率达到90%以上,调小以下参数值后恢复正常. fs.file-max = 65536 net.core.rmem_default=262144 net.core ...

  4. Can not find the tag library descriptor for "http://www.springframework.org/tags"

    1.Download the Spring dependency jar2.Place it to the lib folder path is /WEB-INF/lib/spring.jar 3.T ...

  5. How to Pronounce the word BECAUSE

    How to Pronounce the word BECAUSE Share Tweet Share Tagged With: BECAUSE Reduction Study the BECAUSE ...

  6. SpringCloud之Eureka 服务注册和服务发现基础篇2

    上篇文章讲解了SpringCloud组件和概念介绍,接下来讲解一下SpringCloud组件相关组件使用.原理和每个组件的作用的,它主要提供的模块包括:服务发现(Eureka),断路器(Hystrix ...

  7. URL转义字符

    [URL转义字符] 参考:http://www.cnblogs.com/jiunadianshi/articles/2353968.html

  8. 使用JS伪造Post请求

    [使用JS伪造Post请求] 提到伪造Post请求,首先想到的是构造HTTP包.但实际上有一种更简单的方法,构造HTML FORM表单,使用js进行提交.如下:

  9. 读《asp.net MVC4开发指南(黄保翕编著)》笔记

    在刚刚过去的中秋节中,利用了两天的碎片时间把黄保翕编著的<asp.net MVC4 开发指南>看了遍,笔记如下,欢饮在开发MVC的同学一起来探讨: 1.社区 2.开源程序 3.易测试性 4 ...

  10. C#中获取串口与并口列表

    //获取系统中的串口并加入到下拉框中 cbCashBoxPort.Items.Clear(); string[] ports = System.IO.Ports.SerialPort.GetPortN ...