线段树,没了..

-----------------------------------------------------------------------------------------

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cctype>
  
#define rep(i,n) for(int i=0;i<n;i++)
#define clr(x,c) memset(x,c,sizeof(x))
#define Rep(i,l,r) for(int i=l;i<=r;i++)
  
using namespace std;
  
const int inf=0x7fffffff;
const int maxn=100005;
  
int a[maxn];
int minv[1<<18];
  
void build(int o,int l,int r) {
int m=l+(r-l)/2;
if(l==r) minv[o]=a[l];
else {
build(o*2,l,m);
build(o*2+1,m+1,r);
minv[o]=min(minv[o*2],minv[o*2+1]);
}
}
  
int p,v;
void update(int o,int l,int r) {
int m=l+(r-l)/2;
if(l==r) minv[o]=v;
else {
p<=m ? update(o*2,l,m) : update(o*2+1,m+1,r);
minv[o]=min(minv[o*2],minv[o*2+1]);
}
}
  
int ql,qr;
int query(int o,int l,int r) {
int m=l+(r-l)/2,ans=inf;
if(ql<=l && qr>=r) return minv[o];
if(ql<=m) ans=min(ans,query(o*2,l,m));
if(qr>m) ans=min(ans,query(o*2+1,m+1,r));
return ans;
}
int main()
{
freopen("test.in","r",stdin);
freopen("test.out","w",stdout);
int n,q;
scanf("%d%d",&n,&q);
Rep(i,1,n) scanf("%d",&a[i]);
build(1,1,n);
int cmd[20],change[20],cnt;
char s[100];
while(q--) {
scanf("%s",s);
int len=strlen(s);
cmd[cnt=0]=0;
for(int i=6;i<len;++i)
if(isdigit(s[i])) (cmd[cnt]*=10)+=s[i]-'0';
else cmd[++cnt]=0;
if(s[0]=='q') {
ql=cmd[0],qr=cmd[1];
printf("%d\n",query(1,1,n));
} else {
rep(i,cnt) change[i]=a[cmd[i]];
rep(i,cnt) { v=a[p=cmd[i]]=change[(i+1)%cnt]; update(1,1,n); }
}
}
return 0;
}

-----------------------------------------------------------------------------------------

12299 RMQ with Shifts
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
shif 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.
Input
There 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 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.
Output
For each query, print the minimum value (rather than index) in the requested range.
Sample Input
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)
Sample Output
1
4
6

UVa 12299 RMQ with Shifts(线段树)的更多相关文章

  1. UVa 12299 RMQ with Shifts(移位RMQ)

    p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: "Times New ...

  2. HDU 1754 - I Hate It & UVA 12299 - RMQ with Shifts - [单点/区间修改、区间查询线段树]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1754 Time Limit: 9000/3000 MS (Java/Others) Memory Li ...

  3. RMQ with Shifts(线段树)

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

  4. TZOJ 4325 RMQ with Shifts(线段树查询最小,暴力更新)

    描述 In the traditional RMQ (Range Minimum Query) problem, we have a static array A. Then for each que ...

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

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

  6. UVA 12299 RMQ with shifts

    就是线段树的单点修改和区间查询. 然而输入打了一个小时才弄清楚. #include<iostream> #include<cstdio> #include<cstring ...

  7. UVA 12299 RMQ with Shifts(线段树:单点更新)

    题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...

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

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

  9. UVA 11983 Weird Advertisement(线段树求矩形并的面积)

    UVA 11983 题目大意是说给你N个矩形,让你求被覆盖k次以上的点的总个数(x,y<1e9) 首先这个题有一个转化,吧每个矩形的x2,y2+1这样就转化为了求N个矩形被覆盖k次以上的区域的面 ...

随机推荐

  1. MySQL数据处理函数

    数据处理函数 有时从数据库表中获取到的数据须要进行一些处理. 如将小写字母替换为对应的大写字母.这个处理过程能够在客户机上进行.也能够在数据库上进行. 数据库上进行会更高效.数据库中有对应的数据处理函 ...

  2. mysql关联更新

    update tb_sdd_info a,tb_bnm_evian_info b set a.username=b.username where a.username=b.memberno and  ...

  3. JavaScript之面向对象学习一

    1.通过Object构造函数和对象字面量来创建对象缺点:使用同一个接口创建很多的对象,会产生大量的重复代码.比如我需要创建人的对象,并且需要三类人,医生.工程师.老师,他们可以抽象出很多属性,比如姓名 ...

  4. Git - 常用技能

    参考: http://wuchong.me/blog/2015/03/30/git-useful-skills/

  5. apache rewrite rule

    http://10.58.104.19:8008/site/833/3f11d2b44b7d3baa2149f26a30f8c68d/b.js?siteid=332323 将一个静态请求转换成一个动态 ...

  6. Python中初始化的问题以及注释问题

    #coding=utf-8 # __author__ = 'minmin' from Tkinter import * #创建一个基于Frame的Application类 class Applicat ...

  7. PCRE兼容正则表达式函数

    1.preg_grep()函数 函数语法: array preg_grep ( string pattern, array input ) 函数功能: 使用数组input中的元素一一匹配表达式patt ...

  8. Windows 安装 psutil

    第一步:下载pustil 网址:https://pipy.python.org  (http://yunpan.cn/cJg8aQpYwqfzh (提取码:7fa7)) 第二步:安装这个就没有什么好说 ...

  9. Date对象需要注意的点

    var today=new Date(); Date对象取得了PC内部时钟的一个快照,并同时返回一个Date对象实例. 注意静态Date对象和Date对象实例的差别,后者包含一个实际的日期值.毫秒为单 ...

  10. 树型动态规划(树形dp)

    树型动态规划就是在“树”的数据结构上的动态规划,树型动态规划是建立在树上的,所以有二个方向: 1.根—>叶:这种题目基本上碰不到 2.叶->根:根的子节点传递有用的信息给根,完后根得出最优 ...