一、题目

二、题目链接

  http://codeforces.com/contest/920/problem/F

三、题意

  给定$N$个范围在$[1, 1e6)$的数字和$M$个操作。操作有两种类型:

  $1$ $l$ $r$:更新区间$[l$, $r]$的数字ai为d[ai]。其中d[i]表示数字i的因子的个数。如:d[1] = 1, d[2] = 2, d[3] = 2, d[4] = 3。

  $2$ $l$ $r$:查询区间$[l, r]$的数字和并输出。

四、思路

  典型的数据结构题。很明显这是线段树的菜。

  对于线段树的每个节点,维护所“管辖”区间的和值和最大值。

  更新时,如果当前区间的最大值$maxv<=2$,那么,不需要往下更新下去了。因为$d[1] = 1$, $d[2] = 2$。否则,继续更新下去。这样并不会超时,因为对于一个范围在$[1, 1e6)$的数字而言,反复做$i = d[i]$这样的操作,次数并不会太多。

  另外,更新完子区间后,要做上推合并操作。这是线段树很常见的操作。

五、源代码

  

#pragma GCC optimize(2)
#pragma comment(linker, "/STACK:102400000, 102400000")
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
;

template <class T> inline void read(T &x) {
    int t;
    bool flag = false;
    ')) ;
    ';
     + t - ';
    if(flag) x = -x;
}

typedef struct {
    LL maxv, sum;
} Node;
Node data[MAXN * ];
 << ], n, q;
void init() {
    ;
    ; i <= N; ++i) {
        for(int j = i; j <= N; j += i)
            d[j]++;
    }
    memset(data, , sizeof(data));
}

void pushup(int root){
    data[root].sum = data[root << ].sum + data[root <<  | ].sum;
    data[root].maxv = max(data[root << ].maxv, data[root <<  | ].maxv);
}

, , int r = n) {
    if(l > x || r < x)return;
    if(l == r && l == x) {
        data[root].sum = data[root].maxv = LL(val);
        return;
    }
    ;
    , l, mid);
     | , mid + , r);
    pushup(root);
}

, , int r = n) {
    if(l > r || l > ur || r < ul)return;
    if(ul <= l && ur >= r && data[root].maxv <= 2LL)return;
    if(l == r) {
        data[root].sum = data[root].maxv = LL(d[data[root].sum]);
        return;
    }
    ;
    , l, mid);
     | , mid + , r);
    pushup(root);
}

LL query(, , int r = n) {
    if(l > r || l > qr || r < ql)return 0LL;
    if(ql <= l && qr >= r)return data[root].sum;
    ;
    , l, mid) + query(ql, qr, root <<  | , mid + , r);
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("Finput.txt", "r", stdin);
#endif // ONLINE_JUDGE
    init();
    int tmp, type, l, r;
    scanf("%d%d", &n, &q);
    ; i <= n; ++i){
        read(tmp);
        build(i, tmp);
    }
    while(q--){
        read(type), read(l), read(r);
        )update(l, r);
        else printf("%lld\n", query(l, r));
    }
    ;
}

