B. Problems for Round

题目连接:

http://www.codeforces.com/contest/673/problem/B

Description

There are n problems prepared for the next Codeforces round. They are arranged in ascending order by their difficulty, and no two problems have the same difficulty. Moreover, there are m pairs of similar problems. Authors want to split problems between two division according to the following rules:

Problemset of each division should be non-empty.

Each problem should be used in exactly one division (yes, it is unusual requirement).

Each problem used in division 1 should be harder than any problem used in division 2.

If two problems are similar, they should be used in different divisions.

Your goal is count the number of ways to split problem between two divisions and satisfy all the rules. Two ways to split problems are considered to be different if there is at least one problem that belongs to division 1 in one of them and to division 2 in the other.

Note, that the relation of similarity is not transitive. That is, if problem i is similar to problem j and problem j is similar to problem k, it doesn't follow that i is similar to k.

Input

The first line of the input contains two integers n and m (2 ≤ n ≤ 100 000, 0 ≤ m ≤ 100 000) — the number of problems prepared for the round and the number of pairs of similar problems, respectively.

Each of the following m lines contains a pair of similar problems ui and vi (1 ≤ ui, vi ≤ n, ui ≠ vi). It's guaranteed, that no pair of problems meets twice in the input.

Output

Print one integer — the number of ways to split problems in two divisions.

Sample Input

5 2

1 4

5 2

Sample Output

2

题意

有n道题,他们的编号就是他们的难度,你需要把这些题目分到div1和div2去

div1的题目难度都应该比div2高

现在给你m个关系,a[i],b[i]表示,a[i]和b[i]应该在不同的div

问你一共有多少种分类的方式

题解:

枚举每一个位置,前面的全部扔到div2去,后面的全部扔到div1去

看是否合法就好了

前面的不能有div1的题目,后面的不能有div2的,就检查这个就好了

代码

#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+6;
int a[maxn],b[maxn],flag[maxn],n,m,ma[maxn],mi[maxn];
int main()
{
scanf("%d%d",&n,&m);
for(int i=1;i<=m;i++)
{
scanf("%d%d",&a[i],&b[i]);
if(a[i]>b[i])swap(a[i],b[i]);
if(flag[a[i]]==2)return puts("0");
if(flag[b[i]]==1)return puts("0");
flag[a[i]]=1,flag[b[i]]=2;
}
for(int i=1;i<=n+1;i++)
ma[i]=0,mi[i]=100;
for(int i=1;i<=n;i++)
ma[i]=max(ma[i-1],flag[i]);
for(int i=n;i>=1;i--)
{
if(flag[i]==0)mi[i]=mi[i+1];
else
{
if(mi[i+1]==100)mi[i]=flag[i];
else mi[i]=min(flag[i],mi[i+1]);
}
}
int ans = 0;
for(int i=1;i<n;i++)
if(ma[i]<=1&&mi[i+1]>=2)ans++;
cout<<ans<<endl;
}

Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) B. Problems for Round 水题的更多相关文章

  1. Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) B

    B. Problems for Round time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  2. Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition)只有A题和B题

    连接在这里,->点击<- A. Bear and Game time limit per test 2 seconds memory limit per test 256 megabyte ...

  3. Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) D Bear and Two Paths

    题目链接: http://codeforces.com/contest/673/problem/D 题意: 给四个不同点a,b,c,d,求是否能构造出两条哈密顿通路,一条a到b,一条c到d. 题解: ...

  4. Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) C - Bear and Colors

    题目链接: http://codeforces.com/contest/673/problem/C 题解: 枚举所有的区间,维护一下每种颜色出现的次数,记录一下出现最多且最小的就可以了. 暴力n*n. ...

  5. Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) D. Bear and Two Paths 构造

    D. Bear and Two Paths 题目连接: http://www.codeforces.com/contest/673/problem/D Description Bearland has ...

  6. Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) C. Bear and Colors 暴力

    C. Bear and Colors 题目连接: http://www.codeforces.com/contest/673/problem/C Description Bear Limak has ...

  7. Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) A. Bear and Game 水题

    A. Bear and Game 题目连接: http://www.codeforces.com/contest/673/problem/A Description Bear Limak likes ...

  8. Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition)

    A.暴力枚举,注意游戏最长为90分钟 B.暴力,c[l]++,c[r]--,记录中间有多长的段是大小为n的,注意特判m=0的情况 C.暴力枚举,我居然一开始没想出来!我一直以为每次都要统计最大的,就要 ...

  9. Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) D

    D. Bear and Two Paths time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

随机推荐

  1. collision

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAd0AAACYCAIAAAAuvaRSAAAAA3NCSVQICAjb4U/gAAAgAElEQVR4Xu

  2. haproxy代理https配置方法【转】

    记得在之前的一篇文章中介绍了nginx反向代理https的方法,今天这里介绍下haproxy代理https的方法: haproxy代理https有两种方式:1)haproxy服务器本身提供ssl证书, ...

  3. JBoss6.1.0修改启动jvm内存以及修改日志级别【转】

    转自 JBoss6.1.0修改启动jvm内存以及修改日志级别 - liangbinny的专栏 - 博客频道 - CSDN.NEThttp://blog.csdn.net/liangbinny/arti ...

  4. 使用数据库管理工具打开MySql

    1.推荐使用软件:Navicat_Premium_11.0.10.exe.  下载地址:http://pan.baidu.com/s/1nu6mTF7 2.下载上面文件并安装. 3.打开Navicat ...

  5. Tomcat实现多域名之间session共享

    最近启用二级域名后,面临一个主域名与二级域名之间 session 不能共享的问题,带来的麻烦就是用户在主域名登陆,但由于二级域名 session 不能共享 ,因此无法进行登陆的操作,对一些功能有一些影 ...

  6. [转]关于MyEclipse下的项目无法使用BASE64Encoder问题的解决办法

    [链接] http://blog.csdn.net/longlonglongchaoshen/article/details/75087616

  7. Golang新起航!(编译安装go)

    别废话,直接上~ linux下安装GO1.8 1.下载go的版本 国内地址源:https://dl.gocn.io/ 在这里选择源码的方式安装,在安装go的时候是需要gcc的,所以你的linux系统需 ...

  8. find命令的使用

    在以.conf结尾的文件里面查找含有aaa字符串的那一行   ( -name后面可以写  "*.*"   即匹配所有的文件 ) find / -name "*.conf& ...

  9. git ——本地项目上传到git

    1.(先进入项目文件夹)通过命令 git init 把这个目录变成git可以管理的仓库 git init 2.把文件添加到版本库中,使用命令 git add .添加到暂存区里面去,不要忘记后面的小数点 ...

  10. linux虚拟机磁盘不够用以及进行扩容时遇到的问题

    我使用的是:gparted live cd工具  系统是centOS6.2 使用gparted live cd工具进行无损分区,方法很简单,下载iso文件都在VMware对应的linux系统上设置CD ...