hdu 5381 The sum of gcd】的更多相关文章

题目链接:hdu 5381 The sum of gcd 将查询离线处理,依照r排序,然后从左向右处理每一个A[i],碰到查询时处理.用线段树维护.每一个节点表示从[l,i]中以l为起始的区间gcd总和.所以每次改动时须要处理[1,i-1]与i的gcd值.可是由于gcd值是递减的,成log级,对于每一个gcd值记录其区间就可以.然后用线段树段改动,可是是改动一个等差数列. #include <cstdio> #include <cstring> #include <vecto…
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…
The sum of gcd Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 23    Accepted Submission(s): 4 Problem Description You have an array A,the length of A is n Let f(l,r)=∑ri=l∑rj=igcd(ai,ai+1....a…
The sum of gcd Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 641    Accepted Submission(s): 277 Problem Description  You have an array A with the length of $n$ \[Let\quad f(l,r) = \sum_{i = l}…
知道对于一个数列,如果以x为左(右)端点,往右走,则最多会有log(a[x])个不同的gcd,并且有递减性 所以会分成log段,每一段的gcd相同 那我们可以预处理出对于每一个位置,以这个位置为左端点和右端点的时候,分别产生的gcd的值和分界处 那么这道题就可以用莫队算法了,O(n * sqrt(n) * logn) 标程是用线段树 代码: //File Name: hdu5381.cpp //Author: long //Mail: 736726758@qq.com //Created Tim…
题意:有一个含n个元素的序列,接下来有q个询问区间,对每个询问区间输出其 f(L,R) 值. 思路: 天真单纯地以为是道超级水题,不管多少个询问,计算量顶多就是O(n2) ,就是暴力穷举每个区间,再直接开个1e8大的int数组保存其结果不就行了?呵呵,限制你内存,看你怎么死!即使给了你这么大的内存,O(n2) 也不容易过,计算量偏大,少一点也许可以. 贴个O(n2)代码. #include <bits/stdc++.h> #define MAX(X,Y) ((X) > (Y) ? (X)…
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.…
大神题解: http://blog.csdn.net/u014800748/article/details/47680899 The sum of gcd Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 526    Accepted Submission(s): 226 Problem Description You have an…
[题目] The sum of gcd 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 line of input contains an integer T, indicating the number of test cases. For each…
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…