Codeforces 976C Nested Segments
题面:
C. Nested Segments
- (2, 1), (3, 1), (4, 1), (5, 1) — not even touching borders;
- (3, 2), (4, 2), (3, 5), (4, 5) — touch one border;
- (5, 2), (2, 5) — match exactly.
题目描述:
题目分析:


1 #include <cstdio>
2 #include <cstring>
3 #include <iostream>
4 #include <cmath>
5 #include <set>
6 #include <map>
7 #include <algorithm>
8 #include <utility>
9 using namespace std;
10 const int maxn = 3e5+5;
11 struct node{
12 int l, r; //左右端点
13 int num; //编号
14 };
15 node seg[maxn]; //存放区间
16
17 bool cmp(node a, node b){
18 return a.l < b.l; //使区间按左端点从小到大排序
19 }
20
21 int main(){
22 int n;
23 scanf("%d", &n);
24 for(int i = 1; i <= n; i++){
25 scanf("%d%d", &seg[i].l, &seg[i].r);
26 seg[i].num = i;
27 }
28
29 sort(seg+1, seg+n+1, cmp);
30
31 int max_right = seg[0].r; //最大的右端点
32 int max_i = 0; //最大右端对应区间
33
34 for(int i = 1; i <= n; i++){
35 if(seg[i].r > max_right){
36 if(seg[i].l == seg[i-1].l){
37 cout << seg[i-1].num << " ";
38 cout << seg[i].num << endl;
39 return 0;
40 }
41 else{
42 max_right = seg[i].r; //更新最大右端点
43 max_i = i; //记录位置
44 }
45 }
46 else {
47 cout << seg[i].num << " ";
48 cout << seg[max_i].num << endl;
49 return 0;
50 }
51 }
52 cout << "-1 -1\n";
53 return 0;
54 }
Codeforces 976C Nested Segments的更多相关文章
- [离散化+树状数组]CodeForces - 652D Nested Segments
Nested Segments time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...
- codeforces 652D Nested Segments 离散化+树状数组
题意:给你若干个区间,询问每个区间包含几个其它区间 分析:区间范围比较大,然后离散化,按右端点排序,每次更新树状数组中的区间左端点,查询区间和 注:(都是套路) #include<cstdio& ...
- codeforces 652D . Nested Segments 线段树
题目链接 我们将线段按照右端点从小到大排序, 如果相同, 那么按照左端点从大到小排序. 然后对每一个l, 查询之前有多少个l比他大, 答案就是多少.因为之前的r都是比自己的r小的, 如果l还比自己大的 ...
- CodeForces 652D Nested Segments
离散化+树状数组 先对坐标离散化,把每条线段结尾所在点标1, 询问某条线段内有几条线段的时候,只需询问这段区间的和是多少,询问结束之后再把这条线段尾部所在点标为0 #include<cstdio ...
- 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 ...
- 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 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 ...
随机推荐
- codeforces 1000C - Covered Points Count 【差分】
题目:戳这里 题意:给出n个线段,问被1~n个线段覆盖的点分别有多少. 解题思路: 这题很容易想到排序后维护每个端点被覆盖的线段数,关键是端点值不好处理.比较好的做法是用差分的思想,把闭区间的线段改为 ...
- 【原】无脑操作:Centos 7.6 + MariaDB + Rsyslog + LogAnalyzer环境搭建
背景: 网络安全法第三章第二十一条明确规定"采取监测.记录网络运行状态.网络安全事件的技术措施,并按照规定留存相关的网络日志不少于六个月". 为了满足合规性的要求,应当建设相应的日 ...
- js create Array ways All In One
js create Array ways All In One ES6 const arr = [...document.querySelectorAll(`[data-dom="^div& ...
- SSL/TLS All In One
SSL/TLS All In One HTTPS SSL/TLS 的工作原理 https://www.websecurity.digicert.com/zh/cn/security-topics/ho ...
- Visual Studio Online & Web 版 VS Code
Visual Studio Online & Web 版 VS Code https://online.visualstudio.com https://devblogs.microsoft. ...
- vue & vue router & match bug
vue & vue router & match bug match bugs solution name must be router https://stackoverflow.c ...
- learning free programming resources form top university of the world
learning free programming resources form top university of the world Harvard university https://www. ...
- Git 学习相关笔记
Git Bash 相关命令学 基础概念 参考: https://www.cnblogs.com/gaoht/p/9087070.html https://www.runoob.com/git/git- ...
- Gateway网关
前提要在注册中心把网关和服务都进行注册 通俗来说,网关就是指在客户端和服务端的一面墙,这面墙有请求转发,负载均衡,权限控制,跨域,熔断降级,限流保护等功能. 客户端发送请求,请求先通过网关,网关根据特 ...
- JAVA 判断一个字符串是否是合法的日期格式?
采用SimpleDateFormat类的parse方法进行判断,如果转换不成功,就会出现异常.另外,还需要判断字符串的长度,若不判断,第二个字符串就会验证通过,实际上也不是合法的.话不多说,且看代码: ...