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 ...
随机推荐
- 在JavaScript中创建命名空间的几种写法
在JavaScript中全局变量经常会引起命名冲突,甚至有时侯重写变量也不是按照你想像中的顺序来的,可以看看下面的例子: var sayHello = function() { return 'Hel ...
- iOS申请真机调试证书 -- 图文详解
请参考这篇文章 : http://ios.9tech.cn/news/2013/1011/33117.html 这篇文章完全就是对的,主要是最后一步 “配置Xcode" 图没有配全,也配得不 ...
- Google 分布式关系型数据库 F1
F1是Google开发的分布式关系型数据库,主要服务于Google的广告系统.Google的广告系统以前使用MySQL,广告系统的用户经常需要使用复杂的query和join操作,这就需要设计shard ...
- 避免IE执行AJAX时,返回JSON出现下载文件
<bean id="mappingJacksonHttpMessageConverter" class="org.springframework.http.conv ...
- kill -0
http://unix.stackexchange.com/questions/169898/what-does-kill-0-do 检查有没有权限杀他
- winxp sp2
不支持sha2,所以ssl建立失败, sp3就可以了 http://superuser.com/questions/802693/sha2-support-for-windows-xp-sp2-any ...
- Java学习笔记之Scanner报错java.util.NoSuchElementException
转载自:IT学习者-螃蟹 一个方法A使用了Scanner,在里面把它关闭了.然后又在方法B里调用方法A之后就不能再用Scanner了Scanner in = new Scanner(System.in ...
- margin:0 auto
<!doctype html> <html> <head> <meta charset="utf-8"> <title> ...
- HDU1874 最短路 SPFA
最短路 Time Limit: 1 Sec Memory Limit: 128 MB Submit: 24 Solved: 17 [Submit][Status][Web Board] Descr ...
- 使用log4j无法输出日志
前段时间在项目的过程中使用log4j来输出日志,但是在一个项目里我明明已经在src/main/resource目录下创建了log4j.properties.具体配置如下: log4j.rootLogg ...