就是线段树的单点修改和区间查询。

然而输入打了一个小时才弄清楚。

 #include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define MN 100000
#define R return
#define INF 0x3f3f3f3f
char ch;
inline int read(){
int x = ; ch=getchar();
while(ch < ''||ch > '') ch=getchar();
while(ch >=''&&ch <='') x = x* + ch - '',ch = getchar();
R x ;
}
int tree[MN*+];
int n,q,a[MN+],cha[],cnt,l,r;
void init(int t,int a,int b,int l,int add){
int m=a+(b-a)/;
if(a==b){tree[t]=add;R;}
if(m>=l) init(t<<,a,m,l,add);
if(m<l) init(t<<|,m+,b,l,add);
tree[t]=min(tree[t<<],tree[t<<|]);
}
int query(int t,int a,int b,int l,int r){
if(l<=a&&b<=r) R tree[t];
int m=(a+b)/,ans=INF;
if(l<=m) ans=min(ans,query(t<<,a,m,l,r));
if(m<r) ans=min(ans,query(t<<|,m+,b,l,r));
R ans;
}
void evlos(bool k){
if(k){
l=read();r=read();
printf("%d\n",query(,,n,l,r));
}
if(!k){
cnt=; cha[++cnt]=read();
while(ch==',') cha[++cnt]=read();
cha[++cnt]=cha[];
for(int i=;i<cnt;i++) init(,,n,cha[i],a[cha[i+]]);
int v=a[cha[]];
for(int i=;i+<cnt;i++) a[cha[i]]=a[cha[i+]];
a[cha[cnt-]]=v;
}
}
void solve(){
bool k;
ch=getchar();
while(ch!='q'&&ch!='s') ch=getchar();
if(ch=='q') k=;
if(ch=='s') k=;
while(ch!='(') ch=getchar();
evlos(k);
}
int main(){
n=read();q=read();
for(int i=;i<=n;i++) a[i]=read(),init(,,n,i,a[i]);
while(q--) solve();
R ;
}

——————————————————————————————————————————————————————————

来自Paper Cloud的博客,未经允许,请勿转载,谢谢。

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. UVa 12299 RMQ with Shifts(线段树)

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

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

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

  4. 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 ...

  5. 【UVA】12299-RMQ with Shifts(线段树)

    改动的时候因为数据非常小,所以能够直接暴力改动,查询的时候利用线段树即可了. 14337858 option=com_onlinejudge&Itemid=8&page=show_pr ...

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

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

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

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

  8. RMQ with Shifts(线段树)

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

  9. C. RMQ with Shifts

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

随机推荐

  1. 线程并发工具类之CountDownLatch的使用及原理分析

    原文链接:http://www.studyshare.cn/blog/details/1149/1 java开发工具下载地址及安装教程大全,点这里.更多技术文章,在这里. 一.定义 CountDown ...

  2. 读取txt文件的数据,并将其转换为矩阵

    import numpy as nppath_txt_data = 'C:/Users/51102/Desktop/my_yolo/data/box/train.txt'def input_data( ...

  3. win10下jupyter修改默认路径的办法

    查了很多资料,发现都不管用,最后亲测找到一种方法. 实现的方法就是修改快捷方式标签的目标栏,如下图: 后面有一个%USERPROFILE% 将%USERPROFILE%改成你要的路径就可以了 然后应用 ...

  4. iptables限制访问

    iptables限制访问 常用命令 # 查看规则 iptables -L INPUT --line-numbers # 开放指定的端口 iptables -A INPUT -p tcp --dport ...

  5. ASPxComboBox默认情况下不显示代码和名称,特别头疼,直到发现了关键

    1.ASPxComboBox 默认不开启 AutoPostBack: 既是开启,总显示第一行(好像是个bug) 2.只好ajax,但是默认情况下不显示代码和名称,特别头疼,直到发现了关键 <dx ...

  6. Linux-firewall防火墙

    systemctl status firewalld firewall-cmd --zone=public --list-ports ##查看已开放的端口 2.添加5901端口到白名单 执行 fire ...

  7. Linux 系统安全相关

    本篇关于Linux的一些安全知识,主要就是与账号相关的安全. 账户文件锁定 当服务器中的用户账号已经固定,不在进行更改,可锁定账户文件.锁定后,无法添加.删除账号,也无法更改密码等. 锁定账户文件 c ...

  8. keepalived+nginx+lnmp 网站架构

    <网站架构演变技术研究> 项目实施手册 2019年8月2日 第一章:  实验环境确认 4 1.1-1.系统版本 4 1.1-2.内核参数 4 1.1-3.主机网络参数设置 4 1-1-4 ...

  9. 小白式Git使用教程,从0到1

    Git是什么? Git是目前世界上最先进的分布式版本控制系统.工作原理 / 流程: Workspace:工作区 Index / Stage:暂存区 Repository:仓库区(或本地仓库) Remo ...

  10. c++的boost库

    c++ 的boost库的理解? 参考:http://zh.highscore.de/cpp/boost/introduction.html https://www.cnblogs.com/lidabo ...