976 C. Nested Segments
You are given a sequence a1, a2, ..., an of one-dimensional segments numbered 1 through n. Your task is to find two distinct indices i and j such that segment ai lies within segment aj.
Segment [l1, r1] lies within segment [l2, r2] iff l1 ≥ l2 and r1 ≤ r2.
Print indices i and j. If there are multiple answers, print any of them. If no answer exists, print -1 -1.
The first line contains one integer n (1 ≤ n ≤ 3·105) — the number of segments.
Each of the next n lines contains two integers li and ri (1 ≤ li ≤ ri ≤ 109) — the i-th segment.
Print two distinct indices i and j such that segment ai lies within segment aj. If there are multiple answers, print any of them. If no answer exists, print -1 -1.
5
1 10
2 9
3 9
2 3
2 9
2 1
3
1 5
2 6
6 20
-1 -1
寻找是否存在一个段包含在另一个段里,输出段的编号
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <ctime>
#include <map>
#include <set>
using namespace std;
#pragma comment(linker, "/stck:1024000000,1024000000")
#define lowbit(x) (x&(-x))
#define max(x,y) (x>=y?x:y)
#define min(x,y) (x<=y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.1415926535897932384626433832
#define ios() ios::sync_with_stdio(true)
#define INF 0x3f3f3f3f
#define mem(a) ((a,0,sizeof(a)))
typedef long long ll;
struct node
{
int x,y,z;
bool operator<(const node &a)
{
return a.x==x?a.y<y:a.x>x;
}
}e[];
int n;
int main()
{
scanf("%d",&n);
for(int i=;i<n;i++)
{
scanf("%d%d",&e[i].x,&e[i].y);
e[i].z=i;
}
sort(e,e+n);
for(int i=;i<n-;i++)
{
if(e[i].x<=e[i+].x && e[i].y>=e[i+].y)
{
printf("%d %d\n",e[i+].z+,e[i].z+);
return ;
}
}
printf("-1 -1\n");
return ;
}
976 C. Nested Segments的更多相关文章
- ural1987 Nested Segments
Nested Segments Time limit: 1.0 secondMemory limit: 64 MB You are given n segments on a straight lin ...
- 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 ...
随机推荐
- Spring25大面试题
1.什么是Spring框架?Spring框架有哪些主要模块? Spring框架是一个为Java应用程序的开发提供了综合.广泛的基础性支持的Java平台.Spring帮助开发人员攻克了开发中基础性的问题 ...
- 斯坦福新深度学习系统 NoScope:视频对象检测快1000倍
以作备份,来源http://jiasuhui.com/archives/178954 本文由“新智元”(微信ID:AI_era)编译,来源:dawn.cs.stanford.edu,编译:刘小芹 斯坦 ...
- ORA-1157错误解决
一.错误描述 ORA-1157, "cannot identify/lock data file %s - see DBWR trace file" 引起的原因: 因为数据文件已经 ...
- VC++ LPARAMA 转换成CString
如果是SendMessage发送的CString CString s = "xxxxxx";SendMessage(hWnd,WM_XXXX,NULL,(LPARAM)&s ...
- Kettle的概念学习系列之Kettle是什么?(一)
不多说,直接上干货! Kettle是什么? Kettle是一款国外开源的ETL工具,纯java编写,可以在Window.Linux.Unix上运行,绿色无需安装,数据抽取高效稳定. Kettle 中文 ...
- 启动项目报错:org.springframework.beans.factory.UnsatisfiedDependencyException
dubbo项目: 启动项目报错:(web端) org.springframework.beans.factory.UnsatisfiedDependencyException: Error creat ...
- 再次建立wordpress
山大的火星人的站还在维护www.h4ck.org.cn. 也许是募课潮过后的效应,www时代还能聚合很多知识,到了客户端时代技术越发松散,很难发实用的技术总结. 如果重新审视问题不难发现,问题在于使用 ...
- jQuery学习(六)——使用JQ完成省市二级联动
1.JQ的遍历操作 方式一: 1 $(function(){ //全选/全不选 $("#checkallbox").click(function(){ var isChecked= ...
- 3ds Max 2018 在安装后无法启动或出现不稳定
问题: 安装 3ds Max 2018 后,软件无法正常启动,或在打开后不久出现不稳定和崩溃. 原因: 有多种原因可能会导致这些错误: ▪ 3ds Max.Windows 更新和 ProSound.d ...
- eclipse界面更改为黑色
效果如下: 更改很简单,该两个配置就行了,如下图: 1.在window中打开Preferences,然后跟下图一样配置就行了.