UVA 12299 RMQ with shifts
就是线段树的单点修改和区间查询。
然而输入打了一个小时才弄清楚。
- #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的更多相关文章
- UVa 12299 RMQ with Shifts(移位RMQ)
p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: "Times New ...
- UVa 12299 RMQ with Shifts(线段树)
线段树,没了.. ----------------------------------------------------------------------------------------- # ...
- UVA 12299 RMQ with Shifts(线段树:单点更新)
题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...
- 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 ...
- 【UVA】12299-RMQ with Shifts(线段树)
改动的时候因为数据非常小,所以能够直接暴力改动,查询的时候利用线段树即可了. 14337858 option=com_onlinejudge&Itemid=8&page=show_pr ...
- TOJ 4325 RMQ with Shifts / 线段树单点更新
RMQ with Shifts 时间限制(普通/Java):1000MS/3000MS 运行内存限制:65536KByte 描述 In the traditional RMQ (Range M ...
- nyoj 568——RMQ with Shifts——————【线段树单点更新、区间求最值】
RMQ with Shifts 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描述 In the traditional RMQ (Range Minimum Q ...
- RMQ with Shifts(线段树)
RMQ with Shifts Time Limit:1000MS Memory Limit:65535KB 64bit IO Format:%I64d & %I64u Pra ...
- C. RMQ with Shifts
C. RMQ with Shifts Time Limit: 1000ms Case Time Limit: 1000ms Memory Limit: 131072KB 64-bit intege ...
随机推荐
- 使用Filezilla Server配置FTP服务器
一.下载Filezilla Server 官网网址:https://filezilla-project.org 二.安装Filezilla Server Filezilla Server的安 ...
- Python进阶----数据库的基础,关系型数据库与非关系型数据库(No SQL:not only sql),mysql数据库语言基础(增删改查,权限设定)
day37 一丶Python进阶----数据库的基础,mysql数据库语言基础(增删改查,权限设定) 什么是数据库: 简称:DataBase ---->DB 数据库即存放数据的仓库, ...
- java反射 详解!!!!
java反射(特别通俗易懂) 反射是框架设计的灵魂 (使用的前提条件:必须先得到代表的字节码的Class,Class类用于表示.class文件(字节码)) 一.反射的概述 JAVA反射机制是在运行状态 ...
- CSS-服务器端字体笔记
服务器端字体 在CSS3中可以使用@font-face属性来利用服务器端字体. @font-face 属性的使用方法: @font-face{ font-family:webFont; src:ur ...
- C#创建DataTable(转载)
来源:https://www.cnblogs.com/xietianjiao/p/11213121.html方法一: DataTable tblDatas = new DataTable(" ...
- Ftp站点搭建的详细过程(包括指定用户登录)
最近接到要部署一个Ftp站点的一个任务,然后过程中有点小插曲踩了一些坑(指定用户登录,用户名和密码都是对的,输入了超级多遍,还是不行,登录不上,后面详细说明解决方案),特此记录一下.避免大家踩坑. 参 ...
- 关于小程序授权地理位置(wx.getLocation + 用户体验)
wx.getLocation 如果用户曾点击过一次 “确认授权” , 那么再次调用该接口时将不会出现弹出框(可以直接拿到经纬度) 关于用户体验: 在 onLoad 中判断: 如果用户之前“没有触发过“ ...
- 免费的天气API测试接口
网上几乎所有的天气接口都需要注册key,然后还各种频率限制,每天调用次数才几百次? 太坑爹了吧 一个简单的天气预报功能, 为什么要搞的这么复杂, 收什么费? 推荐一个真正免费的天气API接口, 返回j ...
- C语言中指针是什么?
学习交流可加 微信读者交流①群 (添加微信:coderAllen) 程序员技术QQ交流①群:736386324 --- ==恶名昭著的指针究竟是什么== " 指针是一种保存变量地址的变量,在 ...
- 泛微 e-cology OA 远程代码执行漏洞复现
0x00 前言 Poc已在github公开,由于环境搭建较为复杂,所以我在空间搜索引擎中找了国外的网站进行复现 如果有想自行搭建环境复现的可以在公众号内回复“泛微环境”即可获取源码及搭建方式 0x01 ...