给你一个数组a_i​,D(x)为x的约数个数

两种操作:

1.将[l,r]的a_i​替换为D(a_i)

2.输出∑​a_i ( l <= i <= r )

当区间最大值<=2时,就不会被修改了,因为d(2)=2,d(1)=1。

#include<cstdio>
#include<iostream>
#define R register int
#define ls (tr<<1)
#define rs (tr<<1|1)
const int M=;
using namespace std;
inline long long g() {
register long long ret=,fix=; register char ch; while(!isdigit(ch=getchar())) fix=ch=='-'?-:fix;
do ret=ret*+(ch^); while(isdigit(ch=getchar())); return ret*fix;
}
int n,m;
long long sum[],mx[],cnt[];
inline void upd(int tr) {sum[tr]=sum[ls]+sum[rs]; mx[tr]=max(mx[ls],mx[rs]);}
inline void calc() {for(R i=;i<=M;++i) for(R j=;i*j<=M;++j) ++cnt[i*j];}
inline void build(int tr,int l,int r) {
if(l==r) {mx[tr]=sum[tr]=g(); return ;}
R md=(l+r)>>; build(ls,l,md),build(rs,md+,r); upd(tr);
}
inline void change(int tr,int l,int r,int LL,int RR) {
if(mx[tr]<=) return ;
if(l==r) {sum[tr]=mx[tr]=cnt[sum[tr]]; return ;}
R md=(l+r)>>;
if(LL>md) change(rs,md+,r,LL,RR);
else if(RR<md+) change(ls,l,md,LL,RR);
else change(ls,l,md,LL,md),change(rs,md+,r,md+,RR); upd(tr);
}
inline long long query(int tr,int l,int r,int LL,int RR) {
if(l==LL&&r==RR) return sum[tr];
R md=(l+r)>>;
if(LL>md) return query(rs,md+,r,LL,RR);
else if(RR<md+) return query(ls,l,md,LL,RR);
else return query(ls,l,md,LL,md)+query(rs,md+,r,md+,RR);
}
signed main() {
n=g(),m=g(); calc(); build(,,n);
for(R i=,k,l,r;i<=m;++i) {
k=g(),l=g(),r=g();
if(k==) change(,,n,l,r);
else printf("%lld\n",query(,,n,l,r));
}
}

2019.04.18

CF920F SUM and REPLACE 线段树的更多相关文章

  1. 【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) ...

  2. codeforces 1217E E. Sum Queries? (线段树

    codeforces 1217E E. Sum Queries? (线段树 传送门:https://codeforces.com/contest/1217/problem/E 题意: n个数,m次询问 ...

  3. Yandex.Algorithm 2011 Round 1 D. Sum of Medians 线段树

    题目链接: Sum of Medians Time Limit:3000MSMemory Limit:262144KB 问题描述 In one well-known algorithm of find ...

  4. Codeforces 85D Sum of Medians(线段树)

    题目链接:Codeforces 85D - Sum of Medians 题目大意:N个操作,add x:向集合中加入x:del x:删除集合中的x:sum:将集合排序后,将集合中全部下标i % 5 ...

  5. 【BZOJ4262】Sum 单调栈+线段树

    [BZOJ4262]Sum Description Input 第一行一个数 t,表示询问组数. 第一行一个数 t,表示询问组数. 接下来 t 行,每行四个数 l_1, r_1, l_2, r_2. ...

  6. CF1217E Sum Queries? (线段树)

    完了,前几天才说 edu 的 DEF 都不会,现在打脸了吧 qwq 其实在刚说完这句话 1min 就会了 D,3min 就会了 E 发现,对于大小 \(\ge 3\) 的不平衡集合,它至少有一个大小为 ...

  7. codeforces 85D D. Sum of Medians 线段树

    D. Sum of Medians time limit per test 3 seconds memory limit per test 256 megabytes input standard i ...

  8. leetcode@ [307] Range Sum Query - Mutable / 线段树模板

    Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive ...

  9. [tem]线段树练习

    1080 线段树练习 单点修改,区间查询和 #include <iostream> #include <cstdio> #include <algorithm> # ...

随机推荐

  1. ES6 Set数据结构

    Set ES6 提供了新的数据结构 Set.它类似于数组,但是成员的值都是唯一的,没有重复的值. const s = new Set(); // const声明一个只读的常量.一旦声明,常量的值就不能 ...

  2. gVim/Vim 一键编译、连接、运行 C/C++ 单文件

    用于Gvim 或 Vim 配置文件的一键编译与运行函数(注:需要机器上安装了GCC才行) 本代码只加入了对C/C++的编译与运行,如果要加入其语言的可以参考此代码加入即可 同时,本代码加入了对Wind ...

  3. 截取带HTML标签的文本并保留文本样式

    一个截取HTML文本的工具,可以按照文字字数或文字字节长度进行截取,保留HTML样式并在最后自动补齐截取后的标签.按工作要求编写,时间紧迫,代码未优化,欢迎讨论和指正.​1. [文件] SubHtml ...

  4. 有时候,Visual C++代码中加中文注释会导致错误!

    今天做题发现了个奇葩错误,以此警戒自己. 张某,做的一道题. --------------------------------------------------------------------- ...

  5. codeforces 703D D. Mishka and Interesting sum(树状数组)

    题目链接: D. Mishka and Interesting sum time limit per test 3.5 seconds memory limit per test 256 megaby ...

  6. MySQL记录_20160919

    1.首先先看下什么是MySQL. MySQL是一个关系型数据库管理系统,由瑞典MySQL AB 公司开发,目前属于 Oracle 旗下产品.MySQL 最流行的关系型数据库管理系统,其开放源码这一特点 ...

  7. 使用Tornado作为Django App的服务器

    闲来无事,折腾折腾. 老是听说tonado是个异步web框架和服务器,作为框架倒是了解到了,但是服务器一直不太懂.所以决定了解一下,既然可以做服务器,那就把自己的django app部署到这上边去. ...

  8. 百度地图API的第一次接触

    因为项目的需求,第一次接触了百度API. 第一步:引用百度地图API的脚本 如果在局域网环境中,要把地图文件和js文件都要下载下来 <script type="text/javascr ...

  9. 为BindingList添加Sort

    最近在优化WPF性能时, 发现在特定条件下BindingList比ObservableCollection性能更高, 因为它提供Disable/Enable 更改通知的方法.这样我们可以不需要很频繁的 ...

  10. [xdoj1233]Glory and LCS

    题意:求两个排列的最长公共子序列n<=1e5 解题关键:转化为LIS. 最长公共子序列 的 nlogn 的算法本质是 将该问题转化成 最长增序列(LIS),因为 LIS 可以用nlogn实现,所 ...