LibreOJ #514. 「LibreOJ β Round #2」模拟只会猜题意
题目描述

给定一个长度为 nnn 的序列 AAA 。
定义 f(l,r)=∑i=lrAif(l,r)=\sum_{i=l}^{r} A_{i}f(l,r)=∑i=lrAi。
询问 mmm 次,每次询问一个数字 xxx,请求出所有满足 r−l+1≥xr-l+1 \ge xr−l+1≥x 区间 [l,r][l,r][l,r] 中最大的 f(l,r)f(l,r)f(l,r)。
输入格式
第一行两个数,表示 nnn 和 mmm 。
之后 nnn 个数,表示序列 AAA。
之后 mmm 行每行一个数 xxx,表示询问 xxx 。
输出格式
输出 mmm 行,每行一个答案,表示最大的 f(l,r)f(l,r)f(l,r) 。
样例
样例输入
5 5
1 2 3 4 5
1
2
3
4
5
样例输出
15
15
15
15
15
数据范围与提示

前缀和就好
#include <cstring>
#include <cstdio>
#define N 10005 int sum[N],maxn[N],n,m;
inline int max(int a,int b) {return a>b?a:b;}
int main()
{
memset(maxn,-0x3f,sizeof(maxn));
scanf("%d%d",&n,&m);
for(int a,i=;i<=n;++i)
scanf("%d",&a),sum[i]=sum[i-]+a;
for(int i=;i<=n;++i)
for(int j=;j<=i;++j)
maxn[i-j+]=max(maxn[i-j+],sum[i]-sum[j-]);
for(int i=;i<=n;++i)
for(int j=i+;j<=n;++j)
maxn[i]=max(maxn[i],maxn[j]);
for(int x;m--;)
{
scanf("%d",&x);
printf("%d\n",maxn[x]);
}
return ;
}
LibreOJ #514. 「LibreOJ β Round #2」模拟只会猜题意的更多相关文章
- Loj514「LibreOJ β Round #2」模拟只会猜题意 - 模拟
注意初始化即可. #include <bits/stdc++.h> using namespace std; ],a[],t1,t2,t3,t4; int main(){ memset(a ...
- 汕头市队赛 SRM10 T1模拟只会猜题意
模拟只会猜题意 SRM 10 描述 有一本n个单词的词典,求按下列方法能造出的不相同的词汇数目. 1.词典中的单词是一个词. 2.能分为两部分的,其中前一部分是一个词典词或者其非空前缀,后一部分是一 ...
- loj514模拟只会猜题意
果然是道模拟... 一开始想线段树 看了一眼数据范围:“这tm不是前缀和吗” 然后水过 #include<iostream> #include<cstdio> #include ...
- LibreOJ #517. 「LibreOJ β Round #2」计算几何瞎暴力
二次联通门 : LibreOJ #517. 「LibreOJ β Round #2」计算几何瞎暴力 /* LibreOJ #517. 「LibreOJ β Round #2」计算几何瞎暴力 叫做计算几 ...
- LibreOJ #528. 「LibreOJ β Round #4」求和
二次联通门 : LibreOJ #528. 「LibreOJ β Round #4」求和 /* LibreOJ #528. 「LibreOJ β Round #4」求和 题目要求的是有多少对数满足他们 ...
- LibreOJ #527. 「LibreOJ β Round #4」框架
二次联通门 : LibreOJ #527. 「LibreOJ β Round #4」框架 /* LibreOJ #527. 「LibreOJ β Round #4」框架 %% xxy dalao 对于 ...
- LibreOJ #526. 「LibreOJ β Round #4」子集
二次联通门 : LibreOJ #526. 「LibreOJ β Round #4」子集 /* LibreOJ #526. 「LibreOJ β Round #4」子集 考虑一下,若两个数奇偶性相同 ...
- LibreOJ #525. 「LibreOJ β Round #4」多项式
二次联通门 : LibreOJ #525. 「LibreOJ β Round #4」多项式 官方题解 : /* LibreOJ #525. 「LibreOJ β Round #4」多项式 由于会有多种 ...
- LibreOJ #524. 「LibreOJ β Round #4」游戏
二次联通门 : LibreOJ #524. 「LibreOJ β Round #4」游戏 /* LibreOJ #524. 「LibreOJ β Round #4」游戏 找找规律就会发现.. 当有X的 ...
随机推荐
- SeetaFace教程(一) 在 VS 中的编译安装和环境配置
SeetaFace开源库由FaceDetection.FaceAlignment.FaceIdentification三部分组成.FaceDetection是在一副图片中检测出人脸区域,以一个方形区域 ...
- 面试题: 数据库 sql优化 sql练习题 有用 学生表,课程表,成绩表,教师表 练习
什么是存储过程?有哪些优缺点? 什么是存储过程?有哪些优缺点? 存储过程就像我们编程语言中的函数一样,封装了我们的代码(PLSQL.T-SQL). 存储过程的优点: 能够将代码封装起来 保存在数据库之 ...
- 转-tcp建立和释放详解
建立TCP需要三次握手才能建立,而断开连接则需要四次握手.整个过程如下图所示: 先来看看如何建立连接的. [更新于2017.01.04 ]该部分内容配图有误,请大家见谅,正确的配图如下,错误配图也不删 ...
- Maven 3 入门 -- 安装与配置
Maven 3 入门 -- 安装与配置 Maven以及其Eclipse插件m2eclipse的安装 (本文参考了Maven实战) 检查JDK的安装以及环境变量的配置 打开cmd echo %Java_ ...
- OpenType字体与TrueType字体的区别
TrueType采用几何学中二次B样条曲线及直线来描述字体的外形轮廓,其特点是:TrueType既可以作打印字体,又可以用作屏幕显示:由于它是由指令对字形进行描述,因此它与分辨率无关,输出时总是按照打 ...
- xgene:之illumina,,ion-torrent
illumina技术: 工具:flowcell(流动池):8通道,每个通道都有 2种DNA引物 种在玻璃表面(用共价键连到Flowcell上),这引物和文库中的接头互补 Flowcell:8个l ...
- 后缀数组dc3算法模版(待补)
模版: ; #define F(x) ((x)/3+((x)%3==1?0:tb)) #define G(x) ((x)<tb?(x)*3+1:((x)-tb)*3+2) int wa[maxn ...
- HDU - 6156 2017CCPC网络赛 Palindrome Function(数位dp找回文串)
Palindrome Function As we all know,a palindrome number is the number which reads the same backward a ...
- react-router-dom
创建: 2019/05/18 安装 npm install react-router-dom --save
- js call apply bind
call.apply.bindcat.call(dog, a, b) == cat.apply(dog, [a, b]) == (cat.bind(dog, a, b))() 1.作用 改变函数内的t ...