UVa 12299 - RMQ with Shifts 线段树 单点更新

BLE蓝牙胎压监测 胎压监测系统新技术 阅读详情



  RMQ with Shifts 

In the traditional RMQ (Range Minimum Query) problem, we have a static array A. Then for each query (L, R)(L$ \le$R), we report the minimum value among A[L], A[L + 1], ..., A[R]. Note that the indices start from 1, i.e. the left-most element is A[1].

In this problem, the array A is no longer static: we need to support another operation

shift(i1, i2, i3,..., ik)(i1 < i2 < ... < ik, k > 1)

we do a left ``circular shift" of A[i1], A[i2], ..., A[ik].

For example, if A={6, 2, 4, 8, 5, 1, 4}, then shift(2, 4, 5, 7) yields {6, 8, 4, 5, 4, 1, 2}. After that,shift(1, 2) yields 8, 6, 4, 5, 4, 1, 2.

Input 

There will be only one test case, beginning with two integers n, q ( 1$ \le$n$ \le$100, 000, 1$ \le$q$ \le$250, 000), the number of integers in array A, and the number of operations. The next line contains n positive integers not greater than 100,000, the initial elements in array A. Each of the next q lines contains an operation. Each operation is formatted as a string having no more than 30 characters, with no space characters inside. All operations are guaranteed to be valid.


Warning: The dataset is large, better to use faster I/O methods.

Output 

For each query, print the minimum value (rather than index) in the requested range.

Sample Input 

7 5
6 2 4 8 5 1 4
query(3,7)
shift(2,4,5,7)
query(1,4)
shift(1,2)
query(2,2)

Sample Output 

1
4
6



The Seventh Hunan Collegiate Programming Contest 
Problemsetter: Rujia Liu, Special Thanks: Yiming Li & Jane Alam Jan

-------------------

因为只有交换元素的操作,所以数组里的值是固定的,可以先对num数组做shift处理,然后线段树单点更新求最小值。

scanf("%5s",s);读5个字符到串里。

------------------

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#define N 222222

using namespace std;

const int OO=1e9;

int num[N];

struct Tree
{
    int l;
    int r;
    int min;
} tree[N*4];

void push_up(int root)
{
    tree[root].min=min(tree[root<<1].min,tree[root<<1|1].min);
}

void build(int root,int l,int r)
{
    tree[root].l=l;
    tree[root].r=r;
    if(tree[root].l==tree[root].r)
    {
        tree[root].min=num[l];
        return;
    }
    int mid=(l+r)/2;
    build(root<<1,l,mid);
    build(root<<1|1,mid+1,r);
    push_up(root);
}
void update(int root,int pos,int val)
{
    if(tree[root].l==tree[root].r)
    {
        tree[root].min=val;
        return;
    }
    int mid=(tree[root].l+tree[root].r)/2;
    if(pos<=mid)
        update(root<<1,pos,val);
    else
        update(root<<1|1,pos,val);
    push_up(root);
}
int query(int root,int L,int R)
{
    if(L<=tree[root].l&&R>=tree[root].r)
        return tree[root].min;
    int mid=(tree[root].l+tree[root].r)/2,ret=OO;
    if(L<=mid) ret=min(ret,query(root<<1,L,R));
    if(R>mid) ret=min(ret,query(root<<1|1,L,R));
    return ret;
}

int main()
{
    int n,q,x,y;
    int stk[1111];
    int cnt;
    char s[11];
    while (~scanf("%d%d",&n,&q))
    {
        for (int i=1;i<=n;i++)
        {
            scanf("%d",&num[i]);
        }
        build(1,1,n);
        while (q--)
        {
            scanf("%6s",s);
            if (s[0]=='q')
            {
                scanf("%d,%d)",&x,&y);
                printf("%d\n",query(1,x,y));
                //cerr<<x<<" "<<y;
            }
            if (s[0]=='s')
            {
                char c;
                int rm;
                cnt=0;
                while (scanf("%d%c",&x,&c))
                {
                    stk[cnt++]=x;
                    if (cnt==1)
                    {
                        rm=num[stk[0]];
                    }
                    else
                    {
                        num[stk[cnt-2]]=num[stk[cnt-1]];
                        update(1,stk[cnt-2],num[stk[cnt-2]]);
                    }
                    if (c!=',') break;
                }
                num[stk[cnt-1]]=rm;
                update(1,stk[cnt-1],num[stk[cnt-1]]);
            }
        }
    }
    return 0;
}






  RMQ with Shifts 

