Given you a sequence of number a 1, a 2, ..., a n, which is a permutation of 1...n. You need to answer some queries, each with the following format: Give you two numbers L, R, you should calculate sum of gcd(a[i], a[j]) for every L <= i < j <= R.…
Sum Of Gcd 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=4676 Description Given you a sequence of number a1, a2, ..., an, which is a permutation of 1...n. You need to answer some queries, each with the following format: Give you two numbers L, R, y…
任意门:http://acm.hdu.edu.cn/showproblem.php?pid=4676 Sum Of Gcd Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 908    Accepted Submission(s): 438 Problem Description Given you a sequence of numb…
题目链接 给n个数, m个询问, 每个询问给出[l, r], 问你对于任意i, j.gcd(a[i], a[j]) L <= i < j <= R的和. 假设两个数的公约数有b1, b2, b2...bn, 那么这两个数的最大公约数就是phi[b1] + phi[b2] + phi[b3]...+phi[bn]. 知道这个就可以用莫队了, 具体看代码. #include <bits/stdc++.h> using namespace std; #define pb(x) pu…
The sum of gcd Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Problem Description You have an array A,the length of A is nLet f(l,r)=∑ri=l∑rj=igcd(ai,ai+1....aj)   Input There are multiple test cases. The first li…
题意:给定一个11~nn的全排列AA,若干个询问,每次询问给出一个区间[l,r][l,r],要求得出∑l≤i<j≤r  gcd(Ai,Aj)的值. 解法:这题似乎做的人不是很多,蒟蒻当然不会做只能看题解了qwq,目前看到一个比较好的题解是https://blog.csdn.net/Maxwei_wzj/article/details/79355887. 没什么好说的,首先必须先推式子. 那么这一坨东西到底是什么意思呢?其实就是对于每个数d,sigma[d|ai][d|aj] 是从区间[l,r]中…
题意:http://acm.hdu.edu.cn/showproblem.php?pid=5381 思路:这个题属于没有修改的区间查询问题,可以用莫队算法来做.首先预处理出每个点以它为起点向左和向右连续一段的gcd发生变化的每个位置,不难发现对每个点A[i],这样的位置最多logA[i]个,这可以利用ST表用nlognlogA[i]的时间预处理,然后用二分+RMQ在nlogn的时间内得到.然后就是区间变化为1时的转移了,不难发现区间变化为1时,变化的答案仅仅是以变化的那一个点作为左端点或右端点的…
题意我就不说了   解析: 莫队,先预处理出以i为右端点的区间的gcd值,有一些连续的区间的gcd值是相同的,比如[j,i],[j+1,i],[j+2,i]的gcd值是相同的,我们可以把[j,j+2]这个 区间保存下来.同时也预处理出以i为左端点的,最后用莫队算法.详见代码实现.   代码 #include<cstdio> #include<vector> #include<cstring> #include<string> #include<cmat…
Boring counting Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 98304/98304 K (Java/Others) Total Submission(s): 2811    Accepted Submission(s): 827 Problem Description In this problem we consider a rooted tree with N vertices. The vertices a…
题目链接:https://www.luogu.org/problemnew/show/P1903 题目大意:中文题目 具体思路:莫队单点修改+区间询问模板题,在原来的区间询问的基础上,我们要记录当前这次操作之前单点修改的操作都有哪些,如果有多余的操作,就先消除这些操作:如果操作数还不够,就在加上这些操作就可以了,这个题会卡常数,注意block的赋值. block的赋值 = ceil(exp((log(n)+log(num1))/3));这里的num1指的是操作数,n代表点的个数. 然后我们可以对…