[Codeforces 863E]Turn Off The TV
Description
Luba needs your help again! Luba has n TV sets. She knows that i-th TV set will be working from moment of time li till moment ri, inclusive.
Luba wants to switch off one of TV sets in order to free the socket. Let's call some TV set redundant if after switching it off the number of integer moments of time when at least one of TV sets is working won't decrease. Luba will be very upset if she has to switch off a non-redundant TV set.
Help Luba by telling her the index of some redundant TV set. If there is no any, print -1.
Input
The first line contains one integer number n (1 ≤ n ≤ 2·105) — the number of TV sets.
Then n lines follow, each of them containing two integer numbers li, ri (0 ≤ li ≤ ri ≤ 109) denoting the working time of i-th TV set.
Output
If there is no any redundant TV set, print -1. Otherwise print the index of any redundant TV set (TV sets are indexed from 1 to n).
If there are multiple answers, print any of them.
Sample Input
3
1 3
4 6
1 7
Sample Output
1
题解
给的标签又是数据结构...本来想打一个线段树...发现值域太大...
我们考虑这样一个问题:什么情况下才会导致一个区间被另外的区间完全覆盖呢?
一定只有两种情况:一种是一个区间只被一个完整的区间完全包括,另一种是被两个区间拼在一起包括。
我们按左端点为主关键词,右端点为次关键词,将所有区间排序。
那么发现以上的两种情况只会变成:
1.第$i$个区间被第$i-1$个区间完全包括;
2.第$i$个区间被第$i-1$个和第$i+1$个区间包括。
第一种情况很好考虑,只要按顺序遍历,找到一个$a[i].r<=a[i-1].r$的就是满足条件的。
我们看第二种情况,假设我们在考虑第$i$个区间时判断$i-1$满不满足,如果$i-2$的右端点$+1$大于$i$的左端点,那么$i-1$就可以被覆盖。
//It is made by Awson on 2017.10.1
#include <set>
#include <map>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <vector>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define LL long long
#define Min(a, b) ((a) < (b) ? (a) : (b))
#define Max(a, b) ((a) > (b) ? (a) : (b))
using namespace std;
const int N = 2e5;
void read(int &x) {
char ch; bool flag = ;
for (ch = getchar(); !isdigit(ch) && ((flag |= (ch == '-')) || ); ch = getchar());
for (x = ; isdigit(ch); x = (x<<)+(x<<)+ch-, ch = getchar());
x *= -*flag;
} int n;
struct tt {
int l, r, id;
bool operator < (const tt &b) const{
return l == b.l ? r < b.r : l < b.l;
}
}a[N+]; void work() {
read(n);
for (int i = ; i <= n; i++)
read(a[i].l), read(a[i].r), a[i].id = i;
sort(a+, a++n);
for (int i = ; i <= n; i++) {
if (a[i].r <= a[i-].r) {
printf("%d\n", a[i].id);
return;
}
else if (a[i].l <= a[i-].l) {
printf("%d\n", a[i-].id);
return;
}
a[i].l = Max(a[i-].r+, a[i].l);
}
printf("-1\n");
}
int main() {
work();
return ;
}
[Codeforces 863E]Turn Off The TV的更多相关文章
- E. Turn Off The TV Educational Codeforces Round 29
http://codeforces.com/contest/863/problem/E 注意细节 #include <cstdio> #include <cstdlib> #i ...
- Codeforces 1097 Alex and a TV Show
传送门 除了操作 \(3\) 都可以 \(bitset\) 现在要维护 \[C_i=\sum_{gcd(j,k)=i}A_jB_k\] 类比 \(FWT\),只要求出 \(A'_i=\sum_{i|d ...
- Codeforces 1097F Alex and a TV Show (莫比乌斯反演)
题意:有n个可重集合,有四种操作: 1:把一个集合设置为单个元素v. 2:两个集合求并集. 3:两个集合中的元素两两求gcd,然后这些gcd形成一个集合. 4:问某个可重复集合的元素v的个数取模2之后 ...
- Codeforces 1097F. Alex and a TV Show
传送门 由于只要考虑 $\mod 2$ 意义下的答案,所以我们只要维护一堆的 $01$ 容易想到用 $bitset$ 瞎搞...,发现当复杂度 $qv/32$ 是可以过的... 一开始容易想到对每个集 ...
- 【Codeforces 1097F】Alex and a TV Show(bitset & 莫比乌斯反演)
Description 你需要维护 \(n\) 个可重集,并执行 \(m\) 次操作: 1 x v:\(X\leftarrow \{v\}\): 2 x y z:\(X\leftarrow Y \cu ...
- Educational Codeforces Round 29(6/7)
1.Quasi-palindrome 题意:问一个字符串(你可以添加前导‘0’或不添加)是否是回文串 思路:将给定的字符串的前缀‘0’和后缀‘0’都去掉,然后看其是否为回文串 #include< ...
- 越狱Season 1- Episode 22: Flight
Season 1, Episode 22: Flight -Franklin: You know you got a couple of foxes in your henhouse, right? ...
- 30个HTML初学者建议
The most difficult aspect of running Nettuts+ is accounting for so many different skill levels. If w ...
- 设计模式教程(Design Patterns Tutorial)笔记之三 行为型模式(Behavioral Patterns)
目录 · Strategy · When to use the Strategy Design Pattern? · Sample Code · Observer · When to use the ...
随机推荐
- C语言博客作业—函数嵌套调用
一.实验作业 1.1 PTA题目:递归法对任意10个数据按降序排序 1.1.1设计思路 void sort(int a[],int n) { 定义整型循环变量i,中间变量temp,最小值min: 令m ...
- bug终结者 团队作业第八周
bug终结者 团队作业第八周 本次任务 素材提供及编辑:20162328 蔡文琛 博客修改完善:20162322 朱娅霖 "bug终结者" 宏伟蓝图 UML 手绘底稿 用例图 选项 ...
- 201621123068 Week03-面向对象入门
1. 本周学习总结 初学面向对象,会学习到很多碎片化的概念与知识.尝试学会使用思维导图将这些碎片化的概念.知识点组织起来.请使用工具画出本周学习到的知识点及知识点之间的联系.步骤如下: 1.1 写出你 ...
- 第一部分 linux系统命令
一.linux系统命令 pwd 当前目录位置 / 根目录 cd (change direcory) cd ..返回上一层目录 ls 显示当前目录下文件 ls -l 显示目录下详细文件信息 ls -lh ...
- 网上找的hadoop面试题目及答案
1.Hadoop集群可以运行的3个模式? 单机(本地)模式 伪分布式模式全分布式模式2. 单机(本地)模式中的注意点? 在单机模式(standalone)中不会存在守护进程,所有东西都运行在一个JVM ...
- [Android]上传到多个Maven仓库的Gradle插件RapidMavenPushPlugin
博客搬迁至https://blog.wangjiegulu.com RSS订阅:https://blog.wangjiegulu.com/feed.xml RapidMavenPushPlugin 用 ...
- 服务器数据恢复方法_存储raid硬盘离线数据恢复案例
[故障描述]某法院的一台HP-P4500的存储系统,底层是12块1TB的硬盘组的RAID.其中每6个1TB的盘一组,第一组的前面一部分组了一个RAID0+1,是存放HP-P4500嵌入式系统,接着组了 ...
- iOS 11 导航栏 item 偏移问题 和 Swift 下 UIButton 设置 title、image 显示问题
html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,bi ...
- Spark快速入门
Spark 快速入门 本教程快速介绍了Spark的使用. 首先我们介绍了通过Spark 交互式shell调用API( Python或者scala代码),然后演示如何使用Java, Scala或者P ...
- ORA-01578和ORA-26040--NOLOGGING操作引起的坏块-错误解释和解决方案(文档ID 1623284.1)
ORA-01578和ORA-26040--NOLOGGING操作引起的坏块-错误解释和解决方案(文档ID 1623284.1) (一)NOLOGGING操作引起的坏块(ORA-01578和ORA-26 ...