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…
题目链接: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…
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…
原题连接: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…
题目链接: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…
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…
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…
                                                                          1100 - Again Array Queries                                                                                                  ->   Link   <- 又是这种区间查询最值问题,题目意思是要使得这个区间的两个数的差值最小值,…
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…
J - Military Problem CodeForces - 1006E 就是一道dfs序的问题 给定一个树, 然后有q次询问. 每次给出u,k, 求以u为根的子树经过深搜的第k个儿子,如果一个节点有多个儿子,按照儿子从小到大的顺序,依次访问,不存在则输出-1. 预处理记录一下每个节点的出入时间 最后每次query直接判断就好了 #include <cstdio> #include <algorithm> #include <vector> using names…
                                                                                                              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…
B - Save the problem! CodeForces - 867B 这个题目还是很简单的,很明显是一个构造题,但是早训的时候脑子有点糊涂,想到了用1 2 来构造, 但是去算这个数的时候算错了... 用1 2 来构造 可以先枚举一些数来找找规律. 1 1 2 2 3 1 1 1    2 1 1 4 .... 可以发现每一个数都是 n/2+1 的可能, 所以反过来推过去就是 (s-1)*2  或者(s-1)*2+1 这个(s-1)*2+1的答案才是正确答案 因为 这个s可以==1 #i…
传送门 题意 给出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);…
B. Queries on a String Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/598/problem/B Description You are given a string s and should process m queries. Each query is described by two 1-based indices li, ri and integer ki. I…
Problem E. MinimaTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100342/attachments Description You are given an array x[1 . . . n] and a number m. For all i from 1 to n−m+ 1 find the minimum among x[i], x[i + 1], . . . , x[i +…
Adieu l'ami. Koyomi is helping Oshino, an acquaintance of his, to take care of an open space around the abandoned Eikou Cram School building, Oshino's makeshift residence. The space is represented by a rectangular grid of n × m cells, arranged into n…
Rock... Paper! After Karen have found the deterministic winning (losing?) strategy for rock-paper-scissors, her brother, Koyomi, comes up with a new game as a substitute. The game works as follows. A positive integer n is decided first. Both Koyomi a…
It's hard times now. Today Petya needs to score 100 points on Informatics exam. The tasks seem easy to Petya, but he thinks he lacks time to finish them all, so he asks you to help with one.. There is a glob pattern in the statements (a string consis…
Polycarp watched TV-show where k jury members one by one rated a participant by adding him a certain number of points (may be negative, i. e. points were subtracted). Initially the participant had some score, and each the marks were one by one added…
[题目链接]: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/contest/361/problem/C 题意:对一个数列有这么两个操作 1.(1,l,r,p)..将区间[l,r]所有数都加上p 2.(2,l,r,m).求出区间[l,r]的最大值为m 现在告诉这么一些操作(<5000个),问能否找到一个原始的数列,有则输出YES与这个数列,否则输出NO,答案可能不唯一输出任何合法的都行. 题解:先给数组赋予最大的初值然后倒着处理,遇到1就减去.如果是2,将这一区间里所有数都去min(自身,MAX) 处理…
目录 @description@ @solution@ @accepted code@ @details@ @description@ 给定一个 n 个点的无向图,标号从 1 到 n.一开始没有任何边存在. 请你完成以下两种操作: 1 x y(1 <= x, y <= n, x ≠ y),将 (x, y) 这一条边置反.也就是,存在变为不存在,不存在变为存在. 2 x y(1 <= x, y <= n, x ≠ y),询问 x, y 是否连通. 注意操作是加密的.记 last 表示…
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…
You are given two integers n and k. Find k-th smallest divisor of n, or report that it doesn't exist. Divisor of n is any such natural number, that n can be divided by it without remainder. Input The first line contains two integers n and k (1 ≤ n ≤ …
今天,开博客,,,激动,第一次啊 嗯,,先来发水题纪念一下 D1. Magic Powder - 1   This problem is given in two versions that differ only by constraints. If you can solve this problem in large constraints, then you can just write a single solution to the both versions. If you fin…
传送门:https://codeforces.com/contest/691/problem/F 题意:给你n个数和q次询问,每次询问问你有多少对ai,aj满足ai*aj>=q[i],注意 a*b 与 b*a是不同的 题解:sum[i]记录的是两个数乘积为i的方法数,然后前缀和记录小于等于乘积为i的方法个数,输出答案就容斥一下,因为n个数最多组成n*(n-1)/2对数,减去小于乘积为q[i]的数后即为乘积大于等于q[i]的方法个数 为什么可以暴力是因为注意到了值域的范围为3e6,调和级数的复杂度…
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 + …
原题链接 Problem Description You are a "Problem Killer", you want to solve many problems. Now you have n problems, the i-th problem's difficulty is represented by an integer ai (1≤ai≤109).For some strange reason, you must choose some integer l and r…
http://codeforces.com/problemset/problem/548/B Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n × m grid, there's exactly one bear in each cell. We denote the bear standing in column n…