URAL-1987 Nested Segments 线段树简单区间覆盖
题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1987
题意:给定n条线段,每两条线段要么满足没有公共部分,要么包含。给出m个询问,求当前点被覆盖的最小长度的线段编号。
由于线段不存在部分相交的情况,因此,直接按照输入顺序覆盖区间就可以了,因为后覆盖的线段更短。
//STATUS:C++_AC_187MS_6805KB
#include <functional>
#include <algorithm>
#include <iostream>
//#include <ext/rope>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>
using namespace std;
//#pragma comment(linker,"/STACK:102400000,102400000")
//using namespace __gnu_cxx;
//define
#define pii pair<int,int>
#define mem(a,b) memset(a,b,sizeof(a))
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define PI acos(-1.0)
//typedef
typedef __int64 LL;
typedef unsigned __int64 ULL;
//const
const int N=;
const int INF=0x3f3f3f3f;
const int MOD=,STA=;
const LL LNF=1LL<<;
const double EPS=1e-;
const double OO=1e15;
const int dx[]={-,,,};
const int dy[]={,,,-};
const int day[]={,,,,,,,,,,,,};
//Daily Use ...
inline int sign(double x){return (x>EPS)-(x<-EPS);}
template<class T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<class T> T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T> inline T lcm(T a,T b,T d){return a/d*b;}
template<class T> inline T Min(T a,T b){return a<b?a:b;}
template<class T> inline T Max(T a,T b){return a>b?a:b;}
template<class T> inline T Min(T a,T b,T c){return min(min(a, b),c);}
template<class T> inline T Max(T a,T b,T c){return max(max(a, b),c);}
template<class T> inline T Min(T a,T b,T c,T d){return min(min(a, b),min(c,d));}
template<class T> inline T Max(T a,T b,T c,T d){return max(max(a, b),max(c,d));}
//End int c[(N*)<<],t[N][],q[N],id[N*];
int n; void pushdown(int rt)
{
if(c[rt]!=-)
c[rt<<]=c[rt<<|]=c[rt];
} void pushup(int rt)
{
if(c[rt<<]==c[rt<<|])
c[rt]=c[rt<<];
else c[rt]=-;
} void update(int l,int r,int rt,int L,int R,int val)
{
if(L<=l && r<=R){
c[rt]=val;
return;
}
pushdown(rt);
int mid=(l+r)>>;
if(L<=mid)update(lson,L,R,val);
if(R>mid)update(rson,L,R,val);
pushup(rt);
} int query(int l,int r,int rt,int w)
{
if(l==r){
return c[rt];
}
pushdown(rt);
int mid=(l+r)>>,ret;
if(w<=mid)ret=query(lson,w);
else ret=query(rson,w);
pushup(rt);
return ret;
} int main()
{
// freopen("in.txt","r",stdin);
int i,j,k,L,R,m;
while(~scanf("%d",&n))
{
k=;
for(i=;i<=n;i++){
scanf("%d%d",&t[i][],&t[i][]);
id[k++]=t[i][];
id[k++]=t[i][];
}
scanf("%d",&m);
for(i=;i<m;i++){
scanf("%d",&q[i]);
id[k++]=q[i];
}
sort(id,id+k);
k=unique(id,id+k)-id;
mem(c,-);
for(i=;i<=n;i++){
L=lower_bound(id,id+k,t[i][])-id+;
R=lower_bound(id,id+k,t[i][])-id+;
update(,k,,L,R,i);
} for(i=;i<m;i++){
printf("%d\n",query(,k,,lower_bound(id,id+k,q[i])-id+));
}
}
return ;
}
URAL-1987 Nested Segments 线段树简单区间覆盖的更多相关文章
- POJ 1436 Horizontally Visible Segments (线段树·区间染色)
题意 在坐标系中有n条平行于y轴的线段 当一条线段与还有一条线段之间能够连一条平行与x轴的线不与其他线段相交 就视为它们是可见的 问有多少组三条线段两两相互可见 先把全部线段存下来 并按x ...
- 2016 Multi-University Training Contest 10 [HDU 5861] Road (线段树:区间覆盖+单点最大小)
HDU 5861 题意 在n个村庄之间存在n-1段路,令某段路开放一天需要交纳wi的费用,但是每段路只能开放一次,一旦关闭将不再开放.现在给你接下来m天内的计划,在第i天,需要对村庄ai到村庄bi的道 ...
- codeforces 652D . Nested Segments 线段树
题目链接 我们将线段按照右端点从小到大排序, 如果相同, 那么按照左端点从大到小排序. 然后对每一个l, 查询之前有多少个l比他大, 答案就是多少.因为之前的r都是比自己的r小的, 如果l还比自己大的 ...
- HDU 4027 Can you answer these queries?(线段树,区间更新,区间查询)
题目 线段树 简单题意: 区间(单点?)更新,区间求和 更新是区间内的数开根号并向下取整 这道题不用延迟操作 //注意: //1:查询时的区间端点可能前面的比后面的大: //2:优化:因为每次更新都 ...
- 线段树(区间树)之区间染色和4n推导过程
前言 线段树(区间树)是什么呢?有了二叉树.二分搜索树,线段树又是干什么的呢?最经典的线段树问题:区间染色:正如它的名字而言,主要解决区间的问题 一.线段树说明 1.什么是线段树? 线段树首先是二叉树 ...
- POJ.2763 Housewife Wind ( 边权树链剖分 线段树维护区间和 )
POJ.2763 Housewife Wind ( 边权树链剖分 线段树维护区间和 ) 题意分析 给出n个点,m个询问,和当前位置pos. 先给出n-1条边,u->v以及边权w. 然后有m个询问 ...
- zoj3686(线段树的区间更新)
对线段树的区间更新有了初步的了解... A Simple Tree Problem Time Limit: 3 Seconds Memory Limit: 65536 KB Given a ...
- 线段树简单入门 (含普通线段树, zkw线段树, 主席树)
线段树简单入门 递归版线段树 线段树的定义 线段树, 顾名思义, 就是每个节点表示一个区间. 线段树通常维护一些区间的值, 例如区间和. 比如, 上图 \([2, 5]\) 区间的和, 为以下区间的和 ...
- Can you answer these queries V SPOJ - GSS5 (分类讨论+线段树维护区间最大子段和)
recursion有一个整数序列a[n].现在recursion有m次询问,每次她想知道Max { A[i]+A[i+1]+...+A[j] ; x1 <= i <= y1 , x2 &l ...
随机推荐
- mysql 字符串函数
对于针对字符串位置的操作,第一个位置被标记为1. ASCII(str) 返回字符串str的 最左面字符的ASCII代码值.如果str是空字符串, 返回0.如果str是NULL,返回NULL. mysq ...
- Lepus经历收获杂谈(二)——QT
QT简介及相关使用指南 1.QT Qt是1991年奇趣科技开发的一个跨平台的C++图形用户界面应用程序框架.它既可以开发GUI程序,也可用于开发非GUI程序,比如控制台工具和服务器.Qt是面向对象的框 ...
- mysql约束(自己原先总结的有点不准)
约束* 约束是添加在列上的,用来约束列的! 1. 主键约束(唯一标识) ****非空*** ****唯一*** ****被引用****(学习外键时) * 当表的某一列被指定为主键后,该列就不能为空,不 ...
- BZOJ 4285 使者
我TM再也不写BIT套主席树了.... #include<iostream> #include<cstdio> #include<cstring> #include ...
- ORACLE学习笔记 索引和约束
/*** 约束 ***/ * 如果某个约束只作用于单独的字段,即可以在字段级定义约束,也可以在表级定义约 束,但如果某个约束作用于多个字段, 必须在表级定义约束* 在定义约束时可以通过CONSTRA ...
- java 构造函数内部的多态方法 完全剖析
我们先来看一个例子,如果你读过<java编程思想>的话 应该会有印象 package com.test.zj; public class PolyConstructors { public ...
- web app 页面旋转整体样式问题
$(window).bind("orientationchange", function (event) { if (event.orientation) { //portrait ...
- 使用模板时 error LNK2019: 无法解析的外部符号
类模板是c++编译器指令 说明了如何生成类和成员函数 除非编译器实现了新的关键字export关键字 否则将模板成员函数放置在一个独立的实现文件中 将无法运行 因为模板不是函数 他们不能单独编译 模板必 ...
- s:iterator标签的使用
1.在说明s:iterator标签的使用前,先了解下struts2中的Value Stack. 这里参考了webwork中对Value Stack的描述,由于struts2是在webwork的基础上进 ...
- Jquery 设置style:display 通过ID隐藏区域
$("#id").css('display','none'); $("#id").css('display','block'); 或 $("#id&q ...