一、题目

二、题目链接

  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. python swap

    swap里面的a,b 不会影响函数作用域外面的变量 java也不可以的吧:python里面没有指针,你可以认为所有的东西都是指向的内容,但是不要试图去改变指针的值 其实我觉得所有的对象都是不可变对象, ...

  2. PostMessage与SendMessage的区别

    PostMessage只负责将消息放到消息队列中,不确定何时及是否处理 SendMessage要等到受到消息处理的返回码(DWord类型)后才继续 PostMessage执行后马上返回 SendMes ...

  3. Pandas 练习题

    1. 使用 pandas 中的函数,下载上证综指过去一段时间的数据,进行数据探索. 上证综指,全称是上海证券综合指数,是以上证所挂牌上市的全部股票为计算范围,以发行量为权数的加权综合股价指数.这一指数 ...

  4. c++ 重设容器的长度(resize)

    #include <iostream> #include <vector> using namespace std; int main () { vector<int&g ...

  5. bin log、redo log、undo log和MVVC

    logs innodb事务日志包括redo log和undo log.redo log是重做日志,提供前滚操作,undo log是回滚日志,提供回滚操作. undo log不是redo log的逆向过 ...

  6. PHP:第五章——字符串转换与比较

    <?php header("Content-Type:text/html;charset=utf-8"); //字符串的转换与比较 //1.ord——返回首字符的ASCLL: ...

  7. bzoj1078

    题解: 一道思路题(话说在那个时候有多少人知道左偏树) 考虑最后一个加进来的点 必然满足 (1)从它到根一直是左链上去的 (2)没有左右子树 在这些点中寻找一个最浅的 然后删除 代码: #includ ...

  8. easyui api常用操作

    一.FORM表单类 一.textbox validatebox 验证 1.验证规则:validType : 验证规则,类型STRING|ARRAY:1个规则就直接一个字符串,多个规则写在数组里 例如: ...

  9. docker部署mysql

    1. 下载 [root@localhost my.Shells]# ./dockerStart.sh start or stop start Redirecting to /bin/systemctl ...

  10. Jenkins无法读取覆盖率报告的解决方法

    报错信息如下: log 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 coverage-report: [mkdir] Cre ...