描述

In the traditional RMQ (Range Minimum Query) problem, we have a static array A. Then for each query (L, R) (L<=R), we report the minimum value among A[L], A[L+1], …, A[R]. Note that the indices 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 shift(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 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}.

输入

There will be only one test case, beginning with two integers n, q (1<=n<=100,000, 1<=q<=120,000), the number of integers in array A, and the number of operations. The next line contains n positive integers not greater than 100,000, the initial elements in array A. Each of the next q lines contains an operation. Each operation is formatted as a string having no more than 30 characters, with no space characters inside. All operations are guaranteed to be valid. Warning: The dataset is large, better to use faster I/O methods.

输出

For each query, print the minimum value (rather than index) in the requested range.

样例输入

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

题意

给你N个数,有两个操作

1.查询区间最小

2.给定几个位置,循环左移

题解

可以看出循环左移的区间不是很大,那么直接拿线段树暴力更新

代码

 #include<bits/stdc++.h>
using namespace std; #define ll long long const int maxn=1e5+; int n,q;
int Min[maxn<<]; void build(int l,int r,int rt)
{
if(l==r)
{
scanf("%d",&Min[rt]);
return;
}
int mid=(l+r)>>;
build(l,mid,rt<<);
build(mid+,r,rt<<|);
Min[rt]=min(Min[rt<<],Min[rt<<|]);
} void update(int L,int c,int l,int r,int rt)
{
if(l==r)
{
Min[rt]=c;
return;
}
int mid=(l+r)>>;
if(L<=mid)update(L,c,l,mid,rt<<);
else update(L,c,mid+,r,rt<<|);
Min[rt]=min(Min[rt<<],Min[rt<<|]);
} int query(int L,int R,int l,int r,int rt)
{
if(L<=l&&r<=R)
return Min[rt];
int mid=(l+r)>>,ans=0x3f3f3f3f;
if(L<=mid)ans=min(ans,query(L,R,l,mid,rt<<));
if(R>mid)ans=min(ans,query(L,R,mid+,r,rt<<|));
return ans;
} int main()
{
scanf("%d%d",&n,&q);
build(,n,);
for(int i=;i<q;i++)
{
getchar();
int pre,cur;
if(getchar()=='s')
{
while(getchar()!='(');
scanf("%d",&pre);
int first=query(pre,pre,,n,);
while(getchar()!=')')
{
scanf("%d",&cur),
update(pre,query(cur,cur,,n,),,n,);
pre=cur;
}
update(pre,first,,n,);
}
else
{
while(getchar()!='(');
scanf("%d,%d)",&pre,&cur);
printf("%d\n",query(pre,cur,,n,));
}
}
return ;
}

TZOJ 4325 RMQ with Shifts(线段树查询最小,暴力更新)的更多相关文章

  1. TOJ 4325 RMQ with Shifts / 线段树单点更新

    RMQ with Shifts 时间限制(普通/Java):1000MS/3000MS     运行内存限制:65536KByte 描述 In the traditional RMQ (Range M ...

  2. UVa 12299 RMQ with Shifts(线段树)

    线段树,没了.. ----------------------------------------------------------------------------------------- # ...

  3. RMQ with Shifts(线段树)

    RMQ with Shifts Time Limit:1000MS     Memory Limit:65535KB     64bit IO Format:%I64d & %I64u Pra ...

  4. ACM/ICPC 2018亚洲区预选赛北京赛站网络赛 D 80 Days (线段树查询最小值)

    题目4 : 80 Days 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 80 Days is an interesting game based on Jules Ve ...

  5. Codeforces295A - Greg and Array(线段树的成段更新)

    题目大意 给定一个序列a[1],a[2]--a[n] 接下来给出m种操作,每种操作是以下形式的: l r d 表示把区间[l,r]内的每一个数都加上一个值d 之后有k个操作,每个操作是以下形式的: x ...

  6. HDU 1394 Minimum Inversion Number(线段树求最小逆序数对)

    HDU 1394 Minimum Inversion Number(线段树求最小逆序数对) ACM 题目地址:HDU 1394 Minimum Inversion Number 题意:  给一个序列由 ...

  7. HDU 1754 I Hate It(线段树区间查询,单点更新)

    描述 很多学校流行一种比较的习惯.老师们很喜欢询问,从某某到某某当中,分数最高的是多少. 这让很多学生很反感.不管你喜不喜欢,现在需要你做的是,就是按照老师的要求,写一个程序,模拟老师的询问.当然,老 ...

  8. RMQ问题(线段树+ST算法)

    转载自:http://kmplayer.iteye.com/blog/575725 RMQ (Range Minimum/Maximum Query)问题是指:对于长度为n的数列A,回答若干询问RMQ ...

  9. 线段树模板(单点更新,区间更新,RMQ)

    Bryce1010模板 1.单点更新 说明 单点更新,区间求和(你问我单点求和??你就不会把区间长度设为0啊?) • sum[]为线段树,需要开辟四倍的元素数量的空间. • build()为建树操作 ...

随机推荐

  1. 浅谈 foreach 的原理

    package com.shenzhou; import java.util.ArrayList; import java.util.Iterator; import java.util.List; ...

  2. Linux MySQL 安装、远程访问和密码重置

    安装: yum install mysql yum install mysql-server yum install mysql-devel 设置开机启动: chkconfig -add mysqld ...

  3. 【JEECG技术文档】JEECG平台对外接口JWT应用文档V3.7.2

    一. 接口方式 接口调用采用http协议,rest请求方式: 二. 接口安全 接口安全采用Json web token (JWT)机制,基于token的鉴权机制. 1. 机制说明 基于token的鉴权 ...

  4. jetty 入门

    jetty因其能作为内嵌的应用服务器,随应用一起存在,在小批量应用中很受欢迎. jetty作为应用服务器: jetty下载: 在官网下载jetty:http://www.eclipse.org/jet ...

  5. Xcode 8 注释快捷键失效

    sudo /usr/libexec/xpccachectl 重启

  6. sping IOC和DI 初始化和关系

    springIOC和spring DI作为spring core的核心思想,有必要学习下才能更好的使用spring ========================================== ...

  7. li之间的间隙问题

    1.间隙是有代码格式中的换行符产生,对代码进行压缩处理或手动删除换行就好:

  8. Android Studio安装插件提示was not installed: Cannot download的解决

    https://blog.csdn.net/xiayiye5/article/details/80510910 2.[Android Studio安装部署系列]三十二.Android模拟器Genymo ...

  9. Kotlin语言学习笔记(3)

    数据类(Data Classes) data class User(val name: String, val age: Int) 编译器自动生成的有: equals()/hashCode() toS ...

  10. HG255D刷机OPENWRT笔记

    1.按网上的办法如下:(http://www.right.com.cn/forum/thread-143721-1-1.html) 自已编译了OPENWRT,然后拆开外壳接上TTL线,通电启动 然后用 ...