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 ...
随机推荐
- laravel5.5任务调度
目录 1. 定义调度 1.1 使用Closure 1.2 Artisan 命令调度 1.3 队列任务调度 1.4 Shell 命令调度 1.5 调度频率设置 1.6 闭包测试限制 1.7 避免任务重复 ...
- centos使用--开机启动
centos6.8 1.利用 chkconfig 来配置启动级别 在CentOS或者RedHat其他系统下,如果是后面安装的服务,如httpd.mysqld.postfix等,安装后系统默认不会自动启 ...
- Xcode 代码提示功能失效
前言: 以前好像很少碰到Xcode中代码提示出问题的情况,最近经常遇到这个问题.没有了Xcode的智能提示,发现我已完全不会写代码了. 本来想吐槽下万恶的baidu,鉴于百度前端时间的各种(贴吧.竞价 ...
- NOIP2018 集训(一)
A题 Simple 时间限制:1000ms | 空间限制:256MB 问题描述 对于给定正整数\(n,m\),我们称正整数\(c\)为好的,当且仅当存在非负整数\(x,y\)使得\(n×x+m×y=c ...
- React01
目录 React-day01 入门知识 React介绍 官网 React开发环境初始化 SPA 脚手架初始化项目(方便,稳定)* 通过webpack进行初始化 配置镜像地址 开发工具配置 元素渲染 组 ...
- 放映PPT幻灯片演示文稿如何让演讲者备注不投影到屏幕上(转载)
ps files/ps.rar 放映PPT幻灯片演示文稿如何让演讲者备注不投影到屏幕上 如题,在PPT幻灯片的演示文稿中加入演讲者备注(使用PPT讲座时苦于有时会忘记一些要讲的数字,文字等),但是在 ...
- linux fork()函数 转载~~~~
转自 :: http://blog.csdn.net/jason314/article/details/5640969 一.fork入门知识 一个进程,包括代码.数据和分配给进程的资源.fork ...
- spring 配置问题记录1-@ResponseBody和favorPathExtension
在搭建springmvc+easyui的项目时,有一个地方参照网上说的方法一直没实现出来, 就是前台的datagrid的数据渲染不上去, 尝试了好多种方法,包括也找了目前手里的项目来进行比较,也没发现 ...
- web自动化测试:watir+minitest(五)
测试报告: 加载minitest-reporters库,并设置相关的参数.既可以在每次运行测试后生成响应的测试报告. 默认会生成一份html的报告在当前目录的test目录下 我们可以指定参数对报告的标 ...
- 【bzoj2097】[Usaco2010 Dec]Exercise 奶牛健美操 二分+贪心
题目描述 Farmer John为了保持奶牛们的健康,让可怜的奶牛们不停在牧场之间 的小路上奔跑.这些奶牛的路径集合可以被表示成一个点集和一些连接 两个顶点的双向路,使得每对点之间恰好有一条简单路径. ...