CF438D The Child and Sequence 线段树
给定数列,区间查询和,区间取模,单点修改。
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 线段树的更多相关文章
- 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 ...
- 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 ...
- 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 ...
- cf250D. The Child and Sequence(线段树 均摊复杂度)
题意 题目链接 单点修改,区间mod,区间和 Sol 如果x > mod ,那么 x % mod < x / 2 证明: 即得易见平凡, 仿照上例显然, 留作习题答案略, 读者自证不难. ...
- CF(438D) The Child and Sequence(线段树)
题意:对数列有三种操作: Print operation l, r. Picks should write down the value of . Modulo operation l, r, x. ...
- CodeForces 438D The Child and Sequence (线段树 暴力)
传送门 题目大意: 给你一个序列,要求在序列上维护三个操作: 1)区间求和 2)区间取模 3)单点修改 这里的操作二很讨厌,取模必须模到叶子节点上,否则跑出来肯定是错的.没有操作二就是线段树水题了. ...
- 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, ...
- 2016暑假多校联合---Rikka with Sequence (线段树)
2016暑假多校联合---Rikka with Sequence (线段树) Problem Description As we know, Rikka is poor at math. Yuta i ...
- [CF438D]The Child and Sequence【线段树】
题目大意 区间取模,区间求和,单点修改. 分析 其实算是一道蛮简单的水题. 首先线段树非常好解决后两个操作,重点在于如何解决区间取模的操作. 一开始想到的是暴力单点修改,但是复杂度就飙到了\(mnlo ...
随机推荐
- Hadoop- Hadoop详解
首先所有知识以官网为准,所有的内容在官网上都有展示,所有的变动与改进,新增内容都以官网为准.hadoop.apache.org Hadoop是一个开源的可拓展的分布式并行处理计算平台,利用服务器集群根 ...
- BZOJ 1041 [HAOI2008]圆上的整点:数学【费马平方和定理】
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1041 题意: 给定n(n <= 2*10^9),问你在圆x^2 + y^2 = n^ ...
- 分享知识-快乐自己:Hibernate 中的 HQL 语句的实际应用
概要: Hibernate 支持三种查询方式: HQL查询.Criteria查询及原声 SQL (Native SQL)查询. HQL(Hibernate Query Language,Hiberna ...
- hdu-5858 Hard problem(数学)
题目链接: Hard problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Othe ...
- Hover show tips
像上面这种效果,hover1时显示2,且1和2有一定间距的东东,一般有两种实现办法: 1.用JS,原理:over1时让2显示,out1时开个定时器延迟500ms再消失,over2时清除定时器,out2 ...
- CRC16算法之一:CRC16-CCITT-FALSE算法的java实现
CRC16算法系列文章: CRC16算法之一:CRC16-CCITT-FALSE算法的java实现 CRC16算法之二:CRC16-CCITT-XMODEM算法的java实现 CRC16算法之三:CR ...
- VirtualBox下安装MacOS11
8.键盘选中 “简体中文” -- > "拼音模式".VirtualBox安装Mac OS 10.11 ,安装日期:2016 / 5 / 14 用虚拟机装黑苹果本人也装了不下3 ...
- 自己实现的vector
#include <iostream> #include <memory> using std::cout; using std::endl; using std::alloc ...
- Mysql源码学习——源码目录结构
目录清单 目录名 注释 Bdb 伯克利DB表引擎 BUILD 构建工程的脚本 Client 客户端 Cmd-line-utils 命令行工具 Config 构建工程所需的一些文件 Dbug Fred ...
- poj1050最大矩阵和——暴力枚举
题目:http://poj.org/problem?id=1050 s[i][j]数组记录以点(i,j)为右下角.(1,1)为左上角的子矩阵内部和: 枚举子矩阵左上角和右下角,取最大值即可. 代码如下 ...