lightoj Again Array Queries】的更多相关文章

1100 - Again Array Queries   PDF (English) Statistics Forum Time Limit: 3 second(s) Memory Limit: 32 MB Given an array with n integers, and you are given two indices i and j (i ≠ j) in the array. You have to find two integers in the range whose diffe…
E. Array Queries 题目链接:http://codeforces.com/problemset/problem/797/E time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output a is an array of n positive integers, all of which are not greater than…
题目链接:codeforces 797 E. Array Queries   题意:给你一个长度为n的数组a,和q个询问,每次询问为(p,k),相应的把p转换为p+a[p]+k,直到p > n为止,求每次询问要转换的次数. 题解:纯暴力会TLE,所以在k为根号100000范围内dp打表 dp[i][j]表示初始p为i, k为j,需要转换几次可以大于n. 状态转移方程:dp[i][j] = dp[i+a[i]+j] + 1 #include <cstdio> #include <al…
797E - Array Queries 思路: 分段处理: 当k小于根号n时记忆化搜索: 否则暴力: 来,上代码: #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; #define maxn 100005 ],size; inline void in(int &am…
                                                                                                              1082 - Array Queries Time Limit: 3 second(s) Memory Limit: 64 MB Given an array with N elements, indexed from 1 to N. Now you will be given…
                                                                          1100 - Again Array Queries                                                                                                  ->   Link   <- 又是这种区间查询最值问题,题目意思是要使得这个区间的两个数的差值最小值,…
