博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
codeforces 673B B. Problems for Round(模拟)
阅读量:5129 次
发布时间:2019-06-13

本文共 2728 字,大约阅读时间需要 9 分钟。

题目链接:

time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

 

Examples
 
input
5 2 1 4 5 2
output
2
input
3 3 1 2 2 3 1 3
output
0
input
3 2 3 1 3 2
output
1
Note

In the first sample, problems 1 and 2 should be used in division 2, while problems 4 and 5 in division 1. Problem 3 may be used either in division 1 or in division 2.

In the second sample, all pairs of problems are similar and there is no way to split problem between two divisions without breaking any rules.

Third sample reminds you that the similarity relation is not transitive. Problem 3 is similar to both 1 and 2, but 1 is not similar to 2, so they may be used together.

 

题意:

把1到n这些数放到两个容器里,要求第一个容器里的任何数都小于第二个容器里的任何数,还有就是相似的不能放一块,相似没有传递性;

 

思路

两个容器第一个记录最大值,第二个记录最小值,对每一对相似的数,小的放在第一个,大的放在第二个,同时检测是否满足最大值最小值,还要更新最大最小;

还有wa点就是两个容器不能为空;

 

AC代码

 

#include 
using namespace std;#define Riep(n) for(int i=1;i<=n;i++)#define Riop(n) for(int i=0;i
=flag2||mmax<=flag1){cout<<"0"<
flag1)flag1=mmin; vis[mmin]=1; s1++; if(mmax
flag1&&i

 

转载于:https://www.cnblogs.com/zhangchengc919/p/5470093.html

你可能感兴趣的文章
steelray project viewer
查看>>
itext jsp页面打印
查看>>
HTTP之报文
查看>>
Perl正则表达式匹配
查看>>
Git
查看>>
DB Change
查看>>
nginx --rhel6.5
查看>>
Eclipse Python插件 PyDev
查看>>
selenium+python3模拟键盘实现粘贴、复制
查看>>
第一篇博客
查看>>
typeof与instanceof的区别
查看>>
网站搭建(一)
查看>>
SDWebImage源码解读之SDWebImageDownloaderOperation
查看>>
elastaticsearch
查看>>
postgreSQL 简单命令操作
查看>>
Spring JDBCTemplate
查看>>
Radon变换——MATLAB
查看>>
第五章笔记
查看>>
Iroha and a Grid AtCoder - 1974(思维水题)
查看>>
gzip
查看>>