Codeforces 931F - Teodor is not a liar!
思路:
最长上升子序列
先差分数组染色
如果存在一个点,被所有区间包含,那么这张图一定是山峰状,如下图:

那么只要分别从前和从后找一个最长非严格上升子序列,然后从前往后更新就可以找出最大的山峰序列的长度,这个就是答案
代码:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mem(a,b) memset(a,b,sizeof(a)) const int N=1e5+;
const int INF=0x3f3f3f3f;
int a[N],dp[N],pre[N],suf[N];
int main(){
ios::sync_with_stdio(false);
cin.tie();
cout.tie();
int n,m,l,r;
cin>>n>>m;
for(int i=;i<=n;i++)cin>>l>>r,a[l]++,a[r+]--;
for(int i=;i<=m;i++)a[i]+=a[i-];
mem(dp,INF);
for(int i=;i<=m;i++){
*upper_bound(dp+,dp+m+,a[i])=a[i];
pre[i]=lower_bound(dp+,dp+m+,INF)-dp-;
}
mem(dp,INF);
for(int i=m;i>=;i--){
*upper_bound(dp+,dp+m+,a[i])=a[i];
suf[i]=lower_bound(dp+,dp+m+,INF)-dp-;
}
int ans=;
for(int i=;i<=m;i++)ans=max(ans,pre[i]+suf[i+]);
cout<<ans<<endl;
return ;
}
Codeforces 931F - Teodor is not a liar!的更多相关文章
- Codeforces 931.F Teodor is not a liar!
F. Teodor is not a liar! time limit per test 1 second memory limit per test 256 megabytes input stan ...
- Codeforces Round #422 (Div. 2) E. Liar 后缀数组+RMQ+DP
E. Liar The first semester ended. You know, after the end of the first semester the holidays beg ...
- Codeforces Round #422 (Div. 2)E. Liar sa+st表+dp
题意:给你两个串s,p,问你把s分开顺序不变,能不能用最多k段合成p. 题解:dp[i][j]表示s到了前i项,用了j段的最多能合成p的前缀是哪里,那么转移就是两种,\(dp[i+1][j]=dp[i ...
- Codeforces Round #468 Div. 2题解
A. Friends Meeting time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- 【codeforces】【比赛题解】#931 CF Round #468 (Div. 2)
因为太迟了,所以没去打. 后面打了Virtual Contest,没想到拿了个rank 3,如果E题更快还能再高,也是没什么想法. [A]Friends Meeting 题意: 在数轴上有两个整点\( ...
- Codeforces Round #468(div2)
A Friends Meeting 题意:有两个人在数轴上的不同位置,现在他们需要到一个位置碰面.每次每人只能向左或向右走1个单位,轮流进行.每个人第一次走时疲劳度+1,第二次走时疲劳度+2,以此类推 ...
- Codeforces 822E Liar dp + SA (看题解)
Liar 刚开始感觉只要开个dp[ i ][ j ][ 0 / 1 ]表示处理了s的前 i 个用了 k 段, i 是否是最后一段的最后一个字符 的 t串最长匹配长度, 然后wa24, 就gg了.感觉这 ...
- Liar CodeForces - 822E (dp,后缀数组)
大意: 给定串$s,t$, 给定整数$x$, 求判断$t$是否能划分为至多$x$段, 使这些段在$s$中按顺序,不交叉的出现. 设$dp_{i,j}$表示$s$匹配到$i$位, 划分了$j$段, 匹配 ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
随机推荐
- rocketmq连接报connect to ip:10909 failed
一.代码重现如下: 二.错误描述: com.alibaba.rocketmq.client.exception.MQClientException: Send [1] times, still fai ...
- ubuntu+anaconda+tensorflow 及相关问题
配置tensorflow部分参考:https://blog.csdn.net/XUTIAN1129/article/details/78997633 装完anaconda, source ~/.bas ...
- weblogic10以下,许可证过期解决办法
weblogic10以后的版本已经不再使用license.bea的方式来进行软件授权,之前的历史版本oracle提供了一个免费的许可证更新. 1.首先进入oracle的官网下载地址http://www ...
- 快速自动安装dart
@"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat Non ...
- Connections in Galaxy War (逆向并查集)题解
Connections in Galaxy War In order to strengthen the defense ability, many stars in galaxy allied to ...
- Web、OAuth2/SSO相关拾遗
OAuth2认证相关:(SSO资源访问流程也应类似设计,它与OAuth2第三方认证.授权不同,是同一个应用系统间的认证.授权过程,且需要实现一个点授权,可访问所有点,一个点退出,收回所有点授权,且有时 ...
- 深度学习课程笔记(二)Classification: Probility Generative Model
深度学习课程笔记(二)Classification: Probility Generative Model 2017.10.05 相关材料来自:http://speech.ee.ntu.edu.tw ...
- Deep Reinforcement Learning for Visual Object Tracking in Videos 论文笔记
Deep Reinforcement Learning for Visual Object Tracking in Videos 论文笔记 arXiv 摘要:本文提出了一种 DRL 算法进行单目标跟踪 ...
- [bug] - 关于poi导入excel时间格式会减少8小时的问题.
这个bug发生在使用poi组件导入导出excel时,(这里是导入) 首先在excel中的格式设定是 yyyy-mm-dd hh:mm:ss 通过配套使用ExcelUtil中 getCellValue( ...
- Vue学习三:v-on:click命令及v-html命令学习
本文为博主原创,未经允许不得转载: 第一部分: v-on:click 命令讲解及使用方法 <!DOCTYPE html> <html lang="zh"> ...