在大大推荐下这个标题不明的人做。而我的最后一个非常喜欢的段树,因此,愤怒出手。认为基本上相同。大值,当最大值小于取模时能够剪枝。
今后再遇到此类问题算是能攻克了
// file name: d.cpp //
// author: huangjipeng //
// creat time: 2014年05月26日 星期一 16时40分18秒 //
///////////////////////////////////////////////////////
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<map>
#include<vector>
#include<queue>
using namespace std;
#define MAXN 100005
struct node
{
int l,r;
int mid;
long long maxx;
long long sum;
}tree[MAXN<<2];
void build(int l,int r,int now)
{
tree[now].l=l;
tree[now].r=r;
tree[now].mid=(l+r)>>1;
if(l==r)
{
scanf("%I64d",&tree[now].maxx);
tree[now].sum=tree[now].maxx;
return ;
}
build(l,tree[now].mid,now<<1);
build(tree[now].mid+1,r,now<<1|1);
tree[now].sum=(tree[now<<1].sum+tree[now<<1|1].sum);
tree[now].maxx=max(tree[now<<1].maxx,tree[now<<1|1].maxx);
}
long long query(int l,int r,int now)
{
if(tree[now].l==l && tree[now].r==r)
return tree[now].sum;
if(l>tree[now].mid)
return query(l,r,now<<1|1);
else if(r<=tree[now].mid)
return query(l,r,now<<1);
else
return query(l,tree[now].mid,now<<1)+query(tree[now].mid+1,r,now<<1|1);
}
void update(int l,int r,long long x,int now)
{
if(tree[now].maxx<x)
return ;
if(tree[now].l==tree[now].r)
{
tree[now].sum=tree[now].sum%x;
tree[now].maxx=tree[now].sum;
return ;
}
if(l>tree[now].mid)
update(l,r,x,now<<1|1);
else if(r<=tree[now].mid)
update(l,r,x,now<<1);
else
{
update(l,tree[now].mid,x,now<<1);
update(tree[now].mid+1,r,x,now<<1|1);
}
tree[now].sum=tree[now<<1].sum+tree[now<<1|1].sum;
tree[now].maxx=max(tree[now<<1].maxx,tree[now<<1|1].maxx);
}
void op3(int k,long long x,int now)
{
if(tree[now].l==k && tree[now].r==k)
{
tree[now].maxx=tree[now].sum=x;
return ;
}
if(k>tree[now].mid)
op3(k,x,now<<1|1);
else
op3(k,x,now<<1);
tree[now].sum=(tree[now<<1].sum+tree[now<<1|1].sum);
tree[now].maxx=max(tree[now<<1].maxx,tree[now<<1|1].maxx);
}
int main()
{
int n,m;
cin>>n>>m;
build(1,n,1);
while(m--)
{
int op;
scanf("%d",&op);
if(op==1)
{
int l,r;
scanf("%d%d",&l,&r);
cout<<query(l,r,1)<<endl;
}
else if(op==2)
{
int l,r;
long long x;
scanf("%d%d%I64d",&l,&r,&x);
update(l,r,x,1);
}
else if(op==3)
{
int k;
long long x;
scanf("%d%I64d",&k,&x);
op3(k,x,1);
}
}
return 0;
}

版权声明:本文博主原创文章,博客,未经同意不得转载。

codeforces 438D的更多相关文章

  1. Codeforces 438D (今日gg模拟第二题) | 线段树 考察时间复杂度的计算 -_-|||

    Codeforces 438D The Child and Sequence 给出一个序列,进行如下三种操作: 区间求和 区间每个数模x 单点修改 如果没有第二个操作的话,就是一棵简单的线段树.那么如 ...

  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 438D The Child and Sequence

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

  4. 【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],…, ...

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

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

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

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

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

  8. CodeForces 438D 线段树 剪枝

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

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

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

随机推荐

  1. SqlBulkCopy批量插入数据时,不执行触发器和约束的解决方法

    原文:SqlBulkCopy批量插入数据时,不执行触发器和约束的解决方法 在new SqlBulkCopy对象的时候,设置一下SqlBulkCopyOptions选项即可,按位或运算 SqlBulkC ...

  2. WPF和Expression Blend开发实例:一个样式实现的数字输入框

    原文:WPF和Expression Blend开发实例:一个样式实现的数字输入框 今天来一个比较奇淫技巧的手法,很少人用,同时也不推荐太过频繁的使用. 先上样式: <Style x:Key=&q ...

  3. BZOJ 3236 AHOI 2013 作业 莫队算法

    题目大意:给出一些数,问在一个区间中不同的数值有多少种,和在一个区间中不同的数值有多少个. 思路:因为没有改动,所以就想到了莫队算法.然后我写了5K+的曼哈顿距离最小生成树,然后果断T了.(100s的 ...

  4. MVC模式编程演示样本-登录认证(静态)

    好,部分博客分享我的总结JSP-Servlet-JavaBean思想认识和三层编程模型的基本流程,ZH- CNMVC该示例实现演示的编程模式-登录身份验证过程,在这里,我仍在使用静态验证usernam ...

  5. UVA - 12001 UVa Panel Discussion

    Description  UVa Panel Discussion  The UVa online judge team is arranging a panel discussion for the ...

  6. 未能加载文件或程序集“Common”或它的某一个依赖项。试图加载格式不正确的程序

    原因:操作系统是64位的,但发布的程序引用了一些32位的ddl,所以出现了兼容性的问题解决方案一:如果是64位机器,IIS——应用程序池——高级设置——启用32位应用程序 :true.解决方案二:修改 ...

  7. REQIMPORT-购买内部应用程序(R12.2.3)

     採购内部申请(R12.2.3) --US Program:Requisition Import Short Name:REQIMPORT Application:Purchasing Execu ...

  8. MVC 01

    ASP.NET MVC 01 - ASP.NET概述 本篇目录: ASP.NET 概述 .NET Framework 与 ASP.NET ASP.NET MVC简介 ASP.NET的特色和优势 典型案 ...

  9. 自己动手写CPU之第八阶段(4)——转移指令实现过程2

    将陆续上传本人写的新书<自己动手写CPU>,今天是第36篇,我尽量每周四篇 开展晒书评送书活动,在亚马逊.京东.当当三大图书站点上,发表<自己动手写CPU>书评的前十名读者,均 ...

  10. 微软系统工具套件SysinternalsSuite各个工具功能说明

    下载地址:http://download.sysinternals.com/files/SysinternalsSuite.zip 工具名    工具说明 Accesschk      Windows ...