题意:

给定一个长度为n的非负整数序列a,你需要支持以下操作:
1)给定l,r,输出a[l] + a[l+1] + ... + a[r]

2)给定l,r,x, 将a[l]、a[l+1]、....、a[r]x取模

3)给定k,y,将a[k]修改为y

n, m <= 100000,a[i], x, y <= 109


对于操作(1)(3)非常简单,线段树基本操作

问题是操作(2),显然的是我们不能对区间和取模,这样就很难受

但是我们可以想到,一个数若是比模数小,就不需要取模,而一个数w有效取模次数最多为log(w)

同时单个数被有效取模的一次只会花费O(logn)

因此每次修改至多使复杂度增加O(lognlogw)

这样我们对于区间l, r暴力对每个能取模的数取模即可

最后时间复杂度为O(mlognlogw)

 #include<bits/stdc++.h>
#define ll long long
#define uint unsigned int
#define ull unsigned long long
using namespace std;
const int maxn = ;
struct shiki {
ll maxx, sum;
}tree[maxn << ];
int n, m;
ll a[maxn]; inline ll read() {
ll x = , y = ;
char ch = getchar();
while(!isdigit(ch)) {
if(ch == '-') y = -;
ch = getchar();
}
while(isdigit(ch)) {
x = (x << ) + (x << ) + ch - '';
ch = getchar();
}
return x * y;
} inline void maintain(int pos) {
int ls = pos << , rs = pos << | ;
tree[pos].maxx = max(tree[ls].maxx, tree[rs].maxx);
tree[pos].sum = tree[ls].sum + tree[rs].sum;
} void build(int pos, int l, int r) {
if(l == r) {
tree[pos].maxx = tree[pos].sum = a[l];
return;
}
int mid = l + r >> ;
build(pos << , l, mid);
build(pos << | , mid + , r);
maintain(pos);
} void get_mod(int pos, int L, int R, int l, int r, ll mod) {
if(l > R || r < L) return;
if(tree[pos].maxx < mod) return;
if(l == r) {
tree[pos].sum %= mod;
tree[pos].maxx %= mod;
return;
}
int mid = l + r >> ;
get_mod(pos << , L, R, l, mid, mod);
get_mod(pos << | , L, R, mid + , r, mod);
maintain(pos);
} void update(int pos, int aim, int l, int r, ll val) {
if(l == r && l == aim) {
tree[pos].maxx = tree[pos].sum = val;
return;
}
int mid = l + r >> ;
if(aim <= mid) update(pos << , aim, l, mid, val);
else update(pos << | , aim, mid + , r, val);
maintain(pos);
} ll query_sum(int pos, int L, int R, int l, int r) {
if(l > R || r < L) return ;
if(l >= L & r <= R) return tree[pos].sum;
int mid = l + r >> ;
return query_sum(pos << , L, R, l, mid) + query_sum(pos << | , L, R, mid + , r);
} int main() {
n = read(), m = read();
for(int i = ; i <= n; ++i) a[i] = read();
build(, , n);
for(int i = ; i <= m; ++i) {
int opt = read(), x = read(), y = read();
if(opt == ) printf("%I64d\n", query_sum(, x, y, , n));
if(opt == ) {
ll p = read();
get_mod(, x, y, , n, p);
}
if(opt == ) update(, x, , n, y);
}
return ;
}

CF438 The Child and Sequence的更多相关文章

  1. Codeforce 438D-The Child and Sequence 分类: Brush Mode 2014-10-06 20:20 102人阅读 评论(0) 收藏

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

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

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

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

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

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

  6. AC日记——The Child and Sequence codeforces 250D

    D - The Child and Sequence 思路: 因为有区间取模操作所以没法用标记下传: 我们发现,当一个数小于要取模的值时就可以放弃: 凭借这个来减少更新线段树的次数: 来,上代码: # ...

  7. 438D - The Child and Sequence

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

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

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

随机推荐

  1. Error creating bean with name 'transactionManager' defined in ServletContext resource XXX

    spring & hibernate整合时候 ,并且使用hibernate.cfg.xml文件时回报这个错误, 解决办法,在hibernate.cfg.xml中加入 <property ...

  2. DialogFragment 将数据传回Activity的onActivityResult方法

    在MyActivity中 弹出一个DialogFragment (某一个控件的点击事件) search= findViewById(R.id.search); search.setOnClickLis ...

  3. Dubbo 的应用

    ---  用于大规模服务化,通过在消费方获取服务提供方的地址列表,实现负载均衡,减轻服务器压力. 最简单调用图 节点角色说明: l  Provider: 暴露服务的服务提供方. l  Consumer ...

  4. 【BZOJ】3302: [Shoi2005]树的双中心 && 2103: Fire 消防站 && 2447: 消防站

    [题意]给定带点权树,要求选择两个点x,y,满足所有点到这两个点中较近者的距离*点权的和最小.n<=50000,h<=100. [算法]树的重心 [题解]代码参考自:cgh_Andy 观察 ...

  5. 【BZOJ】3991: [SDOI2015]寻宝游戏 虚树+DFS序+set

    [题意]给定n个点的带边权树,对于树上存在的若干特殊点,要求任选一个点开始将所有特殊点走遍后返回.现在初始没有特殊点,m次操作每次增加或减少一个特殊点,求每次操作后的总代价.n,m<=10^5. ...

  6. 【CodeForces】899 F. Letters Removing

    [题目]F. Letters Removing [题意]给定只含小写字母.大写字母和数字的字符串,每次给定一个范围要求删除[l,r]内的字符c(l和r具体位置随删除变动),求m次操作后的字符串.n&l ...

  7. 深入理解Spring系列之七:web应用自动装配Spring配置

    转载 https://mp.weixin.qq.com/s/Lf4akWFmcyn9ZVGUYNi0Lw 在<深入理解Spring系列之一:开篇>的示例代码中使用如下方式去加载Spring ...

  8. 在Oracle中查询表的大小

    SELECT segment_name AS TABLENAME,round(BYTES/1024/1024,2)  FROM user_segments WHERE segment_name='表名 ...

  9. 关于parse_str变量覆盖分析

    这个漏洞有两个姿势.一个是不存在的时候一个是存在的时候. 经过测试该漏洞只在php5.2中存在,其余均不存在. 倘若在parse_str函数使用的代码上方未将其定义那么即存在变量覆盖漏洞否则不行. 还 ...

  10. 【Python学习】request库

    Requests库(https://www.python-requests.org/)是一个擅长处理那些复杂的HTTP请求.cookie.header(响应头和请求头)等内容的Python第三方库. ...