【原题题面】传送门

【大致题意】

  • 给定一个长度为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的更多相关文章

  1. 【47.40%】【codeforces 743B】Chloe and the sequence

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  2. 【 CodeForces - 392C】 Yet Another Number Sequence (二项式展开+矩阵加速)

    Yet Another Number Sequence Description Everyone knows what the Fibonacci sequence is. This sequence ...

  3. 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 ...

  4. 【Codeforces 3D】Least Cost Bracket Sequence

    Codeforces 3 D 题意:有一个括号序列,其中一些位置是问号,把第\(i\)个问号改成(需要\(a_i\)的代价,把它改成)需要\(b_i\)的代价. 问使得这个括号序列成立所需要的最小代价 ...

  5. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  6. 【codeforces 466D】Increase Sequence

    [题目链接]:http://codeforces.com/problemset/problem/466/D [题意] 给你n个数字; 让你选择若干个区间; 且这些区间[li,ri]; 左端点不能一样; ...

  7. 【codeforces 602D】Lipshitz Sequence

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  8. 【66.47%】【codeforces 556B】Case of Fake Numbers

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  9. 【35.29%】【codeforces 557C】Arthur and Table

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

随机推荐

  1. tomcat之性能优化

    tomcat是我们常用的web容器,它的性能高低直接影响到应用对外提供服务的能力和用户的体验,所以tomcat的优化至关重要.对于单台tomcat服务器而言,优化主要是两方面:内存优化和配置优化(例如 ...

  2. 关于windows 7 安装Django和基本使用命令

    一.安装 在安装前需注意Django 1.6以前的版本不支持python 3.×以上的版本. Django 2.×支持python 3.6 安装方法:打开cmd->输入pip install - ...

  3. jQuery-AutoComplete自动提示简单实现

    注:本次案列实现功能为 用户注册信息,如果数据库对应表中存在部分信息,点击已有的用户的用户名,自动补全其它已有的基本信息 实现思路:通过AutoComplete提示,异步通过用户名查询全表,充当Aut ...

  4. RS232通信(Android)

    一. 添加依赖dependencies { implementation 'com.github.kongqw:AndroidSerialPort:1.0.1'} 二. 使用方法 package co ...

  5. Opencv-Python No module named 'cv2.cv2'

    关于 No module named 'cv2.cv2'等其他一些问题,一般都是版本不兼容的问题,重装即可. pip uninstall opencv-python 然后 pip install op ...

  6. Sql题面试题

    哪位大神会此题,请给出答案,十分感谢! 哪位大神会此题,请给出答案,十分感谢!

  7. 关于JS的原型与继承笔记

    1.什么是原型? 原型就是公用的方法或者属性. 1.prototype本质上还是一个JavaScript对象: 2.每个函数都有一个默认的属性prototype,而这个prototype的constr ...

  8. Cocos Creator LabelAtlas(艺术数字的使用)

    # 艺术数字资源 (LabelAtlas) **艺术数字资源** 是一种用户自定义的资源,它可以用来配置艺术数字字体的属性. ## 创建艺术数字资源 在 **资源管理器** 中右键,可以在如下菜单中找 ...

  9. xamarin.forms 动态条件更换数据模板

    解决方案1:  https://oren.codes/2014/12/31/datatemplateselector-for-xamarin-forms/ 解决方案2:  https://docs.m ...

  10. 监听器----java

    监听器简介: 1 什么是web监听器? web监听器是一种Servlet中的特殊的类,它们能帮助开发者监听web中的特定事件,比如ServletContext,HttpSession,ServletR ...