#线段树#CF438D The Child and Sequence
题目
支持区间求和,区间取模,单点修改
分析
首先区间取模一直不停取模最多log次是有效的,
所以处理区间最大值,若区间最大值小于模数直接退出,否则暴力修改
时间复杂度\(O(mlog^2n)\)
代码
#include <cstdio>
#include <cctype>
#define rr register
using namespace std;
const int N=100011; typedef long long lll;
int a[N],mx[N<<2],n,m; lll w[N<<2];
inline signed iut(){
rr int ans=0; rr char c=getchar();
while (!isdigit(c)) c=getchar();
while (isdigit(c)) ans=(ans<<3)+(ans<<1)+(c^48),c=getchar();
return ans;
}
inline void print(lll ans){
if (ans>9) print(ans/10);
putchar(ans%10+48);
}
inline signed max(int a,int b){return a>b?a:b;}
inline void pup(int k){
w[k]=w[k<<1]+w[k<<1|1],
mx[k]=max(mx[k<<1],mx[k<<1|1]);
}
inline void build(int k,int l,int r){
if (l==r) {
w[k]=mx[k]=a[l];
return;
}
rr int mid=(l+r)>>1;
build(k<<1,l,mid);
build(k<<1|1,mid+1,r);
pup(k);
}
inline void change(int k,int l,int r,int x,int z){
if (l==r){
w[k]=mx[k]=z;
return;
}
rr int mid=(l+r)>>1;
if (x<=mid) change(k<<1,l,mid,x,z);
else change(k<<1|1,mid+1,r,x,z);
pup(k);
}
inline void update(int k,int l,int r,int x,int y,int z){
if (mx[k]<z) return;
if (l==r){
w[k]%=z,mx[k]%=z;
return;
}
rr int mid=(l+r)>>1;
if (x<=mid) update(k<<1,l,mid,x,y,z);
if (y>mid) update(k<<1|1,mid+1,r,x,y,z);
pup(k);
}
inline lll query(int k,int l,int r,int x,int y){
if (l==x&&r==y) return w[k];
rr int mid=(l+r)>>1;
if (y<=mid) return query(k<<1,l,mid,x,y);
else if (x>mid) return query(k<<1|1,mid+1,r,x,y);
else return query(k<<1,l,mid,x,mid)+query(k<<1|1,mid+1,r,mid+1,y);
}
signed main(){
n=iut(); m=iut();
for (rr int i=1;i<=n;++i) a[i]=iut();
build(1,1,n);
for (rr int z,x,y;m;--m){
z=iut(),x=iut(),y=iut();
if (z==1) print(query(1,1,n,x,y)),putchar(10);
else if (z==3) change(1,1,n,x,y);
else update(1,1,n,x,y,iut());
}
return 0;
}
#线段树#CF438D The Child and Sequence的更多相关文章
- [CF438D]The Child and Sequence【线段树】
题目大意 区间取模,区间求和,单点修改. 分析 其实算是一道蛮简单的水题. 首先线段树非常好解决后两个操作,重点在于如何解决区间取模的操作. 一开始想到的是暴力单点修改,但是复杂度就飙到了\(mnlo ...
- CF438D The Child and Sequence(线段树)
题目链接:CF原网 洛谷 题目大意:维护一个长度为 $n$ 的正整数序列 $a$,支持单点修改,区间取模,区间求和.共 $m$ 个操作. $1\le n,m\le 10^5$.其它数均为非负整数且 ...
- 「CF438D The Child and Sequence」
一道CF线段树好题. 前置芝士 线段树:一个很有用数据结构. 势能分析:用来证明复杂度,其实不会也没什么关系啦. 具体做法 不难发现,对于一个数膜一个大于它的数后,这个数至少减少一半,每个数最多只能被 ...
- CF438D The Child and Sequence 线段树
给定数列,区间查询和,区间取模,单点修改. n,m小于10^5 ...当区间最值小于模数时,就直接返回就好啦~ #include<cstdio> #include<iostream& ...
- CF438D The Child and Sequence
外国人的数据结构题真耿直 唯一有难度的操作就是区间取模,然而这个东西可以暴力弄一下,因为一个数$x$被取模不会超过$logn$次. 证明如下(假设$x Mod y$): 如果$y \leq \fr ...
- 【CF438D】The Child and Sequence(线段树)
点此看题面 大致题意: 给你一个序列,让你支持区间求和.区间取模.单点修改操作. 区间取模 区间求和和单点修改显然都很好维护吧,难的主要是区间取模. 取模标记无法叠加,因此似乎只能暴力搞? 实际上,我 ...
- 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 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 Round #250 (Div. 1) D. The Child and Sequence(线段树)
D. The Child and Sequence time limit per test 4 seconds memory limit per test 256 megabytes input st ...
- 线段树【CF620E】The Child and Sequence
Description At the children's day, the child came to Picks's house, and messed his house up. Picks w ...
随机推荐
- 【Azure Developer】AAD API如何获取用户“Block sign in”信息(accountEnabled)
问题描述 使用API获取所有Azure AD中的用户列表,API所参考的文档:https://docs.microsoft.com/en-us/graph/api/user-list?view=gra ...
- 【Azure API 管理】APIM的容量指标(Capacity)数据异常高的情况记录
问题描述 APIM从标准版降级到基础版,在没有用户使用的情况,Capacity的指标平均显示在80%以上. 这是什么异常情况呢? 问题分析 APIM的容量指标(Capacity)是 API 管理实例中 ...
- 【Azure 应用服务】App Service下部署的应用报错 Out of Memory
问题描述 应用部署到App Service后,遇见了Out of Memory的错误. 报错信息:GetData Error:, Exception of type 'System.OutOfMem ...
- python执行JavaScript代码出现编码问题的解决方案
当我们安装好nodejs环境,想在python代码中去调用JavaScript代码,常常会出现编码的问题. 举个例子: python代码如下: 点击查看代码 import execjs f = ope ...
- 【苹果】SpringBoot监听Iphone15邮件提醒,Selenium+Python自动化抢购脚本
前言 缘由 Iphone15来了,两年之约你还记得吗? 遂整合之前iphone13及iphone14的相关抢购代码,完成一个SpringBoot监听Iphone15有货邮件提醒+python自动化脚本 ...
- ConcurrentHashMap的put方法
使用JDK8 源码: public V put(K key, V value) { return putVal(key, value, false); } /** Implementation for ...
- 使用C#创建服务端Web API
前言 C# Web API 是一种基于 .NET 平台(包括但不限于.NET Framework 和 .NET Core)构建 HTTP 服务的框架,用于创建 RESTful Web 服务.REST( ...
- folder-alias vscode左侧目录树 起别名 插件 (git decorations)
folder-alias vscode左侧目录树 起别名 插件 插件 效果 不足 文件路径或目录路径中包含中文 会挂不上别名,纯英文路径没问题 有修改后,git会覆盖,不显示别名 个人意见 我的项目都 ...
- WPF之控件布局
目录 控件概述 WPF的内容模型 各类内容模型详解 ContentControl族 HeaderedContentControl族 ItemsControl族 ListBox:在XAML中添加数据 L ...
- pod为什么会被驱逐及如何避免pod被驱逐导致的服务中断
Pod被驱逐的原因主要有以下几点: 资源不足:当节点资源(如CPU.内存.存储等)不足以满足Pod的资源需求时,调度器会选择将其中一个或多个Pod驱逐出节点,以便在资源有限的节点上安排新的Pod. 超 ...