描述

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. day06-单表查询

    1.单表查询的语法 SELECT 字段1,字段2... FROM 表名 WHERE 条件 GROUP BY field HAVING 筛选 ORDER BY field LIMIT 限制条数 2.关键 ...

  2. Django权限auth模块详解

    转自:http://www.cnblogs.com/Finley/p/5575305.html 1,auth模块是Django提供的标准权限管理系统,可以提供用户身份认证,用户组和权限管理 2,aut ...

  3. vue:在router里面给页面加title

    vue中给组件页面加页面标题:{ path: '/', name: 'index', component: disconnect, meta: { title: '首页' } }, { path: ' ...

  4. Linux命令:zip

    语法: zip   [选项]   zip文件  源文件s   选项 全称 含义 举例 -r recursive 递归压缩子目录里的文件(包括子目录里的子目录) zip   -r    target.z ...

  5. 关于GC.Collect在不同机器上表现不一致问题

    2019.1.17,昨天项目更新后策划反应: 游戏卡,表现为:每走几步就卡一下.前天还没有. 但在我本机测试中,却没有任何卡顿感. QC同学的机器也卡.我去看了下,打开Profiler,没开deep, ...

  6. JQUERY 简单易用的提示框插件

    业务开发过程中,为了避免用户的误操作,提示框是必要的,于是琢磨出了下面这个使用,方便的提示框 还要引入遮罩层的样式如下: /*弹出层*/.input{height: 32px;border: 1px ...

  7. python在DWR框架下的post

    使用requests.post,但一直要在headers中设置相应的Content-Type和Referer # coding=utf-8 import urllib2 import requests ...

  8. MySQL 各种主流 SQLServer 迁移到 MySQL 工具对比

    原地址:https://www.cnblogs.com/overblue/p/5796887.html Mss2sql:这个比较好用

  9. property 、classmethod 、 staticmethod 的用法

    @property # property是一个装饰器函数 ,作用:将一个方法伪装成属性 # 所有的装饰器函数都怎么用? 在函数.方法.类的上面一行直接@装饰器的名字 # 装饰器的分类: # 装饰函数 ...

  10. 过滤access日志前5条数据

    cat /usr/local/nginx/logs/access.log|awk '{print $1}'|sort|uniq -c|sort -n -r|head -5 找不到的话可以find查找a ...