RMQ with Shifts |
In the traditional RMQ (Range Minimum Query) problem, we have a static array A. Then for eachquery (L, R) (LR), 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 operation
For example, if A={6, 2, 4, 8, 5, 1, 4}, then shift(2, 4, 5, 7) yields {6, 8, 4, 5, 4, 1, 2}. After that,shift(1, 2) yields 8, 6, 4, 5, 4, 1, 2.
Warning: The dataset is large, better to use faster I/O methods.
7 5 6 2 4 8 5 1 4 query(3,7) shift(2,4,5,7) query(1,4) shift(1,2) query(2,2)
1 4 6
#include
#include
#define L(i) i<<1
#define R(i) i<<1|1
#define N 100011
/*
线段树,注意这里是离散的点更新,这些点是有序的,update(l,r,id)中
l、r表示更新的点的下表,若左右孩子都更新时for()寻找断点
状态不佳,l、r的含义糊涂了好久
*/
struct node{
int l,r,val;
int mid(){return (l+r)/2;}
}st[N<<2];
int min(int a,int b){
return a=r)
return query(l,r,L(id));
else if(mid=com[r])
update(l,r,L(id));
else if(mid