CF(438D) The Child and Sequence(线段树)
题意:对数列有三种操作:
- Print operation l, r. Picks should write down the value of
.
- Modulo operation l, r, x. Picks should perform assignment a[i] = a[i] mod x for
each i (l ≤ i ≤ r). - Set operation k, x. Picks should set the value of a[k] to x (in
other words perform an assignment a[k] = x).
/******************************************************
* author:xiefubao
*******************************************************/
#pragma comment(linker, "/STACK:102400000,102400000")
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <string.h>
//freopen ("in.txt" , "r" , stdin);
using namespace std; #define eps 1e-8
const double pi=acos(-1.0);
typedef long long LL;
const int Max=100100*2;
const int INF=1000000007;
struct node
{
int l,r;
node * left,*right;
int ma;
LL sum;
} nodes[Max];
int Mid(node* p)
{
return (p->l+p->r)/2;
}
int tot=0;
void buildtree(node* p,int left,int right)
{
p->l=left;
p->r=right;
p->ma=0;
p->sum=0;
if(left==right)
return ;
int mid=(left+right)/2;
tot++;
p->left=nodes+tot;
buildtree(p->left,left,mid);
tot++;
p->right=nodes+tot;
buildtree(p->right,mid+1,right);
}
void update(node* p,int i,int value)
{
if(p->l==i&&p->r==i)
{
p->sum=value;
p->ma=value;
return ;
}
int mid=Mid(p);
if(i<=mid)
update(p->left,i,value);
else
update(p->right,i,value);
p->sum=p->left->sum+p->right->sum;
p->ma=max(p->left->ma,p->right->ma);
}
void update2(node* p,int l,int r,int x)
{
if(p->ma<x)
return;
if(p->l==l&&p->r==r&&l==r)
{
p->sum%=x;
p->ma=p->sum;
return ;
}
int mid=Mid(p);
if(r<=mid)
update2(p->left,l,r,x);
else if(l>mid)
update2(p->right,l,r,x);
else
{
update2(p->left,l,mid,x);
update2(p->right,mid+1,r,x);
}
p->sum=p->left->sum+p->right->sum;
p->ma=max(p->left->ma,p->right->ma);
}
LL query(node* p,int l,int r)
{
if(l==p->l&&r==p->r)
{
return p->sum;
}
int mid=Mid(p);
if(r<=mid)
return query(p->left,l,r);
if(l>mid)
return query(p->right,l,r);
return query(p->left,l,mid)+query(p->right,mid+1,r);;
}
int n,m;
int main()
{
while(scanf("%d%d",&n,&m)==2)
{
tot=0;
buildtree(nodes,0,n+1);
for(int i=1; i<=n; i++)
{
int a;
scanf("%d",&a);
update(nodes,i,a);
}
while(m--)
{
int t;
scanf("%d",&t);
if(t==1)
{
int l,r;
scanf("%d%d",&l,&r);
cout<<query(nodes,l,r)<<endl;
}
else if(t==2)
{
int l,r,x;
scanf("%d%d%d",&l,&r,&x);
update2(nodes,l,r,x);
}
else if(t==3)
{
int i,x;
scanf("%d%d",&i,&x);
update(nodes,i,x);
}
}
}
return 0;
}
CF(438D) The Child and 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 438D The Child and Sequence (线段树 暴力)
传送门 题目大意: 给你一个序列,要求在序列上维护三个操作: 1)区间求和 2)区间取模 3)单点修改 这里的操作二很讨厌,取模必须模到叶子节点上,否则跑出来肯定是错的.没有操作二就是线段树水题了. ...
- 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 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 证明: 即得易见平凡, 仿照上例显然, 留作习题答案略, 读者自证不难. ...
- 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, ...
- CF438D The Child and Sequence 线段树
给定数列,区间查询和,区间取模,单点修改. n,m小于10^5 ...当区间最值小于模数时,就直接返回就好啦~ #include<cstdio> #include<iostream& ...
- 2016暑假多校联合---Rikka with Sequence (线段树)
2016暑假多校联合---Rikka with Sequence (线段树) Problem Description As we know, Rikka is poor at math. Yuta i ...
- 2018.07.23 codeforces 438D. The Child and Sequence(线段树)
传送门 线段树维护区间取模,单点修改,区间求和. 这题老套路了,对一个数来说,每次取模至少让它减少一半,这样每次单点修改对时间复杂度的贡献就是一个log" role="presen ...
随机推荐
- Linux socket 编程中存在的五个隐患
前言: Socket API 是网络应用程序开发中实际应用的标准 API.尽管该 API 简单,但是 开发新手可能会经历一些常见的问题.本文识别一些最常见的隐患并向您显示如何避免它 ...
- Python: PS 滤镜--碎片特效
本文用 Python 实现 PS 滤镜中的碎片特效,这个特效简单来说就是将图像在 上,下,左,右 四个方向做平移,然后将四个方向的平移的图像叠加起来做平均.具体的效果图可以参考之前的博客 http:/ ...
- 可变对象 vs 不可变对象(Python)
Python 在 heap 中分配的对象分成两类:可变对象和不可变对象.所谓可变对象是指,对象的内容是可变的,例如 list.而不可变的对象则相反,表示其内容不可变. 不可变对象:int,string ...
- Mysql优化ibdata1大小
在MySQL数据库中,如果不指定innodb_file_per_table参数来单独存在每个表的数据,MySQL的数据都会存放在ibdata1文件.mysql ibdata1存放数据,索引等,是MYS ...
- 把ISO文件当作光盘挂载
当不能挂载光盘或者U盘时候,只需要把ISO文件传到某个目录中,比如/data下,即可挂载,如下所示: mount -o loop /data/rhel-server-6.3-x86_64-dvd. ...
- [BJWC2012]冻结 分层图最短路
昨晚飞行路线之后,这道题就应该能一眼切了 题目当然也不难,跑一遍分层图最短路即可 Code: #include<cstring> #include<algorithm> #in ...
- 解决zabbix容器中文无法选择的问题
1.查看zabbiz-web运行的容器 2.进入容器 3.安装语言包(针对centos7) yum install -y kde-l10n-chinese 4.更新gitbc包(因为镜像阉割了该包的部 ...
- 如何解决本地仓库和远程仓库的冲突(Conflict)
Background: 我有一个github仓库管理我的代码,我将这个仓库的代码clone到我的工作电脑和私人电脑本地方便我上班和在家时都可以对我的代码进行更新. 一天,我在家修改过代码之后并未提交, ...
- Java基础学习总结(27)——7 款开源 Java 反编译工具
今天我们要来分享一些关于Java的反编译工具,反编译听起来是一个非常高上大的技术词汇,通俗的说,反编译是一个对目标可执行程序进行逆向分析,从而得到原始代码的过程.尤其是像.NET.Java这样的运行在 ...
- Maven的SSH搭建以及部署
本人有点傻,研究Maven研究了有一段时间,刚刚有些入门,记录下来方便以后使用 工作环境:jdk7 myeclipse10 maven3.1.1 1 下载maven3.1.1 http://maven ...