Codeforces传送门

洛谷传送门

题意翻译

给定数列,区间查询和,区间取模,单点修改。

n,m≤105n,m≤105n,m\le 10^5

题目描述

At the children’s day, the child came to Picks’s house, and messed his house up. Picks was angry at him. A lot of important things were lost, in particular the favorite sequence of Picks.

Fortunately, Picks remembers how to repair the sequence. Initially he should create an integer array a[1],a[2],...,a[n]a[1],a[2],...,a[n]a[1],a[2],...,a[n] . Then he should perform a sequence of mm operations. An operation can be one of the following:

  1. Print operation l,rl,rl,r . Picks should write down the value of .
  2. Modulo operationl,r,xl,r,x l,r,x. Picks should perform assignment a[i]=a[i] mod xa[i]=a[i]modx a[i]=a[i]\ \mathrm{mod}\ x for each iii (l≤i≤r)" role="presentation" style="position: relative;">(l≤i≤r)(l≤i≤r)(l\le i\le r) .
  3. Set operation k,xk,xk,x . Picks should set the value of a[k]a[k]a[k] to xxx (in other words perform an assignment a[k]=x" role="presentation" style="position: relative;">a[k]=xa[k]=xa[k]=x).

Can you help Picks to perform the whole sequence of operations?

输入输出格式

输入格式:

The first line of input contains two integer: n,mn,mn,m (1≤n,m≤1051≤n,m≤1051\le n,m\le 10^{5}) . The second line contains nnn integers, separated by space: a[1],a[2],...,a[n](1≤a[i]≤109)" role="presentation" style="position: relative;">a[1],a[2],...,a[n](1≤a[i]≤109)a[1],a[2],...,a[n](1≤a[i]≤109) a[1],a[2],...,a[n] (1\le a[i]\le 10^{9}) — initial value of array elements.

Each of the next mmm lines begins with a number type" role="presentation" style="position: relative;">typetypetype .

  • If type=1type=1type=1 , there will be two integers more in the line: l,r(1≤l≤r≤n)l,r(1≤l≤r≤n) l,r (1\le l\le r\le n) , which correspond the operation 111.
  • If type=2" role="presentation" style="position: relative;">type=2type=2type=2 , there will be three integers more in the line: l,r,x(1≤l≤r≤n;1≤x≤109)l,r,x(1≤l≤r≤n;1≤x≤109)l,r,x (1\le l\le r\le n; 1\le x\le 10^{9}) , which correspond the operation 2.
  • If type=3type=3type=3 , there will be two integers more in the line: k,x(1≤k≤n;1≤x≤109)k,x(1≤k≤n;1≤x≤109)k,x (1\le k\le n; 1\le x\le 10^{9}) , which correspond the operation 3.

输出格式:

For each operation 1, please print a line containing the answer. Notice that the answer may exceed the 32-bit integer.

输入输出样例

输入样例#1:

5 5
1 2 3 4 5
2 3 5 4
3 3 5
1 2 5
2 1 3 3
1 1 3

输出样例#1:

8
5

输入样例#2:

10 10
6 9 6 7 6 1 10 10 9 5
1 3 9
2 7 10 9
2 5 10 8
1 4 7
3 3 7
2 7 9 9
1 2 4
1 6 6
1 5 9
3 1 10

输出样例#2:

49
15
23
1
9

样例解释

对于样例#1:

  • At first, a = {1, 2, 3, 4, 5}.
  • After operation 1, a = {1, 2, 3, 0, 1}.
  • After operation 2, a = {1, 2, 5, 0, 1}.
  • At operation 3, 2 + 5 + 0 + 1 = 8.
  • After operation 4, a = {1, 2, 2, 0, 1}.
  • At operation 5, 1 + 2 + 2 = 5.

解题分析

考虑每次取模后, 如果当前数值比模数大, 则肯定取模后的值至少比原来少一半, 因此不考虑单点修改的话每个数字最多修改log(N)log(N)log(N)次。 所以总复杂度为O(Nlog2(N))O(Nlog2(N))O(Nlog^2(N))。

我们维护一个区间最大值, 如果当前区间最大值<<<script type="math/tex" id="MathJax-Element-41"><</script>模数, 则直接returnreturnreturn。

代码如下:

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <algorithm>
#define R register
#define IN inline
#define gc getchar()
#define W while
#define MX 100050
#define ll long long
#define ls (now << 1)
#define rs (now << 1 | 1)
template <class T>
IN void in(T &x)
{x = 0; R char c = gc;W (!isdigit(c)) c = gc;W (isdigit(c))x = (x << 1) + (x << 3) + c - 48, c = gc;
}
int dot, q;
ll dat[MX], MOD;
struct Node
{ll sum, mx;} tree[MX << 5];
namespace SGT
{IN void pushup(const int &now){tree[now].mx = std::max(tree[ls].mx, tree[rs].mx);tree[now].sum = tree[ls].sum + tree[rs].sum;}void build(const int &now, const int &lef, const int &rig){if(lef == rig) return tree[now].mx = tree[now].sum = dat[lef], void();int mid = lef + rig >> 1;build(ls, lef, mid), build(rs, mid + 1, rig);pushup(now);}void modify(const int &now, const int &lef, const int &rig, const int &tar, const ll &del){if(lef == rig) return tree[now].mx = tree[now].sum = del, void();int mid = lef + rig >> 1;if(tar <= mid) modify(ls, lef, mid, tar, del);else modify(rs, mid + 1, rig, tar, del);pushup(now);}void mod(const int &now, const int &lef, const int &rig, const int &lb, const int &rb){if(tree[now].mx < MOD) return;if(lef == rig) return tree[now].sum = tree[now].mx = tree[now].sum % MOD, void();int mid = lef + rig >> 1;if(lb <= mid) mod(ls, lef, mid, lb, rb);if(rb > mid) mod(rs, mid + 1, rig, lb, rb);pushup(now);}IN ll query(const int &now, const int &lef, const int &rig, const int &lb, const int &rb){if(lef >= lb && rig <= rb) return tree[now].sum;int mid = lef + rig >> 1; ll ret = 0;if(lb <= mid) ret += query(ls, lef, mid, lb, rb);if(rb > mid) ret += query(rs, mid + 1, rig, lb, rb);return ret;}
}
int main(void)
{int typ, a, b; ll c;in(dot), in(q);for (R int i = 1; i <= dot; ++i) in(dat[i]);SGT::build(1, 1, dot);W (q--){in(typ);if(typ == 1){in(a), in(b);printf("%I64d\n", SGT::query(1, 1, dot, a, b));}else if(typ == 2){in(a), in(b), in(MOD);SGT::mod(1, 1, dot, a, b);}else{in(a), in(c);SGT::modify(1, 1, dot, a, c);}}
}

[Codeforces Round #250 (Div. 1) -D] The Child and Sequence相关推荐

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

  2. Codeforces Round #250 (Div. 2) A - The Child and Homework

    传送门Codeforces Round #250 (Div. 2) A - The Child and Homework 第一次做完之后交上去,过了例子.顺手就锁定了...然后一个小时之后就被HACK ...

  3. Codeforces Round #250 (Div. 2)—A. The Child and Homework

         好题啊,被HACK了.曾经做题都是人数越来越多.这次比赛 PASS人数 从2000直掉 1000人  被HACK  1000多人! ! ! ! 没见过的科技啊 1 2 4 8 这组数 被黑的 ...

  4. Codeforces Round 250(Div. 2)

    layout: post title: Codeforces Round 250 (Div. 2) author: "luowentaoaa" catalog: true tags ...

  5. Codeforces Round #250 (Div. 2) (ABCD题解)

    比赛链接:http://codeforces.com/contest/437 A. The Child and Homework time limit per test:1 second memory ...

  6. Codeforces Round #529 (Div. 3) E. Almost Regular Bracket Sequence (括号配对,前缀和)

    翻转一个括号使得所有括号都能配对,问一共可以翻转几个括号. AC 方法1: 如果某个位置上的右括号数量大于他的左括号的数量那么这个位置及之后的位置无论如何翻转都不能满足配对. 例如:())((() 第 ...

  7. 【Christmas Game】【CodeCraft-21 and Codeforces Round #711 (Div. 2)】【Nim-博弈】【树形DP】【拆分树】

    CodeCraft-21 and Codeforces Round #711 (Div. 2) Christmas Game Nim-博弈 树形DP 拆分树 牛客链接 https://ac.nowco ...

  8. Educational Codeforces Round 112(Div.2) ABC题解

    D题好像可以做一做,挖个坑以后做好了来填(doge Educational Codeforces Round 112(Div.2) 题目列表 1.A 2.B 3.C 1.A 原题链接 题目大意 有三种 ...

  9. Codeforces Round #400 (Div. 1 + Div. 2, combined) 776E. The Holmes Children(待翻译)

    Codeforces Round #241 (Div. 2) 514C Watto and Mechanism ≤,≠,≥<> 时间限制:1S / 空间限制:256MB [在线测试提交传送 ...

最新文章

  1. 竞赛老陪跑怎么办?来自一位Kaggle比赛失败者的含泪总结
  2. 10-05索引的创建和使用
  3. linux logrotate进行日志分割
  4. 预算1000以内,可以买哪些手机?
  5. 三维点云学习(3)6- 实现K-Means
  6. java技术大牛之路
  7. K-th Number Poj - 2104 主席树
  8. 股票交易数据下载 | 下载股票历史交易数据到本地Excel
  9. PS视频教程|photoshop视频教程零基础入门到精通
  10. 群晖虚拟机VMM定时开启
  11. Photoshop脚本 镜头光晕滤镜的使用
  12. android游戏工作心得体会,幼儿园游戏的心得体会(精选6篇)
  13. openwrt路由器安装Transmission软件包与web控制台(中文界面)
  14. 内存泄漏的原因及解决方法
  15. left函数未定义_access中LEFT函数未定义的解决方案\表达式中'left'函数未定义。
  16. Android获取手机设备识别码(IMEI)和手机号码
  17. 一文分析 Web3 尚未被主流采用的 6 个主要原因
  18. html拖动控件详解
  19. Redis 的 hash,及其序列化问题
  20. php php拼接字符串函数_PHP常见字符串操作函数与用法总结

热门文章

  1. 我的世界有宠物系统的服务器,我的世界:养宠物,玩科技,全新的游戏玩法等你来...
  2. chemkin 使用C3H8/空气在对冲里燃烧
  3. 今天在csdn看到一博主今年大三,初中就喜欢上编程,学习了各种知识,初中…挺震惊。不禁细数我的编程史,挺有感。
  4. Matlab修改单位、说明和表变量名称
  5. 完美解决Mac系统下Chrome插件安装时程序包无效:CRX_HEADER_INVALID
  6. 发那科机器人电柜没电怎么回事_发那科数控机床电池没电导致程序丢失如何恢复...
  7. keil + STM32CubeMX 开发stm32L0 踩坑
  8. IDC数据中心相关业务简单介绍
  9. [转载] Linux 内核进程详解之二: bdi-default
  10. 基于 Laravel PHP 框架的房地产管理系统