Codefroces 920F SUM and REPLACE(线段树)
题意:给你n个数,进行m次操作,分别是将区间[l,r]内的所有数替换成自己的因子数 和 对区间[l,r]进行求和。
题解:可以发现2的因子个数还是2,1的因子个数还是1,所以如果某个数被更新成1或者2之后就不需要再进行更新了。
#include<bits/stdc++.h>
#define ll long long
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
using namespace std;
const int N = 3e5+;
const int M = 1e6+;
ll tree[N<<];
bool ok[N<<];
int num[M], a[N];
int n, m;
void PushUp(int rt)
{
tree[rt] = tree[rt<<] + tree[rt<<|];
ok[rt] = ok[rt<<] && ok[rt<<|];
}
void Build(int l, int r, int rt)
{
if(l == r)
{
tree[rt] = a[l];
if(tree[rt] == || tree[rt] == ) ok[rt] = ;
else ok[rt] = ;
return ;
}
int m = l+r >> ;
Build(lson);
Build(rson);
PushUp(rt);
}
ll Query(int L, int R, int l, int r, int rt)
{
if(L <= l && r <= R)
return tree[rt];
int m = l+r >> ;
ll ans = ;
if(L <= m) ans += Query(L,R,lson);
if(m < R) ans += Query(L,R,rson);
return ans;
} void Revise(int L, int R, int l, int r, int rt)
{
if(ok[rt]) return ;
if(l == r)
{
tree[rt] = num[tree[rt]];
if(tree[rt] == || tree[rt] == ) ok[rt] = ;
return ;
}
int m = l+r >> ;
if(L <= m) Revise(L,R,lson);
if(m < R) Revise(L,R,rson);
PushUp(rt);
}
int main()
{
ios::sync_with_stdio(false);
cin.tie();
cout.tie();
memset(num, , sizeof(num));
for(int i = ; i < M; i++)
for(int j = i; j < M; j+=i)
num[j]++;
cin >> n >> m;
for(int i = ; i <= n; i++)
cin >> a[i];
Build(,n,);
int q, l, r;
while(m--)
{
cin >> q >> l >> r;
if(q == )
cout << Query(l,r,,n,) << endl;
else
Revise(l,r,,n,);
}
return ;
}
Codefroces 920F SUM and REPLACE(线段树)的更多相关文章
- 【Educational Codeforces Round 37】F. SUM and REPLACE 线段树+线性筛
题意 给定序列$a_n$,每次将$[L,R]$区间内的数$a_i$替换为$d(a_i)$,或者询问区间和 这题和区间开方有相同的操作 对于$a_i \in (1,10^6)$,$10$次$d(a_i) ...
- CF920F SUM and REPLACE 线段树
给你一个数组a_i,D(x)为x的约数个数 两种操作: 1.将[l,r]的a_i替换为D(a_i) 2.输出∑a_i ( l <= i <= r ) 当区间最大值<=2时,就不 ...
- Codeforces 920F - SUM and REPLACE
920F - SUM and REPLACE 思路1: 线段树(982 ms) 每个点最多更新6次 代码: #include<bits/stdc++.h> using namespace ...
- codeforces 1217E E. Sum Queries? (线段树
codeforces 1217E E. Sum Queries? (线段树 传送门:https://codeforces.com/contest/1217/problem/E 题意: n个数,m次询问 ...
- 2018.12.15 codeforces 920F. SUM and REPLACE(线段树)
传送门 线段树入门题. 给你一个序列:支持区间修改成自己的约数个数,区间求和. 实际上跟区间开方一个道理. 2的约数个数为2,1的约数个数为1,因此只要区间的最大值小于3就不用修改否则就暴力修改. 因 ...
- CodeForces - 920F SUM and REPLACE (线段树)
题意:给N个数M次操作,(1<=N,M<=3e5, 1<=ai<=1e6),1是使[L,R]中的每个元素变成其因子的个数之和:2是求[L,R]区间之和 分析:看上去就很线段树的 ...
- Yandex.Algorithm 2011 Round 1 D. Sum of Medians 线段树
题目链接: Sum of Medians Time Limit:3000MSMemory Limit:262144KB 问题描述 In one well-known algorithm of find ...
- Codeforces 85D Sum of Medians(线段树)
题目链接:Codeforces 85D - Sum of Medians 题目大意:N个操作,add x:向集合中加入x:del x:删除集合中的x:sum:将集合排序后,将集合中全部下标i % 5 ...
- 【BZOJ4262】Sum 单调栈+线段树
[BZOJ4262]Sum Description Input 第一行一个数 t,表示询问组数. 第一行一个数 t,表示询问组数. 接下来 t 行,每行四个数 l_1, r_1, l_2, r_2. ...
随机推荐
- 2019.7 佳木斯培训A层
day1题目及题解 day2题目及题解 day3题目及题解 day4题目及题解 day5题目及题解
- 用python twilio模块实现发手机短信的功能
前排提示:这个模块不是用于对陌生人进行短信轰炸和电话骚扰的,这个模块也没有这个功能,如果是抱着这个心态来的,可以关闭网页了 语言:python 步骤一:安装twilio模块 pip install t ...
- Linux中更新firefox
从官网下载Firefox压缩包放在/usr/lib/目录下(应用程序一般都在这个文件夹下) tar jxfv [压缩包名] 解压得到文件夹firefox在解压得到的firefox文件夹中有一个fir ...
- web渗透---第二天
协议常识 HTTP协议 百度百科的解释:超文本传输协议(HTTP,HyperText Transfer Protocol)是互联网上应用最为广泛的一种网络协议. 所有的WWW文件都必须遵守这个标准. ...
- 使用 Docker 生成 Let’s Encrypt 证书
概念 什么是 Container ? https://www.docker.com/resources/what-container https://www.docker.com/why-docker ...
- Hibernate 框架
首先,我们先来了解一下什么是 Hibernate 框架. 什么是 Hibernate 框架? Hibernate是一个开放源代码的对象关系映射框架,它对JDBC进行了非常轻量级的对象封装,它将POJO ...
- Postman系列一:Postman安装及使用过程中遇到的问题
一:Postman的简介.下载安装及界面说明 1.Postman的简单介绍 Postman是一款强大的网页调试和发送网页HTTP请求的工具,Postman让开发和测试人员做API(接口)测试变得更加简 ...
- 后端小白的VUE入门笔记, 进阶篇
使用 vue-cli( 脚手架) 搭建项目 基于vue-cli 创建一个模板项目 通过 npm root -g 可以查看vue全局安装目录,进而知道自己有没有安装vue-cli 如果没有安装的话,使用 ...
- Android 打包时 Keep 住某些方法或类
# ${android_sdk}/tools/proguard/proguard-android.txt # Understand the @Keep support annotation. -kee ...
- windwos环境下安装python2和python3
一 python安装 下载地址: https://www.python.org/downloads/ 环境变量:Path中添加C:\Python27\Scripts\;C:\Python27\; C: ...