给定数列,区间查询和,区间取模,单点修改。

n,m小于10^5

。。。当区间最值小于模数时,就直接返回就好啦~

#include<cstdio>
#include<iostream>
#define R register int
#define ls (tr<<1)
#define rs (tr<<1|1)
using namespace std;
inline long long g() {
register long long ret=,fix=; register char ch; while(!isdigit(ch=getchar())) fix=ch=='-'?-:fix;
do ret=ret*+(ch^); while(isdigit(ch=getchar())); return ret*fix;
}
int n,m,M;
long long sum[],mx[],cnt[];
inline void upd(int tr) {sum[tr]=sum[ls]+sum[rs]; mx[tr]=max(mx[ls],mx[rs]);}
inline void build(int tr,int l,int r) {
if(l==r) {mx[tr]=sum[tr]=g(); return ;}
R md=(l+r)>>; build(ls,l,md),build(rs,md+,r); upd(tr);
}
inline void chg(int tr,int l,int r,int pos,int x) {
if(l==r) {sum[tr]=mx[tr]=x; return ;} R md=(l+r)>>;
if(pos>md) chg(rs,md+,r,pos,x);
else chg(ls,l,md,pos,x); upd(tr);
}
inline void change(int tr,int l,int r,int LL,int RR) {
if(mx[tr]<M) return ;
if(l==r) {mx[tr]=sum[tr]=sum[tr]%M; return ;}
R md=(l+r)>>;
if(LL>md) change(rs,md+,r,LL,RR);
else if(RR<md+) change(ls,l,md,LL,RR);
else change(ls,l,md,LL,md),change(rs,md+,r,md+,RR); upd(tr);
}
inline long long query(int tr,int l,int r,int LL,int RR) {
if(l==LL&&r==RR) return sum[tr];
R md=(l+r)>>;
if(LL>md) return query(rs,md+,r,LL,RR);
else if(RR<md+) return query(ls,l,md,LL,RR);
else return query(ls,l,md,LL,md)+query(rs,md+,r,md+,RR);
}
signed main() {
n=g(),m=g(); build(,,n);
for(R i=,k,l,r;i<=m;++i) {
k=g(),l=g(),r=g();
if(k==) printf("%lld\n",query(,,n,l,r));
else if(k==) M=g(),change(,,n,l,r);
else chg(,,n,l,r);
}
}

2019.04.18

CF438D The Child and Sequence 线段树的更多相关文章

  1. Codeforces Round #250 (Div. 1) D. The Child and Sequence 线段树 区间取摸

    D. The Child and Sequence Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest ...

  2. Codeforces 438D The Child and Sequence - 线段树

    At the children's day, the child came to Picks's house, and messed his house up. Picks was angry at ...

  3. Codeforces Round #250 (Div. 1) D. The Child and Sequence 线段树 区间求和+点修改+区间取模

    D. The Child and Sequence   At the children's day, the child came to Picks's house, and messed his h ...

  4. cf250D. The Child and Sequence(线段树 均摊复杂度)

    题意 题目链接 单点修改,区间mod,区间和 Sol 如果x > mod ,那么 x % mod < x / 2 证明: 即得易见平凡, 仿照上例显然, 留作习题答案略, 读者自证不难. ...

  5. CF(438D) The Child and Sequence(线段树)

    题意:对数列有三种操作: Print operation l, r. Picks should write down the value of . Modulo operation l, r, x. ...

  6. CodeForces 438D The Child and Sequence (线段树 暴力)

    传送门 题目大意: 给你一个序列,要求在序列上维护三个操作: 1)区间求和 2)区间取模 3)单点修改 这里的操作二很讨厌,取模必须模到叶子节点上,否则跑出来肯定是错的.没有操作二就是线段树水题了. ...

  7. Codeforces Round #250 (Div. 1) D. The Child and Sequence (线段树)

    题目链接:http://codeforces.com/problemset/problem/438/D 给你n个数,m个操作,1操作是查询l到r之间的和,2操作是将l到r之间大于等于x的数xor于x, ...

  8. 2016暑假多校联合---Rikka with Sequence (线段树)

    2016暑假多校联合---Rikka with Sequence (线段树) Problem Description As we know, Rikka is poor at math. Yuta i ...

  9. [CF438D]The Child and Sequence【线段树】

    题目大意 区间取模,区间求和,单点修改. 分析 其实算是一道蛮简单的水题. 首先线段树非常好解决后两个操作,重点在于如何解决区间取模的操作. 一开始想到的是暴力单点修改,但是复杂度就飙到了\(mnlo ...

随机推荐

  1. 在eclipse创建Maven工程修改默认JRE

    1. 打开Maven安装目录的setting.xml文件 2.找到profiles标签 3.加入下面配置即可 <profile>    <id>jdk-1.8</id&g ...

  2. linux 使用总结

    shell 简单的实现守护进程 单纯的使用 &命令 + ctrl+D退出终端 原理: 关闭终端有两种方式,一种是点叉,这时候,你关闭的是gnome-terminal这个进程,而Bash是它的子 ...

  3. 设置可见GPU方式

    只可见第一块GPU os.environ["CUDA_VISIBLE_DEVICES"] = "0"

  4. The Review Plan I-禁位排列和容斥原理

    The Review Plan I Time Limit: 5000ms Case Time Limit: 5000ms Memory Limit: 65536KB   64-bit integer ...

  5. RT-Thread信号量使用(动态/静态信号量) 及 信号量的四种使用场合

    信号量(Semaphore),有时被称为信号灯,是在多线程环境下使用的一种设施,是可以用来保证两个或多个关键代码段不被并发调用.在进入一个关键代码段之前,线程必须获取一个信号量:一旦该关键代码段完成了 ...

  6. POCO库中文编程参考指南(8)丰富的Socket编程

    POCO库中文编程参考指南(8)丰富的Socket编程 作者:柳大·Poechant 博客:Blog.CSDN.net/Poechant 邮箱:zhongchao.ustc#gmail.com (# ...

  7. Getting Started with OpenMP

    Getting Started with OpenMP* Abstract As you probably know by now, to get the maximum performance be ...

  8. appium连真机问题

    adb devices -l 后出现:List of devices attached 解决方法:用管理员身份运行以上命令 adb kill-server adb start-server adb d ...

  9. 细说ASP.NET Forms身份认证 别人写的不过很透彻就转来了以后用时再看

    阅读目录 开始 ASP.NET身份认证基础 ASP.NET身份认证过程 如何实现登录与注销 保护受限制的页面 登录页不能正常显示的问题 认识Forms身份认证 理解Forms身份认证 实现自定义的身份 ...

  10. hadoop版本与支持的hbase版本对照…

    hadoop版本与支持的hbase版本对照表 分类: hbase2013-05-20 17:19 701人阅读 评论(2) 收藏 举报 HbaseHadoop As of Hive 0.9.0 the ...