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 ...
随机推荐
- mutable c++
The keyword mutable is used to allow a particular data member of const object to be modified. This i ...
- Tomcat详解及SNS系统的部署实现
Tomcat详解及SNS系统的部署实现 http://jungege.blog.51cto.com/4102814/1409290
- iphone 8 plus 红色特别版,突然自动关机无法启动
今天早上我的iphone 8p 突然自己在床上闪动开机图标,闪了半个多小时它就光荣的自动关机了,我尝试了长按开机键,长按home+开机键15秒,通通木有用,它就是没!反!应! 于是找了售后,学到了正确 ...
- 【2017】KK English
2017/11/24 Regardless of the enormous amount of photos shared on Wechat or Face book, modern city dw ...
- tomcat集群和负载均衡的实现(session同步)
(一)环境说明 (1)服务器有4台,一台安装apache,三台安装tomcat (2)apache2.0.55.tomcat5.5.15.jk2.0.4.jdk1.5.6或jdk1.4.2 (3) ...
- 【现代程序设计】homework-01
HOMEWORK-01 1) 建立 GitHub 账户, 把课上做的 “最大子数组之和” 程序签入 已完成. 2) 在 cnblogs.com 建立自己的博客. 写博客介绍自己的 GitHub 账户. ...
- Android记事本开发01
今天: 学习一下Android的基本知识,了解一下记事本开发大概需要哪些知识. 昨天: 无 遇到的问题:
- Java -- Matrix的一点认识
例如在如下一段代码中: Matrix m = new Matrix(2,3); for(int i=0; i<m.getRowDimension(); i++) { for(int j=0; j ...
- Solidity陷阱:以太坊的随机数生成
title: Solidity陷阱:以太坊的随机数生成 Solidity是一种相当新的语言,因为没有代码是完美的,它包含与代码相关的问题以及你希望用它完成的任务.本文将指导你使用随机数作为以太坊智能合 ...
- 了解腾讯开源的多渠道打包技术 VasDolly源码解析
一.概要 大家应该都清楚,大家上线app,需要上线各种平台,比如:小米,华为,百度等等等等,我们多数称之为渠道,如果发的渠道多,可能有上百个渠道. 针对每个渠道,我们希望可以获取各个渠道的一些独立的统 ...