codeforces 1284D. New Year and Conference(线段树)
题意:有n场讲座,有两个场地a和b,如果在a场地开讲座则需要占用[sai,eai],在b场地开讲座则需要占用[sbi,ebi]这个时间段,假如开两场讲座,如果在a场地开不冲突,而b场地开冲突,则称其为敏感的,同理a和b反过来也是一样的,如果ab两场地都冲突则也不是敏感的,先求给定的n场讲座,任意的两两开设是否敏感。
思路:暴力枚举是O(n^2)复杂度,必定超时,这里可以用线段树或ST表做,达到一个nlogn的复杂度。对于任意一个讲座x,找出所有与x讲座在a场地冲突的讲座,再判断其是否在b场地冲突,如果不是则直接输出“NO”
首先对所有讲座的sa和ea进行升序,例如讲座 i 的时间片是[x,y],在其时间片上与 i 在a场地冲突的讲座用二分的方法可以枚举出来一个离散化后的区间,然后我们用线段树维护b场地的sb最大值和eb最小值,每次查询出这个区间的
的sb最大值和eb最小值,此时如果说sb最大值 > y 或者 eb最小值 < x,那么这些表演中必定存在b场地与表演i不冲突的情况,此时直接输出“NO”,把所有的讲座都check一遍,交换ab次序再check即可,上述只检验了在a场地冲突一定在b场地冲突的情况,但并未考虑在b场地冲突而在a场地不冲突的情况。
总体时间复杂度nlogn。
AC代码:
#include<iostream>
#include<vector>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
using namespace std;
typedef long long ll;
const int maxn = 1e5+;
struct node{
int sa,ea,sb,eb;
node(){};
node(int a,int b,int c,int d){
sa = a,ea = b,sb = c,eb = d;
}
bool operator<(node cur)const{
if(sa == cur.sa ) return ea<cur.ea ;
return sa < cur.sa ;
}
}point[maxn];
int segt_max[*maxn],segt_min[*maxn];
void build(int l,int r,int k){//建两个线段树维护区间最大最小值
if(l == r) {
segt_max[k] = point[l].sb;
segt_min[k] = point[l].eb;
return ;
}
int mid = (l+r)/;
build(l,mid,*k);
build(mid+,r,*k+);
segt_max[k] = max(segt_max[*k],segt_max[*k+]);
segt_min[k] = min(segt_min[*k],segt_min[*k+]);
}
int queryMin(int l,int r,int al,int ar,int k){//查询区间最小值
if(l >= al && r <= ar) return segt_min[k];
int mid = (l+r)/;
if(ar<=mid) return queryMin(l,mid,al,ar,*k);
else if(al>mid){
return queryMin(mid+,r,al,ar,*k+);
}
else {
return min(queryMin(l,mid,al,mid,*k),queryMin(mid+,r,mid+,ar,*k+));
}
}
int queryMax(int l,int r,int al,int ar,int k){//查询区间最大值
if(l >= al && r <= ar) return segt_max[k];
int mid = (l+r)/;
if(ar<=mid) return queryMax(l,mid,al,ar,*k);
else if(al>mid){
return queryMax(mid+,r,al,ar,*k+);
}
else {
return max(queryMax(l,mid,al,mid,*k),queryMax(mid+,r,mid+,ar,*k+));
}
}
bool check(int n){
sort(point+,point++n);
build(,n,);
for(int i = ;i<=n;i++){
int pos = lower_bound(point+,point++n,node(point[i].ea ,1e9+,,))-point-;
//查找与第i场演讲冲突的集合
if(i+>pos) continue;//无冲突直接跳过
//check一下另一个场地的所有表演是否都冲突
if(queryMin(,n,i+,pos,)<point[i].sb || queryMax(,n,i+,pos,)>point[i].eb){
return false;
}
}
return true;
}
int main()
{
int n;
cin>>n;
int f = ;
for(int i = ;i<=n;i++){
cin>>point[i].sa>>point[i].ea>>point[i].sb>>point[i].eb;
}
if(check(n)) f++;
for(int i = ;i<=n;i++){
swap(point[i].sa,point[i].sb);
swap(point[i].ea,point[i].eb);
}
if(check(n)) f++;
if(f == ) cout<<"YES";
else cout<<"NO";
return ;
}
codeforces 1284D. New Year and Conference(线段树)的更多相关文章
- [Codeforces 266E]More Queries to Array...(线段树+二项式定理)
[Codeforces 266E]More Queries to Array...(线段树+二项式定理) 题面 维护一个长度为\(n\)的序列\(a\),\(m\)个操作 区间赋值为\(x\) 查询\ ...
- [Codeforces 280D]k-Maximum Subsequence Sum(线段树)
[Codeforces 280D]k-Maximum Subsequence Sum(线段树) 题面 给出一个序列,序列里面的数有正有负,有两种操作 1.单点修改 2.区间查询,在区间中选出至多k个不 ...
- codeforces 1217E E. Sum Queries? (线段树
codeforces 1217E E. Sum Queries? (线段树 传送门:https://codeforces.com/contest/1217/problem/E 题意: n个数,m次询问 ...
- Codeforces 444 C. DZY Loves Colors (线段树+剪枝)
题目链接:http://codeforces.com/contest/444/problem/C 给定一个长度为n的序列,初始时ai=i,vali=0(1≤i≤n).有两种操作: 将区间[L,R]的值 ...
- Codeforces Gym 100513F F. Ilya Muromets 线段树
F. Ilya Muromets Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100513/probl ...
- Codeforces 834D The Bakery【dp+线段树维护+lazy】
D. The Bakery time limit per test:2.5 seconds memory limit per test:256 megabytes input:standard inp ...
- codeforces 1017C - Cloud Computing 权值线段树 差分 贪心
https://codeforces.com/problemset/problem/1070/C 题意: 有很多活动,每个活动可以在天数为$[l,r]$时,提供$C$个价格为$P$的商品 现在从第一天 ...
- Codeforces 1045. A. Last chance(网络流 + 线段树优化建边)
题意 给你 \(n\) 个武器,\(m\) 个敌人,问你最多消灭多少个敌人,并输出方案. 总共有三种武器. SQL 火箭 - 能消灭给你集合中的一个敌人 \(\sum |S| \le 100000\) ...
- Codeforces 446C DZY Loves Fibonacci Numbers [线段树,数论]
洛谷 Codeforces 思路 这题知道结论就是水题,不知道就是神仙题-- 斐波那契数有这样一个性质:\(f_{n+m}=f_{n+1}f_m+f_{n}f_{m-1}\). 至于怎么证明嘛-- 即 ...
随机推荐
- IIS7启用ASP程序的步骤。
IIS7配置asp程序 https://www.cnblogs.com/rollup/p/4969502.html
- ubuntu 1804 rsync 命令 服务端配置
1. rsync的主要作用 rsync命令是一个远程数据同步工具,可通过LAN/WAN快速同步多台主机间的文件.rsync使用所谓的"rsync算法"来使本地和远程两个主机之间的文 ...
- XSS攻击解决办法 Spring mvc databinder
XSS攻击解决办法 一.SpringMVC架构下@InitBinder方法 Controller方法的参数类型可以是基本类型,也可以是封装后的普通Java类型.若这个普通Java类型没有声明任何注解, ...
- 数据类型(8种)和运算符——Java
一.什么是标识符,它有什么作用(重点掌握) 1. 标识符指的是 标识符是用户编程时使用的名字,用于给变量.常量.函数.语句块等命名,以建立起名称与使用之间的关系.标识符可由任何字母数字字符串形成. 2 ...
- JS宣传页项目-综合实战
按照国际惯例先放图 index.html <!DOCTYPE html> <html lang="en"> <head> <meta ch ...
- Html5学习系列
Html5学习系列 HTML5 规定了一种通过 video 元素来包含视频的标准方法 Ogg = 带有 Theora 视频编码和 Vorbis 音频编码的 Ogg 文件 MPEG4 = 带有 H.26 ...
- javaweb简单的学生信息录入系统
讲一下思路,主界面的设计就是用html表单元素,百度查找各个元素的用法,按照自己的想法摆放即可,表单提交后会把数据交给serverlet去处理,在那里定义几个字符串变量来储存获取到的数据,然后按照项目 ...
- Spring IoC Container源码分析(二)-bean初始化流程
准备 Person实例 @Data public class Person { private String name; private int age; } xml bean配置 <?xml ...
- python常见函数积累
shape() 返回数组或者数据框有多少行或者多少列 import numpy as np x = np.array([[1,2,5],[2,3,5],[3,4,5],[2,3,6]]) #输出数组的 ...
- ACM-ICPC 2018 徐州赛区网络预赛 Features Track
签到题 因为一个小细节考虑不到wa了两次 // 一开始没这个if wa了.因为数据中存在同一帧(frame)一个相同的值出现多次,这样子同一个i 后面的同样的特征会把len重置为1 #include ...