当前位置:网站首页>Luogu p2048 [noi2010] super Piano (rmq+ priority queue)
Luogu p2048 [noi2010] super Piano (rmq+ priority queue)
2022-06-25 08:03:00 【Mfy's little brother 1】
Luogu P2048 [NOI2010] Super piano (RMQ+ Priority queue )
The question :
Yes n A note , The number is 1 to n . The first i The beauty of a note is A i A_i Ai
We need to find k A piece of music composed of super chords , The number of consecutive notes per paragraph x Satisfy L ≤ x ≤ R L\leq x\leq R L≤x≤R , Find the maximum value of the music's beauty .
Ideas :
A triple (x,l,r) Indicates that the left endpoint is x, Right endpoint (l,r). Set the subscript of the maximum value as t, Then the problem turns into a solution s u m [ t ] − s u m [ i − 1 ] sum[t]-sum[i-1] sum[t]−sum[i−1], because sum[i-1] Is the fixed value , So we need sum stay (l,r) The maximum value in the interval
Also pay attention to , Put the biggest (x,l,r) After use , To put (x,l,t-1) and (x,t+1,r) Put into the pile , Because the second largest value may exist
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=5e5+5;
ll sum[maxn],a[maxn],ans;
int n,L,R,k,table[maxn][30];
struct node{
int s,l,r,t;
ll val;
bool operator < (const node &x)const {
return val<x.val;
}
};
priority_queue<node>p;
void init() {
for (int i = 1; i <= n; i++) table[i][0] = i;
for (int j = 1; (1 << j) <= n; j++)
for (int i = 1; i + (1 << j) - 1 <= n; i++) {
int x = table[i][j - 1], y = table[i + (1 << (j - 1))][j - 1];
table[i][j] = sum[x] > sum[y] ? x : y;
}
}
int get(int l, int r) {
int d = log2(r - l + 1);
int x = table[l][d], y = table[r - (1 << d) + 1][d];
return sum[x] > sum[y] ? x : y;
}
int main(){
scanf("%d%d%d%d",&n,&k,&L,&R);
for(int i=1;i<=n;i++){
scanf("%lld",&a[i]);
sum[i]=sum[i-1]+a[i];
}
init();
for(int i=1;i+L-1<=n;i++){
int y=min(i+R-1,n);
int d=get(i+L-1,y);
p.push({
i,i+L-1,y,d,sum[d]-sum[i-1]});
}
while(k--){
node x=p.top();
p.pop();
ans+=x.val;
if(x.t-1>=x.l){
int d1=get(x.l,x.t-1);
p.push({
x.s,x.l,x.t-1,d1,sum[d1]-sum[x.s-1]});
}
if(x.t+1<=x.r){
int d2=get(x.t+1,x.r);
p.push({
x.s,x.t+1,x.r,d2,sum[d2]-sum[x.s-1]});
}
}
printf("%lld",ans);
}
边栏推荐
- RMQ interval maximum subscript query, interval maximum
- Looking for b-end product manager after years? I almost ruined myself
- How to select lead-free and lead-free tin spraying for PCB? 2021-11-16
- 使用Adobe Acrobat Pro调整PDF页面为统一大小
- PH neutralization process modeling
- c#ColorDialog更改文本颜色和FontDialog更改文本字体的使用示例
- 用函数的递归来解决几道有趣的题
- 电子学:第011课——实验 10:晶体管开关
- WebSocket的理解以及应用场景
- 现在通过开户经理发的开户链接股票开户安全吗?
猜你喜欢
Dietary intervention reduces cancer treatment-related symptoms and toxicity
电子学:第010课——实验 8:继电振荡器
Drawing of clock dial
CAN透传云网关CANIOT,CANDTU记录CAN报文远程收发CAN数据
PH neutralization process modeling
电子学:第010课——实验 9:时间与电容器
Knowledge sharing 𞓜 conventional laminated structure of six layer PCB
Pcb|about FPC reinforcement type
Machine learning notes linear regression of time series
飞机引气系统的建模与故障仿真
随机推荐
C WinForm panel custom picture and text
1464. maximum product of two elements in an array
深度学习系列48:DeepFaker
c#搭建ftp服务器并实现文件上传和下载
現在通過開戶經理發的開戶鏈接股票開戶安全嗎?
27. remove elements
MySQL simple permission management
将数据导入到MATLAB
Electronics: Lesson 014 - Experiment 15: intrusion alarm (Part I)
c#中设置lable控件的TextAlign属性控制文字居中的方法
Advantages and differences of three kinds of vias in PCB 2021-10-27
Luogu p3313 [sdoi2014] travel (tree chain + edge weight transfer point weight)
Can transparent cloud gateway caniot and candtu record can messages and send and receive can data remotely
CAN透传云网关CANIOT,CANDTU记录CAN报文远程收发CAN数据
不怕百战失利,就怕灰心丧气
bat启动.NET Core
【补题】2021牛客暑期多校训练营6-n
Est - il sûr d'ouvrir un compte d'actions maintenant via le lien d'ouverture de compte coiffé?
Knowledge sharing 𞓜 conventional laminated structure of six layer PCB
c#磁盘驱动器及文件夹还有文件类的操作