传送门


题目大意:

  给你一个序列,要求在序列上维护三个操作:

  1)区间求和

  2)区间取模

  3)单点修改

这里的操作二很讨厌,取模必须模到叶子节点上,否则跑出来肯定是错的。没有操作二就是线段树水题了。

既然必须模到叶子节点,那我们就模咯。

显然,若$b<c$,则$b%c=b$。

因此我们同时维护一个区间最大值,若某区间内最大值小于模数,就把该分支剪掉。

若$a=b%c$,那么肯定有$a \leq \frac{b}{2}$成立。

也就是说,一个数最多被模$\log_2 x$次。总的时间复杂度为$O(n \log n)$,可以接受(就算取模$log$次以后单点修改将某点的值改大,因为有上述剪枝存在,时间复杂度并不会上升太多)。

代码:

 #include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cctype>
#define foru(i,x,y) for(LL i=x;i<=y;i++)
#define ford(i,x,y) for(LL i=x;i>=y;i--)
#define re(x) x=read()
#define max(a,b) ((aaa=a)>(bbb=b))?aaa:bbb
using namespace std;
typedef long long LL;
typedef double db;
const LL inf=1e9;
const LL N=2e6+; struct node{LL s,m;}t[N];
LL n,m,aaa,bbb; LL read(){
static LL f,x;static char ch;
x=f=;ch=getchar();
while(!isdigit(ch)){f=(ch=='-');ch=getchar();}
while(isdigit(ch)){x=x*+ch-'';ch=getchar();}
return f?-x:x;
} #define mid ((L+R)>>1)
#define ls (k<<1)
#define rs ((k<<1)+1) void upd(LL k,LL L,LL R,LL p,LL x){
if(p<L||p>R)return;
if(L==R){t[k]=(node){x,x};return;}
upd(ls,L,mid,p,x);upd(rs,mid+,R,p,x);
t[k].s=t[ls].s+t[rs].s;
t[k].m=max(t[ls].m,t[rs].m);
} LL qrys(LL k,LL L,LL R,LL l,LL r){
if(r<L||l>R)return ;
if(l<=L&&R<=r)return t[k].s;
return qrys(ls,L,mid,l,r)+qrys(rs,mid+,R,l,r);
} LL qrym(LL k,LL L,LL R,LL l,LL r){
if(r<L||l>R)return ;
if(l<=L&&R<=r)return t[k].m;
return max(qrym(ls,L,mid,l,r),qrym(rs,mid+,R,l,r));
} void mo(LL k,LL L,LL R,LL l,LL r,LL x){
if(r<L||l>R||t[k].m<x)return;
if(L==R){t[k].s%=x;t[k].m=t[k].s;return;}
mo(ls,L,mid,l,r,x);mo(rs,mid+,R,l,r,x);
t[k].s=t[ls].s+t[rs].s;
t[k].m=max(t[ls].m,t[rs].m);
} int main(){
LL l,r,x;
//freopen("mod.in","r",stdin);freopen("mod.out","w",stdout);
re(n);re(m);
foru(i,,n){
re(x);
upd(,,n,i,x);
}
foru(i,,m){
re(x);re(l);re(r);
if(x==){
printf("%I64d\n",qrys(,,n,l,r));
}else if(x==){
re(x);
mo(,,n,l,r,x);
}else{
upd(,,n,l,r);
}
}
return ;
}

CodeForces 438D The Child and Sequence (线段树 暴力)的更多相关文章

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

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

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

  3. 2018.07.23 codeforces 438D. The Child and Sequence(线段树)

    传送门 线段树维护区间取模,单点修改,区间求和. 这题老套路了,对一个数来说,每次取模至少让它减少一半,这样每次单点修改对时间复杂度的贡献就是一个log" role="presen ...

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

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

  6. 题解——CodeForces 438D The Child and Sequence

    题面 D. The Child and Sequence time limit per test 4 seconds memory limit per test 256 megabytes input ...

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

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

  8. 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, ...

  9. Codeforces 438D The Child and Sequence

    题意:给定一个n个数的序列,完成以下3个操作: 1.给定区间求和 2.给定区间对x取模 3.单点修改 对一个数取模,这个数至少折半.于是我们记一个最大值max,如果x>max则不做处理. #in ...

随机推荐

  1. 前台图片Canvas压缩上传小结

    需求来源:之前有个提交审核表单的业务,表单中含有大量附件图片,大约有20多张吧,为了省事,采用的同步上传,一次需要上传很多照片,本来单张图片限制为200KB,这样子总图片大小约为5MB左右,想想也可以 ...

  2. comparable and comparator 比较

      转:http://www.yingjiesheng.com/job-002-393-132.html 一.前言 在Java集合框架里面,各种集合的操作很大程度上都离不开Comparable和Com ...

  3. docker入门资料及常用命令

      Docker17中文开发手册 :https://www.php.cn/manual/view/36147.html   Linux部署Docker及常用命令: https://www.cnblog ...

  4. SpringMVC:拦截器

    SpringMVC:拦截器   概述 SpringMVC的处理器拦截器类似于Servlet开发中的过滤器Filter,用于对处理器进行预处理和后处理.开发者可以自己定义一些拦截器来实现特定的功能. 过 ...

  5. bestphp's revenge

    0x00 知识点 1利用PHP原生类来构造POP链 本题没有可以利用的类,没有可以利用的类就找不到POP链所以只能考虑PHP原生类 我们先来解释一下什么是POP链 POP:面向属性编程 在二进制利用时 ...

  6. css 居中布局方案

    position(transform css3  有些浏览器不兼容) <article id="one"> <section id="section&q ...

  7. 强制浏览器以IE8版本运行

    做为一个开发人员,经常被要求前端页面兼容ie8及以上,所以有时候我们希望ie默认以ie8的版本打开我们的页面. 1.“文档模式”: 在html页面中加入类似下面的代码: <meta http-e ...

  8. POJ 2488:A Knight's Journey 深搜入门之走马观花

    A Knight's Journey Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 35342   Accepted: 12 ...

  9. 19 01 03 css 中 reset 模块 设置

    主要就是让到时候 打入代码时候  把一些bug去除   或者 让一些固有的格式取消 /* 将标签默认的间距设为0 */ body,p,h1,h2,h3,h4,h5,h6,ul,dl,dt,form,i ...

  10. 【收藏】免费开源好看的bootstrap后台模板

    1.ace admin github:https://github.com/bopoda/acedemo:http://ace.jeka.by/ 2.CoreUI jQuery.Angular.Rea ...