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. 【2014】【辛星】【php】【秋季】【2】第一个php程序

    <span style="font-family:KaiTi_GB2312;font-size:18px;">*******************设置server** ...

  2. Qt 读写XML文件

    1.读操作: QDomDocument doc( “mydocument " ); QFile file( "ccc.xml" ); if ( !file.open( I ...

  3. Android群英传》读书笔记 (3) 第六章 Android绘图机制与处理技巧 + 第七章 Android动画机制与使用技巧

    第六章 Android绘图机制与处理技巧 1.屏幕尺寸信息屏幕大小:屏幕对角线长度,单位“寸”:分辨率:手机屏幕像素点个数,例如720x1280分辨率:PPI(Pixels Per Inch):即DP ...

  4. 如何在windows/wamp环境下在本机配置站点

    1. 在D:\wamp\bin\apache\Apache2.5.4\conf文件夹下,找到httpd.conf,使用记事bej打开它,搜索#Include conf/extra/httpd-vhos ...

  5. codevs 3052 多米诺 二分图匹配

    /*codevs 3052 二分图匹配 把矩阵分两批 黑和白 且黑白不相交 这就构成了二分图的两部分 然后求最大匹配*/ #include<cstdio> #include<cstr ...

  6. asp.net 自动遍历实体类

    最近做项目需要读取修改前数据库中被修改的数据所有的信息,一开始想要在model层的每个类都写一个函数return一串字符串, 但是由于表太多,实体类数量太大,写出来太浪费时间,所以决定写一个通用的方法 ...

  7. The performance between the 'normal' operation and the 'shift' operation.

    First, I gonna post my test result with some code: //test the peformance of the <normal operation ...

  8. youphp学习整理

    <?php //后台公共模块 // _list 数据显示 // add 添加/编辑 视图 // insert 添加处理函数 // edit 添加/编辑 视图 // update 更新处理函数 / ...

  9. Wireshark提示没有一个可以抓包的接口

    这是由于win下默认NPF服务是关闭的,需要以管理员的身份开启这个服务 Windows上安装wireshark时,会遇到NPF驱动无法启动的情况,一般如果采用管理员的方式就可以正常启动,或者是将NPF ...

  10. 如何将硬盘GPT分区转换为MBR分区模式

    现在新出的笔记本普遍自带WIN8系统,硬盘分区一般都采用GPT格式,但是包括WIN7及以下的系统都无法安装在GPT格式的硬盘上,因此,如果我们需要安装WIN7系统,需要将硬盘分区从GPT转换成MBR格 ...