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. SQl 跨服务器查询脚本示例

    1.采用OPENDATASOURCE select top 10 *from OPENDATASOURCE('SQLOLEDB','Data Source=IP地址;User ID=连接用户名称;Pa ...

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

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

  3. python实现单单链表

    # -*- coding: utf-8 -*- # @Time : 2018/9/28 22:09 # @Author : cxa # @File : node.py # @Software: PyC ...

  4. Logback的继承体系

    今天碰到一个问题,发现控制台日志输出两遍,搜索得知,这个是由于logback继承体系导致的. logback不仅会继承level,也会继承appender,需要注意的是: <root> & ...

  5. MongoDB官方文档结构

    本文展示MongoDB 3.6.4.0的官方Server文档的结构图——一眼可见完整的知识脉络图.不过,MongoDB除了Server的文档外,还有DRIVERS.CLOUD.TOOLS.DUIDES ...

  6. 博客转移至github

    博客转移到github 鉴于github的各种优势,博客转移!

  7. 洛谷P1286 两数之和

    这个题.. 刚开始没看见输入若干行,所以有的点就.. 令 m = n * (n - 1) / 2 已知 s = {s (1), s(2), ..., s(m)}, s(i) <= s(i+1) ...

  8. java jps命令使用解析

    在linux环境下显示一个进程的信息大家可能一直都在使用ps命令,比如用以下命令来显示当前系统执行的java进程: ps -ef | grep java 针对java的进程,jdk1.5以后提供了一个 ...

  9. SQL Server中删除表中重复数据

    方法一:利用游标,但要注意主字段或标识列 declare @max integer,@id integer open cur_rows fetch cur_rows into @id,@max beg ...

  10. hdu 3951 硬币围成一圈(博弈)

    n个硬币围成一个环 每次只能取1-K个硬币 最后取完者胜 假如5个硬币 每次取1-2个情况1 先手取1个 后手取剩下4个中间2个 破坏了连续 虽然最后剩2个,但先手只能取一个 然后后再取一个 后手胜 ...