uva12299:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=3720

题意:给你n个数,然后有两个操做,shift<a1,a2,a3.....ak>从左到右一次交换,即a1和a2交换,完了之后,a2和a3交换,以此类推。query<a1,a2>,查询a1到a2区间之间的最小值。

题解:一开始没有看懂题目,看错了,看懂之后,才发现是个水题,线段树区间查询,单点更新。不过读入要小心处理一下。

 #include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int N=;
int n,q,a[N];
char str[];
int t1,t2;
struct SegTree{
int l,r;
int minn;
inline int mid(){
return (l+r)/;
}
}num[N*];
void pushup(int rt){
num[rt].minn=min(num[rt<<].minn,num[rt<<|].minn);
}
void build(int rt,int l,int r){
num[rt].l=l;
num[rt].r=r;
if(l==r){
num[rt].minn=a[l];
return;
}
int mid=num[rt].mid();
build(rt<<,l,mid);
build(rt<<|,mid+,r);
pushup(rt);
}
void update(int pos,int rt,int val){
if(num[rt].l==num[rt].r){
num[rt].minn=val;
return;
}
int mid=num[rt].mid();
if(mid>=pos)update(pos,rt<<,val);
else
update(pos,rt<<|,val);
pushup(rt);
}
int query(int rt,int l,int r){
if(num[rt].l==l&&num[rt].r==r){
return num[rt].minn;
}
int mid=num[rt].mid();
if(mid>=r)return query(rt<<,l,r);
else if(mid<l)return query(rt<<|,l,r);
else return min(query(rt<<,l,mid),query(rt<<|,mid+,r));
}
int main(){
scanf("%d%d",&n,&q);
for(int i=;i<=n;i++){
scanf("%d",&a[i]);
}
build(,,n);
for(int i=;i<=q;i++){
scanf("%6s",str);//¶ÁÈ¡6¸ö×Ö·û
if(str[]=='q'){
scanf("%d,%d)",&t1,&t2);
printf("%d\n",query(,t1,t2));
}
else{
char c;
int cnt=;
while (scanf("%d%c",&t2,&c)){
cnt++;
if(cnt==){
t1=t2;
continue;
}
int temp=a[t1];
a[t1]=a[t2];
a[t2]=temp;
update(t1,,a[t1]);
update(t2,,a[t2]);
t1=t2;
if (c!=',') break;
}
}
}
}

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. TOJ 4325 RMQ with Shifts / 线段树单点更新

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

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

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

  4. nyoj 568——RMQ with Shifts——————【线段树单点更新、区间求最值】

    RMQ with Shifts 时间限制:1000 ms  |  内存限制:65535 KB 难度:3   描述     In the traditional RMQ (Range Minimum Q ...

  5. RMQ with Shifts(线段树)

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

  6. C. RMQ with Shifts

    C. RMQ with Shifts Time Limit: 1000ms Case Time Limit: 1000ms Memory Limit: 131072KB   64-bit intege ...

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

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

  8. NYOJ 1012 RMQ with Shifts (线段树)

    题目链接 In the traditional RMQ (Range Minimum Query) problem, we have a static array A. Then for each q ...

  9. 树状数组求最大值 (RMQ with Shifts)

    代码: #include <iostream> #include <stdio.h> #include <string.h> #include <stdlib ...

  10. CSU-1110 RMQ with Shifts (单点更新+区间最小值 zkw线段树)

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

随机推荐

  1. 通过WriteProcessMemory改写进程的内存

    http://www.cnblogs.com/feiyucq/archive/2009/10/21/1587628.html 以PROCESS_ALL_ACCESS权限打开进程以后既能够使用ReadP ...

  2. [Javascript] Creating an Immutable Object Graph with Immutable.js Map()

    Learn how to create an Immutable.Map() through plain Javascript object construction and also via arr ...

  3. linux系统启动

    在本文中,我们按电源按钮简要叙述,以便能够登录到系统,在此期间,系统和计算机硬件是如何一起工作.既作为自己整理知识的摘要,有可能linux0绍,高手请略过. 一般来说linux的启动能够分成三个阶段: ...

  4. Android 图标上面添加提醒(二)使用开源UI类库 Viewbadger

    版权声明:本文为博主原创文章,未经博主允许不得转载. 上一篇讲到用canvas进行绘制得到对应最终的bitmap. 在实际应用中,我们除了给图标添加数字外,也有可能加一些红色方块之类的图标作为新功能的 ...

  5. poj3348 Cows 凸包+多边形面积 水题

    /* poj3348 Cows 凸包+多边形面积 水题 floor向下取整,返回的是double */ #include<stdio.h> #include<math.h> # ...

  6. (转载)Java 1.7的新特性

    网上找了一下,整理了贴出来. 下面是Java 1.7 里新出现的功能的一些用法例子: 对集合的支持 摒弃了 Java 集合接口的实现类,如: ArrayList . HashSet 和 HashMap ...

  7. Android群英传》读书笔记 (4) 第八章 Activity和Activity调用栈分析 + 第九章 系统信息与安全机制 + 第十章 性能优化

    第八章 Activity和Activity调用栈分析 1.Activity生命周期理解生命周期就是两张图:第一张图是回字型的生命周期图第二张图是金字塔型的生命周期图 注意点(1)从stopped状态重 ...

  8. Java基础知识强化之集合框架笔记36:List练习之键盘录入多个数据在控制台输出最大值

    1. 键盘录入多个数据,以0结束,要求在控制台输出这多个数据中的最大值 分析: •  创建键盘录入数据对象 •  键盘录入多个数据,我们不知道多少个,所以用集合存储 •  以0结束,这个简单,只要键盘 ...

  9. Java基础知识强化之集合框架笔记14:List集合存储字符串并遍历

    1. List集合存储学生对象并遍历: 需求:存储字符串并遍历 分析: (1)创建集合对象 (2)创建字符串对象 (3)添加字符串对象到集合中 (4)遍历集合 2. 代码示例: package cn. ...

  10. Initializer block.

    Ref: Initializing Fields Instance initializers are permitted to refer to the current object via the ...