SQLServer Decimal数据类型怎么赋值
252
2022-08-28
RMQ with Shifts (线段树)
In the traditional RMQ (Range Minimum Query) problem, we have a static array A. Then for eachquery (L, R) (L ≤ R), we report the minimum value among A[L], A[L + 1], . . . , A[R]. Note that theindices start from 1, i.e. the left-most element is A[1].In this problem, the array A is no longer static: we need to support another operationshif t(i1, i2, i3, . . . , ik)(i1 < i2 < . . . < ik, k > 1)we do a left “circular shift” of A[i1], A[i2], . . . , A[ik].For example, if A={6, 2, 4, 8, 5, 1, 4}, then shif t(2, 4, 5, 7) yields {6, 8, 4, 5, 4, 1, 2}. After that,shif t(1, 2) yields 8, 6, 4, 5, 4, 1, 2.InputThere will be only one test case, beginning with two integers n, q (1 ≤ n ≤ 100, 000, 1 ≤ q ≤ 250, 000),the number of integers in array A, and the number of operations. The next line contains n positiveintegers not greater than 100,000, the initial elements in array A. Each of the next q lines contains anoperation. Each operation is formatted as a string having no more than 30 characters, with no spacecharacters inside. All operations are guaranteed to be valid.Warning: The dataset is large, better to use faster I/O methods.OutputFor each query, print the minimum value (rather than index) in the requested range.Sample Input7 56 2 4 8 5 1 4query(3,7)shift(2,4,5,7)query(1,4)shift(1,2)query(2,2)Sample Output146
题目大概:
给你n个数,m条询问。每条询问,可以是查询区间最小值,或者是改变某些值的位置,即把第二个数的值放在第一个,第三个数放在第二个,第一个放在最后一个。形成循环,相当于单点更新。
思路:
直接用线段树维护区间最小值就行了,不过输入比较麻烦。
代码:
#include
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~