Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) B
2 seconds
256 megabytes
standard input
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.
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.
Print one integer — the number of ways to split problems in two divisions.
5 2
1 4
5 2
2
3 3
1 2
2 3
1 3
0
3 2
3 1
3 2
1
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.
题意:n道题目区分为两部分 要求两部分不能为空 不能重复 div1的最低难度题目必须高于div2的最高难度 k对相似的题目 必须分在不同的部分 输出分类的方法数
题解: div1的最低难度题目必须高于div2的最高难度 对于k对相似的题目 保持u<v 从低到高记录 难度最高的题目l 从高到低记录难度最低的题目r
若l>r 则无法分类 输出0
若l<r 对于l~r的题目分到两个部分 共有r-l种
#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
#include<stack>
#include<map>
#define ll __int64
#define pi acos(-1.0)
using namespace std;
int n,m;
int exm1,exm2;
int l,r;
int main()
{
scanf("%d %d",&n,&m);
l=;
r=n;
for(int i=;i<=m;i++)
{
scanf("%d %d",&exm1,&exm2);
if(exm1>exm2)
swap(exm1,exm2);
l=max(l,exm1);
r=min(r,exm2);
}
if(r-l<)
cout<<""<<endl;
else
cout<<r-l<<endl;
return ;
}
Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) B的更多相关文章
- Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) B. Problems for Round 水题
B. Problems for Round 题目连接: http://www.codeforces.com/contest/673/problem/B Description There are n ...
- 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 ...
- 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. 题解: ...
- Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) C - Bear and Colors
题目链接: http://codeforces.com/contest/673/problem/C 题解: 枚举所有的区间,维护一下每种颜色出现的次数,记录一下出现最多且最小的就可以了. 暴力n*n. ...
- 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 ...
- 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 ...
- 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 ...
- Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition)
A.暴力枚举,注意游戏最长为90分钟 B.暴力,c[l]++,c[r]--,记录中间有多长的段是大小为n的,注意特判m=0的情况 C.暴力枚举,我居然一开始没想出来!我一直以为每次都要统计最大的,就要 ...
- 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章 MATLAB概述
MATLAB系统由~开发环境.~语言.~数学函数库.~图形处理系统.~应用程序接口(API)5大部分组成. 界面 命令行中的语句格式 命令行的语句格式:>>变量=表达式(没有>> ...
- QOS-QOS(服务质量)概述
QOS-QOS(服务质量)概述 2018年7月7日 20:29 概述及背景: 1. 引入: 传统IP网络仅提供“尽力而为”的传输服务,网络有可用资源就转发,资源不足时就丢弃 新一代IP网络承载了 ...
- Python自动化运维——DNS处理模块
Infi-chu: http://www.cnblogs.com/Infi-chu/ 模块:dnspython 功能: 支持所有的记录类型 可以用于查询.传输并动态更新ZONE信息 支持TSIG(事务 ...
- Kuernetes-设计架构(二)
Kubernetes设计架构 Kubernetes集群包含有节点代理kubelet和Master组件(APIs,scheduler.etc),一切都基于分布式的存储系统.Kubernetes架构图: ...
- 删除txt文件内容
删除txt文件里的 聊天记录的时间那一行 f = open("d:\\面试.txt", "r") g = open("d:\\英雄联盟ADC技巧.tx ...
- L008之前课程实战模拟。
L008之前课程实战模拟. . 安装CentOS 6.5 X86_64 . 配置网络 . 用CRT连接服务器 . 更换源http://mirrors.163.com/.help/CentOS6-Bas ...
- jmeter设置全局变量的方法
需求: 同一个线程组内有两个http请求A.B,A请求的后置处理器中存储的有值,B请求中添加用户变量Va先要引用该值,然后B请求的前置处理器再引用用户变量va. 第一种方式: 1.A请求后置处理添加如 ...
- SQL 注入教程
SQL 注入测评教程 1 准备 安装包:Burpsuit.Python27.sqlmap 2 安装配置 2.1 Burpsuit 1) 解压Burpsuit 2) ...
- Django入门与实战
第1章 介绍课程目标及学习内容 1-1 课程介绍: 第2章 课前准备 2-1 课前准备: 第3章 开发环境搭建 3-1 开发环境搭建: 第4章 创建项目及应用 4-1 创建项目,并了解项目目录下的部分 ...
- python 基础篇 16 递归和二分数查找与编码补充回顾
编码回顾补充: 回顾编码问题: 编码相当于密码本,关系到二进制与看懂的文字的的对应关系. 最早期的密码本: ascii码:只包含英文字母,数字,特殊字符. ...