ural1987 Nested Segments
Nested Segments
Memory limit: 64 MB
Input
Output
Sample
| input | output |
|---|---|
3 |
-1 |
分析:离散化+线段树;
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
#define pii pair<int,int>
#define Lson L, mid, rt<<1
#define Rson mid+1, R, rt<<1|1
const int maxn=3e5+;
const int dis[][]={{,},{-,},{,-},{,}};
using namespace std;
ll gcd(ll p,ll q){return q==?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=;while(q){if(q&)f=f*p;p=p*p;q>>=;}return f;}
int n,m,k,t,q,l[maxn>>],r[maxn>>],val[maxn>>],p[maxn],query[maxn];
struct Node
{
pii Min , lazy;
} T[maxn<<]; void PushUp(int rt)
{
T[rt].Min = min(T[rt<<].Min, T[rt<<|].Min);
} void PushDown(int L, int R, int rt)
{
int mid = (L + R) >> ;
pii t = T[rt].lazy;
T[rt<<].Min = T[rt<<|].Min = t;
T[rt<<].lazy = T[rt<<|].lazy = t;
T[rt].lazy = mp(,-);
} void Build(int L, int R, int rt)
{
if(L == R)
{
T[rt].Min = mp(inf,-);
return ;
}
int mid = (L + R) >> ;
Build(Lson);
Build(Rson);
PushUp(rt);
} void Update(int l, int r, pii v, int L, int R, int rt)
{
if(l==L && r==R)
{
T[rt].lazy = T[rt].Min = v;
return ;
}
int mid = (L + R) >> ;
if(T[rt].lazy.fi) PushDown(L, R, rt);
if(r <= mid) Update(l, r, v, Lson);
else if(l > mid) Update(l, r, v, Rson);
else
{
Update(l, mid, v, Lson);
Update(mid+, r, v, Rson);
}
PushUp(rt);
} pii Query(int l, int r, int L, int R, int rt)
{
if(l==L && r== R)
{
return T[rt].Min;
}
int mid = (L + R) >> ;
if(T[rt].lazy.fi) PushDown(L, R, rt);
if(r <= mid) return Query(l, r, Lson);
else if(l > mid) return Query(l, r, Rson);
return min(Query(l, mid, Lson) , Query(mid + , r, Rson));
} int main()
{
int i,j;
scanf("%d",&n);
j=;
rep(i,,n)scanf("%d%d",&l[i],&r[i]),p[j++]=l[i],p[j++]=r[i],val[i]=r[i]-l[i]+;
scanf("%d",&q);
rep(i,,q)
{
scanf("%d",&query[i]);
p[j++]=query[i];
}
sort(p+,p+j+);
int num=unique(p+,p+j+)-p-;
rep(i,,n)
{
l[i]=lower_bound(p+,p+num+,l[i])-p-;
r[i]=lower_bound(p+,p+num+,r[i])-p-;
}
rep(i,,q)
query[i]=lower_bound(p+,p+num+,query[i])-p-;
Build(,num,);
rep(i,,n)Update(l[i],r[i],mp(val[i],i),,num,);
rep(i,,q)
{
printf("%d\n",Query(query[i],query[i],,num,).se);
}
//system("Pause");
return ;
}
ural1987 Nested Segments的更多相关文章
- URAL-1987 Nested Segments 线段树简单区间覆盖
题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1987 题意:给定n条线段,每两条线段要么满足没有公共部分,要么包含.给出m个询问,求当前 ...
- Code Forces 652D Nested Segments(离散化+树状数组)
Nested Segments time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...
- Educational Codeforces Round 10 D. Nested Segments 离线树状数组 离散化
D. Nested Segments 题目连接: http://www.codeforces.com/contest/652/problem/D Description You are given n ...
- Educational Codeforces Round 10 D. Nested Segments 【树状数组区间更新 + 离散化 + stl】
任意门:http://codeforces.com/contest/652/problem/D D. Nested Segments time limit per test 2 seconds mem ...
- codeforces 652D D. Nested Segments(离散化+sort+树状数组)
题目链接: D. Nested Segments time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
- Educational Codeforces Round 10 D. Nested Segments
D. Nested Segments time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- D - Nested Segments CodeForces - 652D (离散化+树桩数组)
D - Nested Segments CodeForces - 652D You are given n segments on a line. There are no ends of some ...
- [离散化+树状数组]CodeForces - 652D Nested Segments
Nested Segments time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...
- Codeforces 976C Nested Segments
题面: 传送门 C. Nested Segments Input file: standard input Output file: standard output Time limit: 2 secon ...
随机推荐
- JAVA EE 运行环境配置(包含JAVA SE)
JAVA EE 运行环境配置(包含JAVA SE) 1.下载并安装jre-7u7-windows-i586.exe (最新的JAVA运行环境) 2.下载并安装java_ee_sdk-6u4-jdk7- ...
- ios图片剪切
#import "ViewController.h" @interface ViewController ()@property (weak, nonatomic) IBOutle ...
- shell脚本一键同步集群时间
shell脚本一键同步集群时间 弋嘤捕大 椿澄辄 ψ壤 茇徜燕 ㄢ交涔沔 阚龇棚绍 テ趼蜱棣 灵打了个寒颤也没有去甩脱愣是拖着 喇吉辔 秋北酏崖 琮淄脸酷 茇呶剑 莲夤罱 陕遇骸淫 ...
- AJAX 在手机上用时
Response.ContentType = "text/html; text/plain; charset=UTF-8";
- 转 Windows 7设置定时自动执行任务方法
在使用电脑的时候可能会遇到一些需要无人值守让电脑自行执行任务后定时关机的情形,在Win7系统中,我们可以使用"任务计划"设置功能结合 shutdown命令灵活设置任务计划,让Win ...
- C++中L和_T()之区别
字符串前面加L表示该字符串是Unicode字符串._T是一个宏,如果项目使用了Unicode字符集(定义了UNICODE宏),则自动在字符串前面加上L,否则字符串不变.因此,Visual C++里边定 ...
- Win32 SDK Combo Box
如下图所示,显示了三种不同风格的Combo Box样式.当然,现在这样看不出第一种与第三种之间的区别,但是第二种与其他两种的区别是明显的,第二种的列表框始终是出于现实状态的. Combo Box: 一 ...
- asp网站中使用百度ueditor教程
1.根据网站类型及编码选择相应的ueditor版本,如我的网站编码为gb2312,则选择ueditor 1.43 asp gbk版.2.本机IE浏览器应为8.0或以上,8.0以下的ueditor 1. ...
- UITabBarItem's appearance
1.我们知道,用tabBarController创建出来默认的tabBar似这个样子滴... -----------------我是图片分割线----------------------------- ...
- 阅读 LdrInitializeThunk
参考: http://blog.csdn.net/hw_henry2008/article/details/6568255 Windows 的 DLL 装入(除 ntdll.dll 外)和连接是通过 ...