Educational Codeforces Round 37-F.SUM and REPLACE题解的更多相关文章

  1. 【Educational Codeforces Round 37 F】SUM and REPLACE

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 那个D函数它的下降速度是很快的. 也就是说到最后他会很快的变成2或者1 而D(2)==2,D(1)=1 也就是说,几次操作过后很多数 ...

  2. Educational Codeforces Round 37

    Educational Codeforces Round 37 这场有点炸,题目比较水,但只做了3题QAQ.还是实力不够啊! 写下题解算了--(写的比较粗糙,细节或者bug可以私聊2333) A. W ...

  3. Educational Codeforces Round 37 (Rated for Div. 2)C. Swap Adjacent Elements (思维,前缀和)

    Educational Codeforces Round 37 (Rated for Div. 2)C. Swap Adjacent Elements time limit per test 1 se ...

  4. Educational Codeforces Round 40 F. Runner's Problem

    Educational Codeforces Round 40 F. Runner's Problem 题意: 给一个$ 3 * m \(的矩阵,问从\)(2,1)$ 出发 走到 \((2,m)\) ...

  5. Educational Codeforces Round 65 (Rated for Div. 2)题解

    Educational Codeforces Round 65 (Rated for Div. 2)题解 题目链接 A. Telephone Number 水题,代码如下: Code #include ...

  6. Educational Codeforces Round 63 (Rated for Div. 2) 题解

    Educational Codeforces Round 63 (Rated for Div. 2)题解 题目链接 A. Reverse a Substring 给出一个字符串,现在可以对这个字符串进 ...

  7. Educational Codeforces Round 64 (Rated for Div. 2)题解

    Educational Codeforces Round 64 (Rated for Div. 2)题解 题目链接 A. Inscribed Figures 水题,但是坑了很多人.需要注意以下就是正方 ...

  8. Educational Codeforces Round 37 A B C D E F

    A. water the garden Code #include <bits/stdc++.h> #define maxn 210 using namespace std; typede ...

  9. codeforces 920 EFG 题解合集 ( Educational Codeforces Round 37 )

    E. Connected Components? time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  10. Educational Codeforces Round 60 (Rated for Div. 2) 题解

    Educational Codeforces Round 60 (Rated for Div. 2) 题目链接:https://codeforces.com/contest/1117 A. Best ...

随机推荐

  1. 前端工程化 - bower

    什么是bower bower是前端的包管理工具,类似于php的composer,python的pip,虽然先如今bower已经停止了更新(主要是因为Browserify和Webpack等包管理工具的兴 ...

  2. shell 脚本sed替换文件中某个字符串

    有些大文件,特别的大.有几百兆,甚至更大. 用文本编辑器打开十分的费劲,电脑都卡死了. 想替换其中的字符串,很麻烦. 这个时候有了shell,简直强大到爆炸! # du -h user.sql 304 ...

  3. XML_Qt_资料

    1.QXmlQuery Class _ Qt XML Patterns 5.7.html http://doc.qt.io/qt-5/qxmlquery.html ZC: evaluateTo(QAb ...

  4. CMS收集器和G1收集器

    CMS收集器 CMS收集器是一种以获取最短回收停顿时间为目标的收集器.基于"标记-清除"算法实现,它的运作过程如下: 初始标记 并发标记 重新标记 并发清除 初始标记.从新标记这两 ...

  5. 【JMeter】 使用Synchronizing Timer设置请求集合点,实现绝对并发

    布局设置说明 参数说明: Number of Simulated Users to Group 每次释放的线程数量.如果设置为0,等同于设置为线程租中的线程数量. Timeout in millise ...

  6. 3个方法实现JavaScript判断移动端及pc端访问不同的网站

    3个方法比较简单,分别在页面头部加入如下js代码: 对于简单地直接从www.maslinkcom跳转到m.maslink.com,此方法仅从首页而言: <script>(function ...

  7. PHP:第五章——字符串的分割与替换

    <?php header("Content-Type:text/html;charset=utf-8"); //字符串的截取与分割 //1.字符串截取类函数 //1)trim ...

  8. [批处理]自动修改本机IP地址

    前言 抱着笔记本经常到处跑的人,今天回宿舍上网,明天去机房上网,后面去办公室上网,每到一个地方,都要更换一次IP网关掩码 如果都是DHCP还好,关键是为了组织为了方便管理这些地方都是使用的静态IP,所 ...

  9. 更新.xsd后,rdlc 数据源更新不了

  10. 穷举算法和递推算法(Java)

    穷举算法 概念: 最简单算法,依赖计算机的强大计算能力穷尽每一种可能的情况.穷举算法效率不高,但是适合一些没有明显规律可循的场合. 思想: 在使用穷举算法时,需要明确问题答案的范围,这样才可能在指定范 ...