1188 - Fast Queries    PDF (English) Statistics Forum Time Limit: 3 second(s) Memory Limit: 64 MB Given an array of N integers indexed from 1 to N, and q queries, each in the form i j, you have to find the number of distinct integers from index i to …
Description You are given an array a of size n, and q queries to it. There are queries of two types: 1 li ri — perform a cyclic shift of the segment [li, ri] to the right. That is, for every x such that li ≤ x < ri new value of ax + 1 becomes equal t…
a is an array of n positive integers, all of which are not greater than n. You have to process q queries to this array. Each query is represented by two numbers p and k. Several operations are performed in each query; each operation changes p to p + …
链接: https://vjudge.net/problem/LightOJ-1369 题意: The problem you need to solve here is pretty simple. You are give a function f(A, n), where A is an array of integers and n is the number of elements in the array. f(A, n) is defined as follows: long lo…
You are given an array a of size n, and q queries to it. There are queries of two types: 1 li ri — perform a cyclic shift of the segment [li, ri] to the right. That is, for every x such that li ≤ x < ri new value of ax + 1 becomes equal to old value…
题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1100 给你n个数,数的范围是1~1000,给你q个询问,每个询问问你l到r之间数的最小差是多少. 要是l到r的数字个数大于1000,必定会有两个数字重复,所以此时最小差就为0.要是小于等于1000就直接暴力即可. //#pragma comment(linker, "/STACK:102400000, 102400000") #include <algorit…
http://lightoj.com/volume_showproblem.php?problem=1100 刚一看到这题,要询问这么多次,线段树吧,想多了哈哈,根本没法用线段树做. 然后看看数据范围纯暴力的话肯定超时.然后比赛时就liao那了. 今天是补题,然后做这题,前两发傻逼呵呵的想了一种暴力方法,报着也许能过的心态交了,果然没让我失望超时了. 不说这些没用的了,下面说说这题是咋做的. 没用什么高深的算法,好像算法都没用,就纯暴力写的,关键是加入一种常识来优化.传说中的鸽巢原理,其实有点常…
题目链接 非常好的一道题目, 分析,如果用暴力的话,时间复杂度是O(q*n)稳稳的超时 如果用二维DP的话,需要O (n*n)的空间复杂度,会爆空间. 那么分析一下,如果k>sqrt(n)的话,不需要sqrt(n) 次就可以达到大于n 而如果k<sqrt(n)的情况下,不妨用DP来处理,时间复杂度和空间复杂度皆为O ( n*sqrt( n ) ) 那么都可以分类处理了. 详细见code #include <iostream> #include <cstdio> #inc…
题目链接:https://vjudge.net/contest/28079#problem/P 题目大意:给你数组A[]以及如下所示的函数f: long long f( int A[], int n ) { // n = size of A long long sum = 0; for( int i = 0; i < n; i++ ) for( int j = i + 1; j < n; j++ ) sum += A[i] - A[j]; return sum; } 有两个操作:0  x  v…
$dp$预处理,暴力. 如果$k > sqrt(n)$,那么答案不会超过$sqrt(n)$,暴力模拟即可.如果$k <= sqrt(n)$,那么可以$dp$预处理打表. #include <iostream> #include <cstdio> #include <cmath> #include <cstring> #include <string> #include <queue> #include <stack&…
传送门 题意 给出n个数,q个询问,每个询问有两个数p,k,询问p+k+a[p]操作几次后超过n 分析 分块处理,在k<sqrt(n)时,用dp,大于sqrt(n)用暴力 trick 代码 #include<cstdio> int n,a[100100],p,k,q,dp[100100][350]; int main() { scanf("%d",&n); for(int i=1;i<=n;++i) scanf("%d",a+i);…
[题目链接]:http://codeforces.com/problemset/problem/797/E [题意] 给你一个n个元素的数组; 每个元素都在1..n之间; 然后给你q个询问; 每个询问由p和k构成; 会对p进行 p=p+a[p]+k操作若干次; 你要输出p第一次大于n之后操作了多少次; [题解] 部分DP; 这里对于k>400的询问; 我们直接暴力求解; 因为这时暴力所花费的时间已经可以接受了; 而对于剩余的k<=400的询问; 我们写一个记忆化搜索来求解; 很棒的思路吧 [N…
原题连接:http://codeforces.com/problemset/problem/863/D 题意:对a数列有两种操作: 1 l r ,[l, r] 区间的数字滚动,即a[i+1]=a[i], a[l]=a[r] 2 l r ,[l, r] 区间的数字位置反转. 若干个操作之后输出a[b[i]]. 思路: 由于是在操作结束后输出,且b[i]的个数不多(<=100),所以可以通过反推求出答案. AC代码: #include<iostream> #include<cstrin…
提高自己的实力, 也为了证明, 开始板刷lightoj,每天题量>=1: 题目的类型会在这边说明,具体见分页博客: SUM=54; 1000 Greetings from LightOJ [简单A+B] 1001 Opposite Task  [简单题] 1002 Country Roads[搜索题] 1003 Drunk[判环] 1004 Monkey Banana Problem [基础DP] 1006 Hex-a-bonacci[记忆化搜索] 1008 Fibsieve`s Fantabu…
We have an array A of integers, and an array queries of queries. For the i-th query val = queries[i][0], index = queries[i][1], we add val to A[index].  Then, the answer to the i-th query is the sum of the even values of A. (Here, the given index = q…
Difficulty: Easy Question We have an array A of integers, and an array queries of queries. For the i-th query val = queries[i][0], index = queries[i][1], we add val to A[index]. Then, the answer to the i-th query is the sum of the even values of A. (…
We have an array A of integers, and an array queries of queries. For the i-th query val = queries[i][0], index = queries[i][1], we add val to A[index]. Then, the answer to the i-th query is the sum of the even values of A. (Here, the given index = qu…
https://leetcode.com/problems/sum-of-even-numbers-after-queries/ We have an array A of integers, and an array queries of queries. For the i-th query val = queries[i][0], index = queries[i][1], we add val to A[index].  Then, the answer to the i-th que…
We have an array A of integers, and an array queries of queries. For the i-th query val = queries[i][0], index = queries[i][1], we add val to A[index].  Then, the answer to the i-th query is the sum of the even values of A. (Here, the given index = q…
题目要求 We have an array A of integers, and an array queries of queries. For the i-th query val = queries[i][0], index = queries[i][1], we add val to A[index].  Then, the answer to the i-th query is the sum of the even values of A. (Here, the given inde…
package y2019.Algorithm.array; /** * @ProjectName: cutter-point * @Package: y2019.Algorithm.array * @ClassName: SumEvenAfterQueries * @Author: xiaof * @Description: 985. Sum of Even Numbers After Queries * * We have an array A of integers, and an arr…
We have an array A of integers, and an array queries of queries. For the i-th query val = queries[i][0], index = queries[i][1], we add val to A[index].  Then, the answer to the i-th query is the sum of the even values of A. (Here, the given index = q…
题目如下: We have an array A of integers, and an array queries of queries. For the i-th query val = queries[i][0], index = queries[i][1], we add val to A[index].  Then, the answer to the i-th query is the sum of the even values of A. (Here, the given ind…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 暴力 找规律 日期 题目地址:https://leetcode.com/problems/sum-of-even-numbers-after-queries/ 题目描述 We have an array A of integers, and an array queries of queries. For the i-th query val = q…