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 ...
随机推荐
- SQL Server单表已700w+将普通表转换成分区表1
最近项目中,某个表数据量爆发时增长,单表已700w+,读写性能急剧下降,所以考虑加入分区表以解燃眉之急,后续还是要分表分库,当然这是后话.下面简要说一下将普通表转为分区表的步骤. 一.创建文件组 ...
- c3p0-config.xml
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE xml> <c3p0-confi ...
- Linux服务器性能评估与优化
一.影响务器性能因素 影响企业生产环境Linux服务器性能的因素有很多,一般分为两大类,分别为操作系统层级和应用程序级别.如下为各级别影响性能的具体项及性能评估的标准: (1)操作系统级别 内存: C ...
- 修复linux的grub2引导(单独/boot,lvm-root)
root@ubuntu:/home/ubuntu# pwd /home/ubuntu root@ubuntu:/home/ubuntu# lsblk NAME MAJ ...
- element-ui table 行内编辑
EditRow.ts vue+element-ui+slot-scope原生实现可编辑表格 interface NoParamConstructor<T> { new(): T; } ex ...
- 紫书 习题 10-15 UVa 12063(数位dp)
大佬真的强!!https://blog.csdn.net/u014800748/article/details/45225881 #include<cstdio> #include< ...
- 2014 CodingTrip - 携程编程大赛 (预赛第二场)
1001: 食物链(poj1182),直接贴代码,稍作可过 并查集 // // main.cpp // 携程1 // // Created by zhang on 14-4-11. // Copyri ...
- Network authentication method and device for implementing the same
A network authentication method is to be implemented using a network authentication device and a use ...
- [Recompose] Make Reusable React Props Streams with Lenses
If you hard-code a stream of props to target a specific prop, it becomes impossible to reuse that st ...
- Codeforces 558C Amr and Chemistry 全都变相等
题意:给定一个数列,每次操作仅仅能将某个数乘以2或者除以2(向下取整). 求最小的操作次数使得全部的数都变为同样值. 比赛的时候最后没实现.唉.之后才A掉.開始一直在想二分次数,可是半天想不出怎 ...