In the traditional RMQ (Range Minimum Query) problem, we have a static array A. Then for each query (L, R)(L$ \le$R), we report the minimum value among A[L], A[L + 1], ..., A[R]. Note that the indices start from 1, i.e. the left-most element is A[1].

In this problem, the array A is no longer static: we need to support another operation

shift(i1, i2, i3,..., ik)(i1 < i2 < ... < ik, k > 1)

we do a left ``circular shift" of A[i1], A[i2], ..., A[ik].

For example, if A={6, 2, 4, 8, 5, 1, 4}, then shift(2, 4, 5, 7) yields {6, 8, 4, 5, 4, 1, 2}. After that,shift(1, 2) yields 8, 6, 4, 5, 4, 1, 2.

Input 

There will be only one test case, beginning with two integers n, q ( 1$ \le$n$ \le$100, 000, 1$ \le$q$ \le$250, 000), the number of integers in array A, and the number of operations. The next line contains n positive integers not greater than 100,000, the initial elements in array A. Each of the next q lines contains an operation. Each operation is formatted as a string having no more than 30 characters, with no space characters inside. All operations are guaranteed to be valid.


Warning: The dataset is large, better to use faster I/O methods.

Output 

For each query, print the minimum value (rather than index) in the requested range.

Sample Input 

7 5
6 2 4 8 5 1 4
query(3,7)
shift(2,4,5,7)
query(1,4)
shift(1,2)
query(2,2)

Sample Output 

1
4
6



The Seventh Hunan Collegiate Programming Contest 
Problemsetter: Rujia Liu, Special Thanks: Yiming Li & Jane Alam Jan

Google Earth Engine ——在 GEE 中计算面积含各类要素计算(土地分类为例) 在遥感应用中工作时,许多操作需要计算面积。例如,需要在监督分类后计算每个类所覆盖的面积,或者找出灾害后区域内受影响的面积。计算栅格和矢量的面积在大多数软件包中是一个简单的操作,但在 Google Earth Engine 中以稍微不同的方式完成 - 这可能会让初学者感到困惑。在这篇文章中,我将概述计算矢量和图像面积的方法。我们将涵盖以下主题,从简单到复杂。 特征的面积计算,即矢量数据 图像的面积计算(单类) 按类别计算图像的面积 按区域按类别计算图像的面积 按年按地区按类别计算图像的面积 准备数据 阅读详情

相关推荐

STM32F407 CanOpen主机实战:对象字典配置与多电机CIA402协议驱动详解

本文详细介绍了基于STM32F407的CanOpen主机开发实战,重点解析了对象字典的配置流程与多电机CIA402协议驱动方法。通过使用objdictedit工具配置SDO和PDO参数,并整合CanFestival协议栈,实现了对多个伺服电机的稳定同步控制。文章提供了从硬件连接到代码调试的完整指南,帮助开发者快速掌握工业现场的多轴运动控制技术。

plant的博客 536

RMQ with Shifts

RMQ with Shifts In the traditional RMQ (Range Minimum Query) problem, we have a static array A. Then for each query (L, R)(LR), we report the minimum value among A[L], A[L + 1], ..., A[R]. Note

2389

AI辅助Unity UI开发:从设计稿到Prefab的自动化实践

在游戏开发中,UI界面构建常涉及大量重复性工作,如UGUI布局、Prefab制作等。通过AI代码生成技术,可将设计稿自动转换为可编译的工程结构,其原理是结合结构化描述与项目规范,生成编辑器脚本,从而提升开发效率并减少人为错误。这一方法尤其适用于需要快速迭代的客户端开发场景,能有效降低UI卡顿风险。本文以Codex为例,详细介绍了从设计稿解析到Prefab生成的完整链路,并分享了Codex安装、接入DeepSeek等实操经验,帮助开发者将机械搬运交给AI,聚焦更高价值的设计决策。

weixin_27676369的博客 331

uva12299 RMQ with Shifts

RMQ with Shifts In the traditional RMQ (Range Minimum Query) problem, we have a static array A. Then for each query (L, R) (L$ \le$R), we report the minimum value among A[L], A[L + 1], ..., A[R].

eeeaaaaa的专栏 494

手把手教你构建轻量级CLIP模型:从理论到实践

本文手把手教你从零构建一个轻量级CLIP模型,深入解析其核心原理——对比学习,并提供完整的代码实践。通过精简的模型架构、数据准备和训练循环实现,帮助读者彻底理解多模态模型如何让图像与文本在共享空间中对齐,为学习更复杂的AI模型打下坚实基础。

weixin_29100927的博客 329

