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 ...
随机推荐
- DGA特征挖掘
摘自:https://paper.seebug.org/papers/Archive/drops2/%E7%94%A8%E6%9C%BA%E5%99%A8%E5%AD%A6%E4%B9%A0%E8%A ...
- matplotlib 可视化 —— 绘制常见图形
0. 饼状图 plt.pie():Python数据可视化:饼状图 1. 三角形 描点连线,起点和终点相同 triangle1 = ((0, sqrt(3)/2), (1, 3*sqrt(3)/2), ...
- List methods
Python provides methods that operate on lists. For example, append adds a new element to the end of ...
- python-网络-tcp
python-网络-tcp 标签(空格分隔): python TCP[client]-发送数据 from socket import * s = socket(AF_INET, SOCK_STREAM ...
- BZOJ 3240 构造矩阵+矩阵快速幂
思路: ax+b cx+d 构造矩阵+矩阵快速幂 (需要加各种特判,,,,我好像加少了- ) //By SiriusRen #include <cstdio> #include <c ...
- linux系统下,11款常见远程桌面控制软件(转载)
远程控制能够给人们带来很多便利,本文介绍了11款常见的Linux系统下的远程桌面控制工具,总有一款能适合您. 一. Grdc 它是一个用GTK+编写的,适用于gnome桌面环境的远程桌面访问软件.看图 ...
- 一篇文章助你理解Python3中字符串编码问题
前几天给大家介绍了unicode编码和utf-8编码的理论知识,以及Python2中字符串编码问题,没来得及上车的小伙伴们可以戳这篇文章:浅谈unicode编码和utf-8编码的关系和一篇文章助你理解 ...
- Git 内部原理 - (7)维护与数据恢复 (8) 环境变量 (9)总结
维护与数据恢复 有的时候,你需要对仓库进行清理 - 使它的结构变得更紧凑,或是对导入的仓库进行清理,或是恢复丢失的内容. 这个小节将会介绍这些情况中的一部分. 维护 Git 会不定时地自动运行一个叫做 ...
- [洛谷P2085]最小函数值
题目大意:有n个函数,分别为F1,F2,...,Fn.定义Fi(x)=Ai*x^2+Bi*x+Ci (x∈N*).给定这些Ai.Bi和Ci,要求出所有函数的所有函数值中最小的m个(如有重复的要输出多个 ...
- ArcGIS api for javascript——地图配置-定制缩放动画,定制缩放框
描述 本例展示了当用户放大或缩小地图时如何定义地图的动画.zoomDuration和zoomRate是Dojo动画属性,他们确定了动画的duration和帧刷新的rate .这些属性单位是毫秒,zoo ...