D - The Child and Sequence

思路:

  因为有区间取模操作所以没法用标记下传;

  我们发现,当一个数小于要取模的值时就可以放弃;

  凭借这个来减少更新线段树的次数;

来,上代码:

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; #define maxn 100005
#define ll long long struct TreeNodeType {
ll l, r, mid, dis, max;
};
struct TreeNodeType tree[maxn << ]; ll n,m; inline void in(ll &now)
{
char Cget = getchar(); now = ;
while (Cget > '' || Cget < '') Cget = getchar();
while (Cget >= ''&&Cget <= '')
{
now = now * + Cget - '';
Cget = getchar();
}
} void tree_build(ll now, ll l, ll r)
{
tree[now].l = l, tree[now].r = r;
if (l == r)
{
in(tree[now].dis);
tree[now].max = tree[now].dis;
return;
}
tree[now].mid = l + r >> ;
tree_build(now << , l, tree[now].mid);
tree_build(now << | , tree[now].mid + , r);
tree[now].dis = tree[now << ].dis + tree[now << | ].dis;
tree[now].max = max(tree[now << ].max, tree[now << | ].max);
} void tree_to(ll now, ll to,ll x)
{
if (tree[now].l == tree[now].r)
{
tree[now].dis = x;
tree[now].max = x;
return;
}
if (to <= tree[now].mid) tree_to(now << , to, x);
else tree_to(now << | , to, x);
tree[now].dis = tree[now << ].dis + tree[now << | ].dis;
tree[now].max = max(tree[now << ].max, tree[now << | ].max);
} void tree_mod(ll now, ll l, ll r, ll x)
{
if (tree[now].max < x) return;
if (tree[now].l >= l&&tree[now].r <= r) tree[now].dis %= x, tree[now].max %= x;
if (tree[now].l == tree[now].r) return;
if (l <= tree[now].mid) tree_mod(now << , l, r, x);
if (r > tree[now].mid) tree_mod(now << |, l, r, x);
tree[now].dis = tree[now << ].dis + tree[now << | ].dis;
tree[now].max = max(tree[now << ].max, tree[now << | ].max);
//cout <<"^ "<< l << ' ' << r << ' ' << tree[now].dis << ' ' << tree[now].max << endl;
} ll tree_query(ll now, ll l, ll r)
{
if (tree[now].l == l&&tree[now].r == r) return tree[now].dis;
if (l > tree[now].mid) return tree_query(now << | , l, r);
else if (r <= tree[now].mid) return tree_query(now << , l, r);
else return tree_query(now << , l, tree[now].mid) + tree_query(now << | , tree[now].mid + , r);
} int main()
{
in(n), in(m);
tree_build(, , n);
ll op, u, v, x;
for (; m--;)
{
in(op),in(u),in(v);
if (op == ) printf("%lld\n", tree_query(, u, v));
if (op == ) in(x), tree_mod(, u, v, x);
if (op == ) tree_to(, u, v);
}
return ;
}

AC日记——The Child and Sequence codeforces 250D的更多相关文章

  1. AC日记——Sagheer and Nubian Market codeforces 812c

    C - Sagheer and Nubian Market 思路: 二分: 代码: #include <bits/stdc++.h> using namespace std; #defin ...

  2. AC日记——Red and Blue Balls codeforces 399b

    399B - Red and Blue Balls 思路: 惊讶的发现,所有的蓝球的消除都是独立的: 对于在栈中深度为i的蓝球消除需要2^i次操作: 代码: #include <cstdio&g ...

  3. AC日记——Andryusha and Colored Balloons codeforces 780c

    C - Andryusha and Colored Balloons 思路: 水题: 代码: #include <cstdio> #include <cstring> #inc ...

  4. AC日记——Little Elephant and Shifts codeforces 221e

    E - Little Elephant and Shifts 思路: 一次函数线段树(疯狂debug): b不断循环左移,判断每次最小的|i-j|,a[i]=b[j]: 仔细观察发现,每个bi移动时, ...

  5. AC日记——Little Elephant and Problem codeforces 221c

    221C 思路: 水题: 代码: #include <cstdio> #include <cstring> #include <iostream> #include ...

  6. AC日记——Little Elephant and Array codeforces 221d

    221D - Little Elephant and Array 思路: 莫队: 代码: #include <cmath> #include <cstdio> #include ...

  7. AC日记——Little Elephant and Numbers codeforces 221b

    221B - Little Elephant and Numbers 思路: 水题: 代码: #include <cmath> #include <cstdio> #inclu ...

  8. AC日记——Little Elephant and Function codeforces 221a

    A - Little Elephant and Function 思路: 水题: 代码: #include <cstdio> #include <iostream> using ...

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

随机推荐

  1. 超轻量级异步JS框架,别再让嵌套影响我们的优雅代码!

    1.异步JS的重要性 随着Web平台地位的提升,霸占着浏览器的JavaScript语言也成为了世界上最流行的语言之一,甚至通过Node.js进入了服务器编程领域.JavaScript的一个重要特性便是 ...

  2. runtime怎么添加属性、方法等

    ivar表示成员变量 class_addIvar class_addMethod class_addProperty class_addProtocol class_replaceProperty

  3. 《Cracking the Coding Interview》——第13章:C和C++——题目8

    2014-04-25 20:27 题目:实现一个能够通过引用计数来实现自动回收数据的智能指针,用C++,不是java. 解法:这题真心牛,我的第一反应是发呆,因为对引用计数的了解仅限于这个名词,完全没 ...

  4. 《Cracking the Coding Interview》——第8章:面向对象设计——题目6

    2014-04-23 22:57 题目:实现一个数据结构来表示拼图游戏中的碎片. 解法:一个拼图块儿有四条边,每边只有凹凸平三种情况,当两块碎片拼接的时候,分为四个方向进行,块儿上的图案肯定也是判断是 ...

  5. 《Cracking the Coding Interview》——第5章:位操作——题目6

    2014-03-19 06:24 题目:将一个整数的奇偶二进制位交换,(0, 1) (2, 3) ... 解法:使用掩码来进行快速交换,定义掩码为'0101...'和‘1010...’. 代码: // ...

  6. HTTP响应码

    更详细的内容参考:https://baike.baidu.com/item/HTTP状态码/5053660?fr=aladdin 转载CSDN作者:ddhsea 的文章 https://blog.cs ...

  7. Python 自学 Day1

    作业二:编写登陆接口 输入用户名密码 认证成功后显示欢迎信息 输错三次后锁定 #!/usr/bin/env python import getpass def log(): uname = input ...

  8. python_ 运算符与分支结构

    # 运算符与分支结构 ### 运算符 - 赋值运算符 - 用'='表示,左边只能是变量. - 算术运算符 - +.-.*:加.减.乘 - /:除法运算,结果是浮点数 - //:除法运算,结果是整数 - ...

  9. centos 7 安装codeblocks

    CentOS7安装Code::Blocks 在CentOS7上安装Codelocks的过程. 1.安装gcc,需要c和c++两部分,默认安装下,CentOS不安装编译器的,在终端输入以下命令即可yum ...

  10. chrome性能指标(TTFB,TTSR,TTDC,TTFL)

    1.TTFB (Time To First Byte) 是最初的网络请求被发起到从服务器接收到第一个字节这段时间,它包含了 TCP连接时间,发送HTTP请求时间和获得响应消息第一个字节的时间. 注意: ...