当前位置:网站首页>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);
}
边栏推荐
- 协议和服务的区别?
- 洛谷P5994 [PA2014]Kuglarz(异或思维+MST)
- Electronics: Lesson 012 - Experiment 13: barbecue LED
- Electronics: Lesson 013 - Experiment 14: Wearable pulsed luminaries
- Anaconda navigator启动慢的一个解决方法
- WebSocket的理解以及应用场景
- 洛谷P2486 [SDOI2011]染色(树链+线段树 + 树上区间合并 )
- 深度学习系列48:DeepFaker
- [daily training] 207 Class Schedule Card
- 將數據導入到MATLAB
猜你喜欢

Pcb|about FPC reinforcement type

Take you through the normalization flow of GaN

用函数的递归来解决几道有趣的题

Technology blog | how to communicate using SSE

年后求职找B端产品经理?差点把自己坑惨了......

Electronics: Lesson 012 - Experiment 11: light and sound
![[little knowledge] PCB proofing process](/img/bf/f66677294a14baf08cc35d1e8c1e31.jpg)
[little knowledge] PCB proofing process

CAN透传云网关CANIOT,CANDTU记录CAN报文远程收发CAN数据

FM signal, modulated signal and carrier

时钟刻度盘的绘制
随机推荐
电子学:第011课——实验 10:晶体管开关
C # set up FTP server and realize file uploading and downloading
Sword finger offer II 027 Palindrome linked list
Application of can optical transceiver of ring network redundant can/ optical fiber converter in fire alarm system
Est - il sûr d'ouvrir un compte d'actions maintenant via le lien d'ouverture de compte coiffé?
【补题】2021牛客暑期多校训练营9-n
Electronics: Lesson 014 - Experiment 15: intrusion alarm (Part I)
【莫比乌斯反演】
电子学:第014课——实验 15:防入侵报警器(第一部分)
Opencv minimum filtering (not limited to images)
电子学:第012课——实验 13:烧烤 LED
唐老师讲运算放大器(第七讲)——运放的应用
To understand the difference between Gram-positive and Gram-negative bacteria and the difference in pathogenicity
420-二叉树的层序遍历2(429. N 叉树的层序遍历、515.在每个树行中找最大值、116.填充每个节点的下一个右侧节点指针、104.二叉树的最大深度、111.二叉树的最小深度)
Luogu p2839 [national training team]middle (two points + chairman tree + interval merging)
417-二叉树的层序遍历1(102. 二叉树的层序遍历、107.二叉树的层次遍历 II、199.二叉树的右视图、637.二叉树的层平均值)
Matlab代码格式一键美化神器
Luogu p3313 [sdoi2014] travel (tree chain + edge weight transfer point weight)
Machine learning notes linear regression of time series
C WinForm panel custom picture and text