AI 生成 ECU 功能测试用例

本文分享了AI辅助汽车电子测试的实战经验。作者以某车企车身控制器(BCM)项目为例,对比了传统测试用例编写方式(需100小时)与AI辅助方式(仅3个工作日)的效率差异,实现76%的效率提升。文章详细展示了从需求文档生成测试用例的全过程,包括需求文档示例、AI提示词模板和AI生成的完整测试用例表格(涵盖正常功能、边界条件、异常场景等测试类型)。通过具体案例说明如何利用AI快速生成初稿后人工审核优化的方法,为ECU测试工程师提供了可复用的效率提升方案。

小明的博客 920

RMQ with Shifts(线段树单点跟新)

Problem Description In the traditional RMQ (Range Minimum Query) problem, we have a static array A. Then for each query (L, R) (L In this problem, the array A is no longer static: we need to suppo

青春无悔 1758

破解拼多多网页字体加密的Python实现(静态)

爬取或者复制粘贴出来发现数字不是6372,而是这样的一个东西 ""从上图我们可以看出数字是一行的空白,后面被浏览器渲染后才展现的数字。我们可以用这个代码查看十六位进制对应的十进制,为什么要看十进制呢?​,而字体文件中的字符映射关系(cmap)也是以十进制存储的。我们搜索这个属性我们可以看到第一个这样的属性有一个URL,这个就是解密的字体包。然后我们构造一个这样的映射字典 key就是对应的十进制,后面的值就是对应的数字。然后我们需要封装一个函数,将加密文字和映射字典传入,返回解密后的数字。

weixin_64179111的博客 3551

RMQ with Shifts (线段树)

In the traditional RMQ (Range Minimum Query) problem, we have a static array A. Then for eachquery (L, R) (L ≤ R), we report the minimum value among A[L], A[L + 1], . . . , A[R]. Note that theindices ...

a1046765624的博客 506

软件工程期末知识点总结【超详细】

生命周期模型(过程模型):瀑布模型、快速原型模型、增量模型、螺旋模型、喷泉模型。2、实体联系图:1、数据对象2、属性3、联系(1:1、1:N、M:N)3、语句覆盖 就是设计足够的调试用例,使得程序中的每个语句至少执行一次。 5、判定覆盖就是设计足够的测试用例,使得程序中每个判定的取“真”分支和取“假”分支至少都执行一次,判定覆盖又称分支覆盖 6、条件覆盖就是设计足够的测试用例,使得程序判定中的每个条件能获得各种可能的结果。7、软件开发时期通常分成4个阶段:总体设计、详细设计、编码和单元测试、综合测试。

这个人好有趣....hh 1万+

MIPI CSI-2 协议解析

CSI-2标准协议前言一、Overview of CSI-2二、CSI-2 layer Definitions三、 Camera Control Interface(CCI)3.1 数据传输协议(Data Transfer Protocol)3.1.1 消息类型(Message Type)3.1.2 读写操作(Read/Write Operations)3.1.2.1 随机位置单次读3.1.2.2 当前位置单次读3.1.2.3 随机位置连续读3.1.2.4 当前位置连续读3.1.2.5 随机位置单次写3.1

Lucky 3万+

uva 12299 - RMQ with Shifts--- 线段树单点更新

// // main.cpp // uva 12299 - RMQ with Shifts--- 线段树单点更新 // // Created by XD on 15/9/10. // Copyright (c) 2015年 XD. All rights reserved. // /* 线段树单点更新 */ #include #include #include #include

最爱她! 534

STM32电机PID速度控制

2.3 STM32电机PID速度控制 之前的文章,完成了直流减速电机的PWM控制、电机测速。本篇文章,将实现电机的速度闭环控制。 在公众号:小白学移动机器人,发送:速度PID,即可获得本篇文章的STM32工程文件以及相关资料。 2.3.1 解决的问题 解决带编码器直流电机的速度闭环问题。 2.3.2 PID理论 将偏差的比例、积分、微分,通过线性组合构成控制量,用控制量对被控对象进行控制,这样的控制器称为PID控制器。在连续空间中,我们通常探讨模拟PID的控制原理,如图所示: 我们这里用电机速度控制为例,

「小白学移动机器人」一个专注分享移动机器人相关知识的公众号! 6万+

UVA12299 RMQ with Shifts 线段树查询 单点更新

线段树的题目,不是特别难,掌握单点更新 和 区间查找 即可,给一个数组,下标1到n,有一个shift操作,就是把它给你的下标 最前面一个放到最后面一个,相应位置的值也发生改变,然后有询问query(l,r)求出闭区间[l,r]的最小值,因为shift这一命令语句 题目说不超过30个字符,除去括号shift字符串 还有逗号,数字部分 最多也就13个,所以可以把这个强行用单点更新来做,有点暴力, 总

shaonianguai 917

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

UVa 12299 线段树 单点更新 RMQ with Shifts

因为shift操作中的数不多,所以直接用单点更新模拟一下就好了。 太久不写线段树,手好生啊,不是这错一下就是那错一下。 PS:输入写的我有点蛋疼,不知道谁有没有更好的写法。 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include &lt...

weixin_30721899的博客 89

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

uva 12299 RMQ with Shifts(线段树单点更新初步应用)

uva 12299 RMQ with Shifts In the traditional RMQ (Range Minimum Query) problem, we have a static array A. Then for each query (L, R) (LR), we report the minimum value among A[L], A[L + 1],

总有那么一群人喜欢盯着我的博客看,估计这是他们见过最长的博客名,我必须得告诉他们博客名最长可以写多长 540

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

UVA 12299 - RMQ with Shifts(线段树单点更新+模拟)

题目链接 https://cn.vjudge.net/problem/UVA-12299 【题意】 对于一个给定的数组A[1],A[2]…A[n],支持以下两种操作 query(L,R) 查询区间[L,R]中的最小元素值 shifti(i1,i2,..ik) 把元素A[i1],A[i2]…A[ik]的元素循环左移一位 如A={6,2,4,8,5,1,4},执行shift(2,4,5,7)...

Change the world by program. 281

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

题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=3720 题意:给你一个可变的数组A,有两种操作。操作一:shift(i1, i2....in),将数组中这些元素的值变为(A[i2], A[i3]....A[in], A...

weixin_30810583的博客 113

NYOJ-568/1012//UVA-12299RMQ with Shifts,线段树单点更新+区间查询

RMQ with Shifts 时间限制:1000 ms  |  内存限制:65535 KB 难度:3                                                                ->  Link1                                                                 

NYIST_TC_LYQ的博客 643

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

修改的时候由于数据很小,所以可以直接暴力修改,查询的时候利用线段树就行了。 14337858 12299 RMQ with Shifts Accepted C++ 0.282 2014-10-11 16:02:53 #include #include #include #include using namespace st

花月阁 1203

UVa 12299 RMQ with Shifts(移位RMQ)

UVa 12299 - RMQ with Shifts(移位RMQ) Time limit: 1.000 seconds Description - 题目描述 In the traditional RMQ (Range Minimum Query) problem, we have a static array A. Then for each query (L...

141

UVA 12299 RMQ with Shifts

线段树。单点更新,区间查询。就是说每次更新时,就按照题意,一个一个去修改。一开始我认为这样做会超时,跟队友商量了一下,也都认为会超时,但又想不到别的方法。。。。百度了一下,别人都说是水题,简单模板题,也都是这样做的。可能字符串长度不超过30使得更新的量不会太大,所以也不会TLE吧。 #pragma comment(linker, "/STACK:1024000000,1024000000")

DotACM 718

题解 UVA12299 【RMQ with Shifts】

题目简述: 给出n个数q个询问。对于query(a,b),输出区间(a,b)的数的最小值;对于shift(a0,a1,a2,......,an),则将第a1个数的值赋给a0,第a2个数赋给a1......,第an个数赋给an-1,第a0个数赋给an 主要思路:三叉 线段树 (单点修改,区间求最值) 其实就是一道比较裸的线段树模板题,因为题目中shift操作的字符长不超过30 char,也就是说没几...

weixin_30537391的博客 167

UVA 12299 RMQ with Shifts(线段树)

题目大意:第一行输入两个整数(数据个数,操作个数),query(a,b)为查找区间a到b的最小值,并输出。shift(a,b,c,d...)为将a,b,c,d...全部循环左移。 解析:线段树的单点更新。 #include #include #include #include using namespace std; const int INF = 0x3f3f3f3f; cons

小G的ACM之路 665

【UVA12299 RMQ with Shifts】

【Analysis】 这题其实在考输入吧,其他好像不难,shiftshiftshift就用线段树的单点修改即可 【Code】 #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include <queue> typedef long l...

zyn_615的博客 176
上一篇: Poj 2528 Mayor's posters 线段树 离散化 成段更新
下一篇: UVa 11992 - Fast Matrix Operations 成段更新,求最值与和
cyendra
博客等级 码龄14年 191粉丝 462原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值