【codeforces 438D】The Child and Sequence
【原题题面】传送门
【大致题意】
- 给定一个长度为n的非负整数序列a,你需要支持以下操作:
- 1:给定l,r,输出a[l]+a[l+1]+…+a[r]。
- 2:给定l,r,x,将a[l],a[l+1],…,a[r]对x取模。
- 3:给定k,y,将a[k]修改为y。
【数据范围】
n,m<=100000,a[i],x,y<=109。
【题解大意】
维护最大值和区间和,然后通过最大值有没有超过x来判断需不需要取模操作。
【code】
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define rep(k,i,j) for(int k = i;k <= j; ++k)
#define FOR(k,i,j) for(int k = i;k >= j; --k)
inline int read(){
int x=,f=; char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-; ch=getchar();}
while(ch>=''&&ch<=''){x=(x<<)+(x<<)+ch-''; ch=getchar();}
return x*f;
}
#define ls rt<<1
#define rs rt<<1|1
const int mxn = 1e5+;
struct T {ll s;int mx;} tr[mxn<<];
int a[mxn],n,q;
inline void build(int rt,int l,int r){
if(l==r){
tr[rt].s = tr[rt].mx = a[l];
return;
}
int m = l+r >>;
build(ls,l,m),build(rs,m+,r);
tr[rt].s = tr[ls].s + tr[rs].s;
tr[rt].mx = max(tr[ls].mx,tr[rs].mx);
}
inline void update(int rt,int l,int r,int lp,int rp,int x){
if(tr[rt].mx < x) return;
if(lp==rp){
tr[rt].s = tr[rt].mx %= x;
return;
}
int m = lp+rp >>;
if(l<=m) update(ls,l,r,lp,m,x);
if(r>m) update(rs,l,r,m+,rp,x);
tr[rt].s = tr[ls].s + tr[rs].s;
tr[rt].mx = max(tr[ls].mx,tr[rs].mx);
}
inline void update1(int rt,int lp,int rp,int k,int y){
if(lp==rp){
tr[rt].s = tr[rt].mx = y;
return;
}
int m = lp+rp >>;
if(k<=m) update1(ls,lp,m,k,y);
else update1(rs,m+,rp,k,y);
tr[rt].s = tr[ls].s + tr[rs].s;
tr[rt].mx = max(tr[ls].mx,tr[rs].mx);
}
inline ll query(int rt,int lp,int rp,int l,int r){
if(l<=lp&&rp<=r) {return tr[rt].s;}
int m = lp+rp >>;
ll ans = ;
if(l<=m) ans += query(ls,lp,m,l,r);
if(r>m) ans += query(rs,m+,rp,l,r);
return ans;
}
int main(){
n = read(),q = read();
rep(i,,n) a[i] = read();
build(,,n);
while(q--){
int opt = read();
if(opt==){
int l = read(),r = read();
printf("%lld\n",query(,,n,l,r));
}
if(opt==){
int l = read(),r = read(),x = read();
update(,l,r,,n,x);
}
if(opt==){
int k = read(),y = read();
update1(,,n,k,y);
}
}
return ;
}
【调试中出过的错】
1.关于小于号和小于等于
2.关于l与lp(r与rp)的大小
【codeforces 438D】The Child and Sequence的更多相关文章
- 【47.40%】【codeforces 743B】Chloe and the sequence
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【 CodeForces - 392C】 Yet Another Number Sequence (二项式展开+矩阵加速)
Yet Another Number Sequence Description Everyone knows what the Fibonacci sequence is. This sequence ...
- 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 3D】Least Cost Bracket Sequence
Codeforces 3 D 题意:有一个括号序列,其中一些位置是问号,把第\(i\)个问号改成(需要\(a_i\)的代价,把它改成)需要\(b_i\)的代价. 问使得这个括号序列成立所需要的最小代价 ...
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【codeforces 466D】Increase Sequence
[题目链接]:http://codeforces.com/problemset/problem/466/D [题意] 给你n个数字; 让你选择若干个区间; 且这些区间[li,ri]; 左端点不能一样; ...
- 【codeforces 602D】Lipshitz Sequence
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【66.47%】【codeforces 556B】Case of Fake Numbers
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【35.29%】【codeforces 557C】Arthur and Table
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
随机推荐
- eolinker使用初体验(一)
1.官网 https://www.eolinker.com 2.安装测试增强插件,由于chrome安装的时候有问题,建议移步firefox浏览器,不纠结.. 3.新建一个单例测试
- python 判断字符串是否为(或包含)IP地址
下面是某个字符串是否为IP地址import re def isIP(str): p = re.compile('^((25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(25[0-5 ...
- msmq访问格式
//集群测试,以下格式不行(应是Host映射之类没配置OK) //_MSMQPath = @"FormatName:DIRECT=TCP:msmq496-ha\private$\496-10 ...
- 2016(5)系统设计,web应用
试题五(共25分) 阅读以下关于Web应用的叙述,在答题纸上回答问题1至问题3. 某软件企业拟开发一套基于Web的云平台配置管理与监控系统,该系统按租户视图.系统管理视图以及业务视图划分为多个相应的W ...
- 浏览器User-Agent大全
what's the User-Agent UserAgent中文名为用户代理,是Http协议中的一部分,属于头域的组成部分,UserAgent也简称UA.它是一个特殊字符串头,是一种向访问网站提供你 ...
- tensorflow-用DASC结合Inception-v3对imagenet2012聚类实现
一.目的 以imagenet2012作为数据集,用Inception-v3对图像提取特征作为输入,来训练一个自编码器. 以上作为预训练模型,随后在该自编码器的基础上,中间加入一个自表示层,将最终学习到 ...
- [py]pandas数据统计学习
pandas.core.base.DataError: No numeric types to aggregate错误规避 我没有去解决这个问题, 而用填充0规避了这个问题 统计 聚合 d = [ { ...
- Python第3次作业--李珠霞
习题1: **1.初始化一个数据集,包括5-10位同学的成绩数据(数据类型不限),数据格式如下: **学号 姓名 Java C语言 Python2017XXXX 小白 87 68 922017XXXX ...
- 捕鱼达人Demo版下载
链接:https://pan.baidu.com/s/1ihHhikpFXiNJMxa26E8qBw 提取码:npj6
- WPF中使用DataGrid时操作列按钮问题
在使用DataGrid的过程中,我们有时候需要对选取的某一行数据进行多个操作,这个时候操作列只有一个按钮显然无法满足我们的要求,我们需要多个按钮才能达到我们的目的. UI页面代码: <Grid& ...