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. ※C++随笔※=>☆C++基础☆=>※№→C++中 #include<>与#include""

    #include<> 使用尖括号表示在包含文件目录中去查找(包含目录是由用户在设置环境时设置的),而不在源文件目录去查找: #include"" 使用双引号则表示首先在 ...

  2. 彻底理解Cisco/Linux/Windows的IP路由

    -1.只要理解实质,名称并不重要! 很多使用Linux的网络高手在面对Cisco管理员的诸如管理距离,路由度量等词汇时,还没有PK就自觉败下阵来了.我觉得这实在太可惜了,大家本是一家,为何这么为难对方 ...

  3. 第一章 Android体系与系统架构

    1. Dalvik 和 ART(Android Runtime) 在Dalvik中应用好比是一辆可折叠的自行车,平时是折叠的,只有骑的时候,才需要组装起来用.在ART中应用好比是一辆组装好了的自行车, ...

  4. Linux 关闭及重启方式

    一.shutdown 命令 作用:关闭或重启系统 使用权限:超级管理员使用 常用选项 1. -r 关机后立即重启 2. -h关机后不重启 3. -f快速关机,重启时跳过fsck(file system ...

  5. 'Service' object has no attribute 'process'

    在使用selenium+phantomjs时,运行总是出现错误信息: 'Service' object has no attribute 'process' 出现该错误的原因是未能找到可执行程序&qu ...

  6. C#使用Process类调用外部程序(转)

    在程序开发中,一个程序经常需要去调用其他的程序,C#中Process类正好提供了这样的功能.它提供对本地和远程进程的访问并使您能够启动和停止本地系统进程.一.启动进程实例 Process myProc ...

  7. android 数字键盘制作

    //布局相关<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android ...

  8. Android Animation学习 实现 IOS 滤镜退出动画

    IOS的用户体验做的很好,其中一点很重要的地方就是动画效果. 最近在学习Android的Animation,简单实现了一个IOS相机滤镜退出的动画: 布局文件:activity_animation_d ...

  9. .net excel利用NPOI导入oracle

    1.链接数据库 引用System.Data.OracleClient: //数据库链接字符串   Data Source如:192.168.5.153:1521/orcl string linkStr ...

  10. SGU 128.Snake

    时间限制:0.25s 空间限制:4m 题意: 在一个平面坐标中有N个点,现在要你用这N个点构造一个闭合图形,这个图形要满足以下条件: 1.这个图形要是闭合的:          2.图形上的点只能是给 ...