当前位置:网站首页>2022杭电多校第二场1011 DOS Card(线段树)
2022杭电多校第二场1011 DOS Card(线段树)
2022-08-01 06:40:00 【51CTO】
题目描述
DOS is a new single-player game that Kayzin came up with. At the beginning of the game you will be given n cards in a row, each with the number of value ai.
In each “matching” operation you can choose any two cards (we assume that the subscripts of these two cards are i,j(i<j). Notice that i is less than j), and you will get a score of (ai+aj)×(ai−aj).
Kayzin will ask you m times. In the k-th query, you need to select four cards from the cards with subscripts Lk to Rk, and “match” these four cards into two pairs (i.e., two matching operations, but the subscripts of the cards selected in the two matching operations must be different from each other. That is, a card can only be matched at most once. e.g., if you select four tickets with subscripts a, b, c, and d, matching a with b and c with d, or matching a with c and b with d are legal, but matching a with b and b with c is not legal), please calculate the maximum value of the sum of the two matching scores.
Note that the queries are independent of each other.
输入描述
The first line contains an integer T(T≤100) . Then T test cases follow. For one case,
The first line contains two integer n (4≤n≤2×105) and m (1≤m≤105) , n denotes the total number of cards , m denotes the number of times Kayzin queries.
The second line contains n integers a1,a2,…,an (1≤ai≤108), denotes the value of each card.
The next m lines contain Kayzin’s queries. The kth line has two numbers, Lk and Rk (1≤Lk≤Rk≤n), the input guarantees that Rk−Lk≥3
It is guaranteed that the sum of n over all test cases doesn’t exceed 2×105 and the sum of m over all test cases doesn’t exceed 2×05.
输出描述
Print m integer for each case, indicating the maximum scores that can be obtained by selecting four cards (two matching pairs)
题意:
给出长度为n的序列,m次询问,每次询问给出l,r表示区间范围,在[l,r]里选择四个数,两两配对,计算两对的最大值
思路:
输入数组的时候就将变为
方便后续处理
相当于选出四个数来,每个数对答案的贡献可以为正值也可以为负值
但是因为条件限制还有,所以只有
和
两种组合符合题意
区间的最值可以用线段树维护可以划分为
可以划分为
然后三个的为
其中可以划分为
其他的依次类推
pushup的时候,由左右子树当前值和组合的值的最大值转移
代码:
参考
边栏推荐
- Explosive 30,000 words, the hardest core丨Mysql knowledge system, complete collection of commands [recommended collection]
- Dart 异常详解
- leetcode43 string multiplication
- 用位运算为你的程序加速
- Compare two objects are the same depth
- 2022年牛客多校第四场补题
- 轻量级的VsCode为何越用越大?为什么吃了我C盘10G?如何无痛清理VsCode缓存?手把手教你为C盘瘦身
- Dell PowerEdge Server R450 RAID Configuration Steps
- 微信小程序获取手机号phonenumber.getPhoneNumber接口开发
- Qt Widget 项目对qml的加载实例
猜你喜欢

Windows taskbar icon abnormal solution

Information system project managers must recite the work of the core test site (56) Configuration Control Board (CCB)

NIO编程

Using FiddlerScript caught poly FiddlerScript 】 【 download

curl (7) Failed connect to localhost8080; Connection refused

Dart 异常详解

JS的运行原理

仿牛客网讨论社区项目—项目总结及项目常见面试题

Data organization -- singly linked list of the linear table

AspNet.WebApi.Owin 自定义Token请求参数
随机推荐
Datagrip error "The specified database userpassword combination is rejected..."Solutions
crypto-js使用
matplotlib pyplot
Jupyter shortcuts
"By sharing" northwestern university life service | | bytes a second interview on three sides by HR
企业员工人事管理系统(数据库课设)
响应式织梦模板园林花卉类网站
CSP-S2019兴奋不已
小白的0基础教程SQL: 关系数据库概述 02
NUMPY
AspNet.WebApi.Owin 自定义Token请求参数
Win任务栏图标异常解决
The solution to the inconsistency between the PaddleX deployment inference model and the GUI interface test results
matlab simulink 粒子群优化模糊pid控制的电机泵
uva12326
Vsce package after the Command failed: NPM list - production - parseable - the depth = 99999 - loglevel = error exception
目标检测概述-上篇
JS的运行原理
Offer刷题——1
CSP-S2019 Day1