AC日记——The Child and Sequence codeforces 250D
思路:
因为有区间取模操作所以没法用标记下传;
我们发现,当一个数小于要取模的值时就可以放弃;
凭借这个来减少更新线段树的次数;
来,上代码:
#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的更多相关文章
- AC日记——Sagheer and Nubian Market codeforces 812c
C - Sagheer and Nubian Market 思路: 二分: 代码: #include <bits/stdc++.h> using namespace std; #defin ...
- AC日记——Red and Blue Balls codeforces 399b
399B - Red and Blue Balls 思路: 惊讶的发现,所有的蓝球的消除都是独立的: 对于在栈中深度为i的蓝球消除需要2^i次操作: 代码: #include <cstdio&g ...
- AC日记——Andryusha and Colored Balloons codeforces 780c
C - Andryusha and Colored Balloons 思路: 水题: 代码: #include <cstdio> #include <cstring> #inc ...
- AC日记——Little Elephant and Shifts codeforces 221e
E - Little Elephant and Shifts 思路: 一次函数线段树(疯狂debug): b不断循环左移,判断每次最小的|i-j|,a[i]=b[j]: 仔细观察发现,每个bi移动时, ...
- AC日记——Little Elephant and Problem codeforces 221c
221C 思路: 水题: 代码: #include <cstdio> #include <cstring> #include <iostream> #include ...
- AC日记——Little Elephant and Array codeforces 221d
221D - Little Elephant and Array 思路: 莫队: 代码: #include <cmath> #include <cstdio> #include ...
- AC日记——Little Elephant and Numbers codeforces 221b
221B - Little Elephant and Numbers 思路: 水题: 代码: #include <cmath> #include <cstdio> #inclu ...
- AC日记——Little Elephant and Function codeforces 221a
A - Little Elephant and Function 思路: 水题: 代码: #include <cstdio> #include <iostream> using ...
- 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 ...
随机推荐
- 《数据结构》C++代码 前言
现在大二正在上<数据结构>课,课内的书上代码实现很喜欢无脑用类.变量名字很长,而且常常实现太繁琐,并且代码有些无法运行,这些对于老手无所谓,但初学者看起来却会很不舒服.因此写点自己实现这些 ...
- WPF 利用键盘钩子来捕获键盘,做一些不为人知的事情...完整实例
键盘钩子是一种可以监控键盘操作的指令. 看到这句话是不是觉得其实键盘钩子可以做很多事情. 场景 当你的程序需要一个全局的快捷键时,可以考虑使用键盘钩子,如大家常用qq的截图快捷键,那么在WPF里怎么去 ...
- Python 3基础教程3-数学运算
本文来介绍下Python中的常见数学运算,其实和其他语言一样,加减乘除语法差不多,这里注意下Python中指数的表示方法. # 这里介绍 常见的数学运算 # 加法print(5 + 8) # 减法pr ...
- gradle构建
https://blog.csdn.net/baidu_30809315/article/details/77865414
- 1090 Highest Price in Supply Chain (25 分)(树的遍历)
求所有叶节点中的最高价以及这个价格的叶节点个数 #include<bits/stdc++.h> using namespace std; ; vector<int>mp[N]; ...
- vue 三目运算
:class="followed ? 'btn-success':'btn-secondary'"
- java连接Oracle数据库实现增删改查并在Navicat中显示
创建TEST表 eclipse中的java项目 代码 数据库方法类 DBUtil: package util; import java.sql.Connection; import java.sql. ...
- 想了一天的题目QAQ 毛线数列的最值
#include <cstdio> #include <cstring> #include <cmath> #include <iostream> #i ...
- 【bzoj3638】Cf172 k-Maximum Subsequence Sum 模拟费用流+线段树区间合并
题目描述 给一列数,要求支持操作: 1.修改某个数的值 2.读入l,r,k,询问在[l,r]内选不相交的不超过k个子段,最大的和是多少. 输入 The first line contains inte ...
- Java中类的继承深入剖析
在Java开发中,我们常常用到继承这一概念,可以说继承是Java这类面向对象编程语言的基石.正是有了继承这个概念,使得我们可以创建分等级层次的类.今天小编就和大家一起来深入聊聊Java语言的继承. 在 ...