题解 CF920F 【SUM and REPLACE】】的更多相关文章

给你一个数组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) ; using n…
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 namesp…
920F - SUM and REPLACE 思路1: 线段树(982 ms) 每个点最多更新6次 代码: #include<bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define ls rt<<1,l,m #define rs rt<<1|1,m+1,r #define mem(a,b) memset(a,b,sizeof(a)) ; const int…
F. SUM and REPLACE time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output Let D(x) be the number of positive divisors of a positive integer x. For example, D(2) = 2 (2 is divisible by 1 and 2), D(6) …
可以事先打表观察每个数的约数个数,观察到如果进行替换,若干次后这个数便会被替换成1. 所以我们可以直接暴力的进行区间修改,若这个数已经到达1或2,则以后就不再修改,用并查集和树状数组进行维护. 这个方法用了P2391 白雪皑皑的思想处理,用并查集标记该点已经不再用替换. code: #include<bits/stdc++.h> #include<cctype> #define maxn 300010 #define lowbit(x) (x&(-x)) typedef l…
一.题目 二.题目链接 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]$的数字和并输出. 四.思路 典型的数据结构题.很明显这是…
Dicription Let D(x) be the number of positive divisors of a positive integer x. For example, D(2) = 2 (2 is divisible by 1 and 2), D(6) = 4 (6 is divisible by 1, 2, 3 and 6). You are given an array a of n integers. You have to process two types of qu…
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 那个D函数它的下降速度是很快的. 也就是说到最后他会很快的变成2或者1 而D(2)==2,D(1)=1 也就是说,几次操作过后很多数字实际上就不会发生变化了. 我们可以以这个为切入点. 可以用树状数组写,也可以用线段树写. 如果用树状数组写的话. 你需要额外用一个set来维护哪些值是还能变化的. 然后在读入l,r这个范围的时候. 直接用lower_bound查找离它最近的且大于等于它的能改变的值. 将它改变. 然后在树状数组中改…
题目地址:https://oj.leetcode.com/problems/two-sum/ Two Sum Given an array of integers, find two numbers such that they add up to a specific target number. The function twoSum should return indices of the two numbers such that they add up to the target, w…
1.题目描述 2.问题分析 记录所有路径上的值,然后转换为int求和. 3.代码 vector<string> s; int sumNumbers(TreeNode* root) { traverse(root, ""); ; for(auto it = s.begin(); it != s.end(); it++) { sum += stoi(*it); } return sum; } void traverse(TreeNode *t, string str) { if…