【BZOJ4636】蒟蒻的数列 STL
【BZOJ4636】蒟蒻的数列
Description
Input
Output
Sample Input
2 5 1
9 10 4
6 8 2
4 6 3
Sample Output
题解:当一段区间先进行操作l,r,a,再进行操作l,r,b时,最后的结果一定是a,b中的最大值,那我们直接离线处理。对于每段区间,直接让它变成所有包含这段区间的操作中的最大值。用multiset维护一下就好了
#include <cstdio>
#include <cstring>
#include <iostream>
#include <set>
#include <algorithm>
using namespace std;
typedef long long ll;
const int maxn=40010;
int n,tot;
ll ans;
multiset<ll> s;
struct node
{
int org,k;
ll v,val;
}p[maxn<<1];
bool cmp(node a,node b)
{
return a.v<b.v;
}
int main()
{
scanf("%d",&n);
int i,j;
for(i=1;i<=n;i++)
{
scanf("%lld%lld%lld",&p[tot+1].v,&p[tot+2].v,&p[tot+1].val);
if(p[tot+1].v==p[tot+2].v) continue;
p[tot+2].val=p[tot+1].val,p[tot+2].k=1,tot+=2;
}
sort(p+1,p+tot+1,cmp);
multiset<ll>::iterator it;
for(i=1;i<=tot;i++)
{
if(p[i].v!=p[i-1].v&&!s.empty())
{
it=s.end(),--it;
ans+=(p[i].v-p[i-1].v)*(*it);
}
if(p[i].k) it=s.find(p[i].val),s.erase(it);
else s.insert(p[i].val);
}
printf("%lld",ans);
return 0;
}
【BZOJ4636】蒟蒻的数列 STL的更多相关文章
- [BZOJ4636]蒟蒻的数列
[BZOJ4636]蒟蒻的数列 试题描述 蒟蒻DCrusher不仅喜欢玩扑克,还喜欢研究数列 题目描述 DCrusher有一个数列,初始值均为0,他进行N次操作,每次将数列[a,b)这个区间中所有比k ...
- [bzoj4636]蒟蒻的数列_线段树
蒟蒻的数列 bzoj-4636 题目大意:给定一个序列,初始均为0.n次操作:每次讲一段区间中小于k的数都变成k.操作的最后询问全局和. 注释:$1\le n\le 4\cdot 10^4$. 想法: ...
- BZOJ4636: 蒟蒻的数列(动态开节点线段树)
题意 题目链接 Sol 直接上动态开节点线段树 因为只有一次询问,所以中途不需要下传标记 #include<bits/stdc++.h> #define LL long long usin ...
- 【BZOJ-4636】蒟蒻的数列 动态开点线段树 ||(离散化) + 标记永久化
4636: 蒟蒻的数列 Time Limit: 30 Sec Memory Limit: 256 MBSubmit: 247 Solved: 113[Submit][Status][Discuss ...
- 【BZOJ】4636: 蒟蒻的数列
4636: 蒟蒻的数列 Time Limit: 30 Sec Memory Limit: 256 MBSubmit: 145 Solved: 71[Submit][Status][Discuss] ...
- BZOJ_4636_蒟蒻的数列_线段树+动态开点
BZOJ_4636_蒟蒻的数列_线段树+动态开点 Description 蒟蒻DCrusher不仅喜欢玩扑克,还喜欢研究数列 题目描述 DCrusher有一个数列,初始值均为0,他进行N次操作,每次将 ...
- BZOJ 4636: 蒟蒻的数列 分块
4636: 蒟蒻的数列 题目连接: http://www.lydsy.com/JudgeOnline/problem.php?id=4636 Description 蒟蒻DCrusher不仅喜欢玩扑克 ...
- 【bzoj4636】蒟蒻的数列 离散化+线段树
原文地址:http://www.cnblogs.com/GXZlegend/p/6801379.html 题目描述 蒟蒻DCrusher不仅喜欢玩扑克,还喜欢研究数列 题目描述 DCrusher有一个 ...
- 【刷题】BZOJ 4636 蒟蒻的数列
Description 蒟蒻DCrusher不仅喜欢玩扑克,还喜欢研究数列 题目描述 DCrusher有一个数列,初始值均为0,他进行N次操作,每次将数列[a,b)这个区间中所有比k小的数改为k,他想 ...
随机推荐
- Spring Boot 概念知识
转 http://rapharino.com/coder/Spring-Boot-Induction/ Spring Boot Induction 发表于 2016-10-29 | 分类于 c ...
- java程序猿常用Linux命令
1.查找文件 find / -name filename.txt 根据名称查找/目录下的filename.txt文件. find . -name "*.xml" 递归查找所有的xm ...
- vsftp 无法启动,500 OOPS: bad bool value in config file for: anonymous_enable
朋友的FTP启动不了,叫我帮他看,启动时出现以下错误信息: 500 OOPS: bad bool value in config file for: anonymous_enable 看似配置文件错误 ...
- Android Study 之 初识ButterKnife(8.5.1)及简单运用
LZ-Says:突然间不知道说什么好,祝大家编码无bug吧~ 前言 话说,Android开发的兄弟们都知道,每次初始化控件,设置对应的事件.写的那点过程多并且恶心.我们先一块回想下不堪的以前~ 那些年 ...
- [svc]nginx优化25条
参考:
- 每日英语:Who Ruined The Humanities?
You've probably heard the baleful reports. The number of college students majoring in the humanities ...
- vue2.0实现图片加载失败默认显示图片
<div class="bg"> <img :src="goods.phoneFloorAd.resUrl" :onerror="e ...
- Java GC 日志解析
JVM 在Java应用程序优化中是不可缺少的一大重项,如何合理配置Java参数,如果验证配置参数的有效性,从GC日志中可以获得很重要的提示,以下是笔者对GC垃圾收集器默认开启的组合日志的部分的解析,希 ...
- jquery文件导入问题
开发前台web,导入jquery文件的时候最好用 <script type="text/javascript" src="path"></sc ...
- C++-教程3-VS2010C++各种后缀说明
相关资料:"http://blog.csdn.net/kibaamor/article/details/18700607""http://blog.chinaunix.n ...