当前位置:网站首页>A. Prefix range
A. Prefix range
2022-06-12 11:57:00 【Desert –】
subject


Ideas
This question is relatively simple , Directly traversing a given n An integer , Just write it down directly in front of i Maximum and minimum values for nodes , And before writing it down i Extreme value of nodes , Finally, you can give it when you ask .
Code
#include<stdio.h>
int main()
{
int n,q;
int a[150000];
int flag[150000];
scanf("%d %d",&n,&q);
scanf("%d",&a[0]);
int max=a[0],min=a[0];
flag[1]=max-min;
for(int i=1;i<n;i++){
scanf("%d",&a[i]);
if(a[i]>max){
max=a[i];
}
if(a[i]<min){
min=a[i];
}
flag[i+1]=max-min;
}
int x;
q--;
scanf("%d",&x);
printf("%d",flag[x]);
while(q--){
scanf("%d",&x);
printf(" %d",flag[x]);
}
}
边栏推荐
- LeetCode 890. 查找和替换模式(模拟+双哈希表)
- mysql复习
- Google Earth Engine(GEE)——Kmeans聚类快速进行土地分类(双for循环快速调参)
- 异步路径处理
- Go sends SMS based on alicloud
- UML系列文章(31)体系结构建模---部署图
- 无重复字符的最长字符串(LeetCode 3)
- PDSCH 相关
- TinyMCE series (I) TinyMCE environment construction
- Lambda and filter, List 和 numpy array的索引,以及各种距离指标distance-metrics,拼接数组以及axis=0 and axis=1的区分
猜你喜欢

5G NR協議學習--TS38.211下行通道

QT adds a summary of the problems encountered in the QObject class (you want to use signals and slots) and solves them in person. Error: undefined reference to `vtable for xxxxx (your class name)‘

QML学习 第一天

创建Servlet项目

6.6 rl:mdp and reward function

A.前缀极差

UML系列文章(30)体系结构建模---制品图

QML first day

无重复字符的最长字符串(LeetCode 3)

ARM处理器模式与寄存器
随机推荐
Spark常用封装类
Design of tablewithpage
Reasons for SSL introduction and encryption steps
The second regular match is inconsistent with the first one, and the match in the regular loop is invalid
判断网络文件是否存在,获取网络文件大小,创建时间、修改时间
邻居子系统之邻居项状态更新
[database] SQLite version upgrade and downgrade
QT添加QObject类(想使用信号和槽)遇到的问题汇总,亲测解决有效error: undefined reference to `vtable for xxxxxx(你的类名)‘
Linear model of machine learning
Google Earth Engine(GEE)——Kmeans聚类快速进行土地分类(双for循环快速调参)
Cookies and sessions
ARM指令集之数据处理指令寻址方式
单元测试用例框架--unittest
Load/store access instruction of arm instruction set (2)
UML series articles (30) architecture modeling -- product diagram
Basic concepts of machine learning
Kubernetes cluster setup
一个人必须不停地写作,才能不被茫茫人海淹没。
文件夹目录结构自动生成
Record the pits encountered when using JPA