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.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
随机推荐
- P5241 序列(滚动数组+前缀和优化dp)
P5241 序列 挺神仙的一题 看看除了dp好像没什么其他办法了 想着怎么构个具体的图出来,然鹅不太现实. 于是我们想办法用几个参数来表示dp数组 加了几条边肯定要的吧,于是加个参数$i$表示已加了$ ...
- hibernate validator自定义校验注解以及基于服务(服务组)的校验
hibernate validator是Bean Validation 1.1 (JSR 349) Reference Implementation,其广泛的应用在mvc的参数校验中,尤其是使用服务端 ...
- linux服务器启动报错UNEXPECTED INCONSISTENCY解决方法
内网的linux服务器给开发员用来测试以及共享文件使用,今天早上发现xshell连接不上该服务器,一开始进入系统显示reboot and select proper boot device or in ...
- MS08_067漏洞渗透攻击实践
MS08_067漏洞渗透攻击实践 实验前准备 1.两台虚拟机,其中一台为kali,一台为windows xp sp3(英文版). 2.在VMware中设置两台虚拟机网络为NAT模式,自动分配IP地址, ...
- centos 7.2 安装gitlab汉化
####################你如果搜到我的这个博客,你的系统得是centos 7的 80端口没有占用. QQ:1394466404 这个博客维护1年 #### 多地方第一个是百度 ...
- Git clone、git reset
一,git clone 1,git clone某一个分支 git clone -b <branch> <remote_repo> 2,.git 文件太大 :clone的时候,可 ...
- pillow生成验证码
1.结果 2.安装pillow cmd里进入python,pip install pillow,需要等一段时间 3.代码 from PIL import Image, ImageDraw, Image ...
- Eclipse关联Github
摘自:http://jingyan.baidu.com/article/64d05a0262f013de55f73bcc.html 检查Eclipse中是否已安装Git插件,菜单栏Help -> ...
- .NET Standard vs. .NET Core
What is the difference between .NET Core and .NET Standard Class Library project types? Answer1 When ...
- Optical Flow related Tutorials
Optical Flow related Tutorials 2017-04-01 10:50:55 Reference: 1. http://blog.csdn.net/carson2005/art ...