题意:

给定一个长度为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. CSS盒子知识

    此随笔写于学习完CSS盒子之后,所遇到的问题和感悟记录. 1.IE盒子: IE盒子的特性:对于IE浏览器来说width不是内容宽度.而是内容+外边距+边框的内容总和. 也就是说当盒子增加10px;那么 ...

  2. Python学习笔记(三十九)— 内置模块(8)XML基础

    摘抄自:https://www.liaoxuefeng.com/wiki/0014316089557264a6b348958f449949df42a6d3a2e542c000/001432002075 ...

  3. js_beautifier && css_beautifier for emeditor

    // // Unpacker for Dean Edward's p.a.c.k.e.r, a part of javascript beautifier // written by Einar Li ...

  4. 基本控件文档-UITableView---iOS-Apple苹果官方文档翻译

    //转载请注明出处--本文永久链接:http://www.cnblogs.com/ChenYilong/p/3496969.html 技术博客http://www.cnblogs.com/ChenYi ...

  5. 天梯赛 L1-006 连续因子 (模拟)

    一个正整数N的因子中可能存在若干连续的数字.例如630可以分解为356*7,其中5.6.7就是3个连续的数字.给定任一正整数N,要求编写程序求出最长连续因子的个数,并输出最小的连续因子序列. 输入格式 ...

  6. tf.reduce_sum()_tf.reduce_mean()_tf.reduce_max()

    根据官方文档: reduce_sum应该理解为压缩求和,用于降维 tf.reduce_sum(input_tensor,axis=None,keepdims=None,name=None,reduct ...

  7. 生产环境手把手部署ERC20智能合约

    工具 rimex http://remix.ethereum.org/ metamask https://metamask.io/ ERC20 代码 https://github.com/OpenZe ...

  8. python基础===数据伪造模块faker

    介绍文档: https://pypi.org/project/Faker/ https://faker.readthedocs.io/en/latest/ https://faker.readthed ...

  9. queue_delayed_work和queue_work区别 (转http://blog.csdn.net/dosculler/article/details/7968101)

    queue_delayed_work和queue_work 一.参考文献: 1)http://www.linuxidc.com/Linux/2011-08/41655.htm queue_delaye ...

  10. AttributeError: 'str' object has no attribute 'decode'

    ue = e.decode('latin-1')修改为: ue = e.encode('ascii', 'strict')