Codeforces Round #222 (Div. 1) D. Developing Game 线段树有效区间合并
Pavel is going to make a game of his dream. However, he knows that he can't make it on his own so he founded a development company and hired n workers of staff. Now he wants to pick n workers from the staff who will be directly responsible for developing a game.
Each worker has a certain skill level vi. Besides, each worker doesn't want to work with the one whose skill is very different. In other words, the i-th worker won't work with those whose skill is less than li, and with those whose skill is more than ri.
Pavel understands that the game of his dream isn't too hard to develop, so the worker with any skill will be equally useful. That's why he wants to pick a team of the maximum possible size. Help him pick such team.
The first line contains a single integer n (1 ≤ n ≤ 105) — the number of workers Pavel hired.
Each of the following n lines contains three space-separated integers li, vi, ri (1 ≤ li ≤ vi ≤ ri ≤ 3·105) — the minimum skill value of the workers that the i-th worker can work with, the i-th worker's skill and the maximum skill value of the workers that the i-th worker can work with.
In the first line print a single integer m — the number of workers Pavel must pick for developing the game.
In the next line print m space-separated integers — the numbers of the workers in any order.
If there are multiple optimal solutions, print any of them.
4
2 8 9
1 4 7
3 6 8
5 8 10
3
1 3 4
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
#pragma comment(linker, "/STACK:102400000,102400000")
#define ls i<<1
#define rs ls | 1
#define mid ((ll+rr)>>1)
#define pii pair<int,int>
#define MP make_pair
typedef long long LL;
const long long INF = 1e18+1LL;
const double Pi = acos(-1.0);
const int N = 5e5+, M = 2e5+, mod = 1e9+, inf = 2e9; int n;
int tag[N*],mx[N*];
void push_up(int i) {
mx[i] = max(mx[ls],mx[rs]);
}
void push_down(int i,int ll,int rr) {
if(tag[i] != && ll != rr) {
tag[ls] += tag[i];
tag[rs] += tag[i];
mx[ls] += tag[i];
mx[rs] += tag[i];
tag[i] = ;
}
}
void update(int i,int ll,int rr,int l,int r,int v)
{
push_down(i,ll,rr);
if(l == ll && r == rr) {
tag[i] += v;
mx[i] += v;
return ;
}
if(r <= mid) update(ls,ll,mid,l,r,v);
else if(l > mid) update(rs,mid+,rr,l,r,v);
else {
update(ls,ll,mid,l,mid,v);
update(rs,mid+,rr,mid+,r,v);
}
push_up(i);
} int query(int i,int ll,int rr,int x) {
push_down(i,ll,rr);
if(ll == rr) return ll;
if(mx[ls] == x) return query(ls,ll,mid,x);
else return query(rs,mid+,rr,x);
push_up(i);
}
struct ss{
int l,r,h,in;
ss(int l = , int r = , int h = ,int in = ) : l(l), r(r), h(h),in(in) {}
bool operator < (const ss & b) const {
return h < b.h || h == b.h && in > b.in;
}
}p[N],P[N];
int main() {
scanf("%d",&n);
for(int i = ; i <= n; ++i) {
int l,v,r;
scanf("%d%d%d",&l,&v,&r);
p[i] = ss(l,v,v,);
p[i+n] = ss(l,v,r,-);
P[i] = ss(l,r,v,);
}
int m = n << ;
sort(p+,p+m+);
int ans = ,x,y;
for(int i = ; i <= m; ++i) {
int l = p[i].l, r = p[i].r;
update(,,,l,r,p[i].in);
if(mx[] > ans) {
ans = mx[];
x = query(,,,mx[]);
y = p[i].h;
}
}
printf("%d\n",ans);
for(int i = ; i <= n; ++i) {
if(P[i].l <= x && P[i].r >= y && P[i].h >= x && P[i].h <= y) printf("%d\n",i);
}
return ;
}
Codeforces Round #222 (Div. 1) D. Developing Game 线段树有效区间合并的更多相关文章
- Codeforces Round #222 (Div. 1) D. Developing Game
D - Developing Game 思路:我们先枚举左边界,把合法的都扣出来,那么对于这些合法的来说值有v 和 r两维了,把v, r看成线段的两端, 问题就变成了,最多能选多少线段 使得不存在这样 ...
- Codeforces Round #603 (Div. 2) E. Editor(线段树)
链接: https://codeforces.com/contest/1263/problem/E 题意: The development of a text editor is a hard pro ...
- Codeforces Round #244 (Div. 2) B. Prison Transfer 线段树rmq
B. Prison Transfer Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/pro ...
- Codeforces Round #530 (Div. 2) F (树形dp+线段树)
F. Cookies 链接:http://codeforces.com/contest/1099/problem/F 题意: 给你一棵树,树上有n个节点,每个节点上有ai块饼干,在这个节点上的每块饼干 ...
- Codeforces Round #222 (Div. 1) D. Developing Game 扫描线
D. Developing Game 题目连接: http://www.codeforces.com/contest/377/problem/D Description Pavel is going ...
- Codeforces Round #546 (Div. 2) E 推公式 + 线段树
https://codeforces.com/contest/1136/problem/E 题意 给你一个有n个数字的a数组,一个有n-1个数字的k数组,两种操作: 1.将a[i]+x,假如a[i]+ ...
- Codeforces Round #275 Div.1 B Interesting Array --线段树
题意: 构造一个序列,满足m个形如:[l,r,c] 的条件. [l,r,c]表示[l,r]中的元素按位与(&)的和为c. 解法: 线段树维护,sum[rt]表示要满足到现在为止的条件时该子树的 ...
- Codeforces Round #271 (Div. 2) F. Ant colony 线段树
F. Ant colony time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- Codeforces Round #406 (Div. 2) D. Legacy (线段树建图dij)
D. Legacy time limit per test 2 seconds memory limit per test 256 megabytes input standard input out ...
随机推荐
- 配置samba
安装samba服务器之后,很方便的实现Windows和Linux进行通信. 安装步骤:1.在Ubuntu系统下面安装samba服务: nii@ww:~$ sudo apt-get install sa ...
- VMware 虚拟上网的的三种模式 ——bridged、host-only、NAT 模式
恐怕这是今年在上海的最后的一篇博客了,同事们上班都不工作了,我也没有什么事情要做.为什么要写这篇博客呢,原因是我回家要带上自己的笔记本,里面装了一个虚拟机.平时自己的学习和工作都是在虚拟机里进行的.回 ...
- 深入C#内存管理来分析值类型&引用类型,装箱&拆箱,堆栈几个概念组合之间的区别
C#初学者经常被问的几道辨析题,值类型与引用类型,装箱与拆箱,堆栈,这几个概念组合之间区别,看完此篇应该可以解惑. 俗话说,用思想编程的是文艺程序猿,用经验编程的是普通程序猿,用复制粘贴编程的是2B程 ...
- ubuntu下安装mysql及卸载mysql方法
1. 删除mysql a. sudo apt-get autoremove --purge mysql-server-5.0 b. sudo apt-get remove mysql-server c ...
- python基础知识
由于python的灵活性,赋值前无需强调变量的数据类型,并且变量的数据类型在后期的操作过程中还可以改变,故不介绍关键字,直接定义方法及可以调用的方法. I 基本数据类型 一.字符串 1.使用单引号或 ...
- cf723c Polycarp at the Radio
Polycarp is a music editor at the radio station. He received a playlist for tomorrow, that can be re ...
- LPC1768/1769之CAN控制器概述(附库函数下载地址)
一.背景: 使用LPC1769来做CAN的收发,在此对使用LPC1769的CAN控制器进行收发做个总结和记录,以备下 次开发快速上手使用. 附:LPC1768/1769除了支持最高频率不同以外,其它基 ...
- PHP正则表达式详解(二)
前言: 在本文中讲述了正则表达式中的组与向后引用,先前向后查看,条件测试,单词边界,选择符等表达式及例子,并分析了正则引擎在执行匹配时的内部机理. 本文是Jan Goyvaerts为RegexBudd ...
- Linux进程间通信(四):命名管道 mkfifo()、open()、read()、close()
在前一篇文章—— Linux进程间通信 -- 使用匿名管道 中,我们看到了如何使用匿名管道来在进程之间传递数据,同时也看到了这个方式的一个缺陷,就是这些进程都由一个共同的祖先进程启动,这给我们在不相关 ...
- WDCP突破phpmyadmin导入文件时只有20M
WDCP在默认的配置下,PHPMYADMIN的上传上限是20M,很多时候我们的数据库大小已经大于了20M了,那这时候改怎么办呢?下面就用简单的话,告诉大家如何解决这一个问题.方法: 登录到WDCP的后 ...