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!的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 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 ...

  4. Codeforces Round #468 Div. 2题解

    A. Friends Meeting time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  5. 【codeforces】【比赛题解】#931 CF Round #468 (Div. 2)

    因为太迟了,所以没去打. 后面打了Virtual Contest,没想到拿了个rank 3,如果E题更快还能再高,也是没什么想法. [A]Friends Meeting 题意: 在数轴上有两个整点\( ...

  6. Codeforces Round #468(div2)

    A Friends Meeting 题意:有两个人在数轴上的不同位置,现在他们需要到一个位置碰面.每次每人只能向左或向右走1个单位,轮流进行.每个人第一次走时疲劳度+1,第二次走时疲劳度+2,以此类推 ...

  7. Codeforces 822E Liar dp + SA (看题解)

    Liar 刚开始感觉只要开个dp[ i ][ j ][ 0 / 1 ]表示处理了s的前 i 个用了 k 段, i 是否是最后一段的最后一个字符 的 t串最长匹配长度, 然后wa24, 就gg了.感觉这 ...

  8. Liar CodeForces - 822E (dp,后缀数组)

    大意: 给定串$s,t$, 给定整数$x$, 求判断$t$是否能划分为至多$x$段, 使这些段在$s$中按顺序,不交叉的出现. 设$dp_{i,j}$表示$s$匹配到$i$位, 划分了$j$段, 匹配 ...

  9. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

随机推荐

  1. JavaWeb创建的文件夹默认在tomcat/bin中

    系统项目中需要设置缓存目录,原本项目中的目录设置为D:/cache目录,这怎么成?于是手动改成了cache目录,原本想使用了相对路径,web项目能够把缓存路径设置到tomcat的webapp的具体项目 ...

  2. 01: flask基础

    1.1 flask介绍   参考博客: https://www.cnblogs.com/sss4/p/8097653.html 1.django.tornado.flask比较 1. Django:1 ...

  3. 第三周作业HAproxy文件操作

    #coding:utf-8 #Author:Mr Zhi """ HAproxy配置文件操作: 1. 根据用户输入输出对应的backend下的server信息 2. 可添 ...

  4. 使用Navicat for MySQL添加外键约束

    转载:http://blog.csdn.net/u013215018/article/details/54981216 现在有两个表一张是Roles表(角色表),一张是RoleUser表(用户角色) ...

  5. Mac10.13 telnet不能用的解决方法

    telnet在Mac 10.13上不能用了 Restore的方法 brew install inetutils To be clear, brew install inetutils will ins ...

  6. Oracle常用函数——COALESCE

    COALESCE 含义:COALESCE是一个函数, (expression_1, expression_2, ...,expression_n)依次参考各参数表达式,遇到非null值即停止并返回该值 ...

  7. Python3基础 dict in/not in 查询一个字符是否指定字典的键或者值

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  8. git使用操作

    git config --system --unset credential.helper 重置git

  9. 源码编译安装libtool工具

    1. 获取源码 wget http://ftpmirror.gnu.org/libtool/libtool-2.4.6.tar.gz tar xvf libtool-2.4.6.tar.gz -C ~ ...

  10. POJ 3264 Balanced Lineup (线段树查找最大最小值)

    http://poj.org/problem?id=3264 题意:给你一个长度为n的序列a[N] (1 ≤ N ≤ 50000),询问Q(1 ≤ Q ≤ 200000) 次,每次输出[L, R]区间 ...