博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforces Round #222 (Div. 1) D. Developing Game 扫描线
阅读量:5825 次
发布时间:2019-06-18

本文共 4850 字,大约阅读时间需要 16 分钟。

D. Developing Game

题目连接:

Description

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.

Input

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.

Output

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.

Sample Input

4

2 8 9
1 4 7
3 6 8
5 8 10

Sample Output

3

1 3 4

Hint

题意

有n个人,这个人的属性v,他可以接受能力值在[l,r]里面的人

你是一个老板,你需要雇佣尽量多的人,问你怎么去雇佣……

题解:

感觉是一个网络流的样子,其实不然

假设答案是[L,R]区间,把这个抽象成二维平面上的点

那么对于每一个人,我们可以看做是[l,v],[v,R]这么一个矩形,只要这个矩形包括了那个点

那么这个人就是可选的。

知道这个之后,这道题就是傻逼题了

就直接扫描线莽一波就好了

代码

#include 
using namespace std;const int maxn = 3e5 + 15;struct Point{ int l , r , idx; Point ( int l , int r , int idx ) : l( l) , r(r) , idx(idx){}};vector < Point > add[maxn] , del[maxn];pair < int , int > Base[maxn];int N , V[maxn];struct Sgtree{ struct node{ int l , r , maxv , lazy , maxr; void Update( int x ){ lazy += x; maxv += x; } }tree[maxn << 2]; void ReleaseLabel( int o ){ tree[o << 1].Update( tree[o].lazy); tree[o << 1|1].Update(tree[o].lazy); tree[o].lazy = 0; } void Maintain( int o ){ if( tree[o << 1].maxv > tree[o << 1 |1].maxv ) tree[o].maxr = tree[o << 1].maxr; else tree[o].maxr = tree[o << 1 | 1].maxr; tree[o].maxv = max( tree[o << 1].maxv , tree[o << 1 | 1].maxv ); } void Modify( int ql , int qr , int v , int o){ int l = tree[o].l , r = tree[o].r; if( ql <= l && r <= qr ) tree[o].Update( v ); else{ int mid = l + r >> 1; ReleaseLabel( o ); if( ql <= mid ) Modify( ql , qr , v , o << 1 ); if( qr > mid ) Modify( ql , qr , v , o << 1 | 1 ); Maintain( o ); } } void Build( int l , int r , int o ){ tree[o].l = l , tree[o].r = r , tree[o].maxv = 0 , tree[o].maxr = r; if( r > l ){ int mid = l + r >> 1; Build( l , mid , o << 1 ); Build( mid + 1 , r , o << 1 | 1); } } int ask( int ql , int qr , int o ){ int l = tree[o].l , r = tree[o].r; if( ql <= l && r <= qr ) return tree[o].maxv; else{ int mid = l + r >> 1 , rs = -1; ReleaseLabel( o ); if( ql <= mid ) rs = max( rs , ask( ql , qr , o << 1) ); if( qr > mid ) rs = max( rs , ask( ql , qr , o << 1 | 1) ); Maintain( o ); return rs; } } }Sgtree;int main( int argc , char * argv[]){ Sgtree.Build(1 , 300000 , 1); scanf("%d",&N); for(int i = 1 ; i <= N ; ++ i){ int l , r , v; scanf("%d%d%d",&l,&v,&r); add[l].push_back(Point(v,r,i)); del[v].push_back(Point(v,r,i)); Base[i] = make_pair( l , r ); V[i] = v; } int mx = 0 , ansl = -1 , ansr = -1; for(int i = 1 ; i <= 3e5 ; ++ i){ for(int j = 0 ; j < add[i].size() ; ++ j){ int l = add[i][j].l; int r = add[i][j].r; Sgtree.Modify( l , r , 1 , 1 ); } int newmx = Sgtree.tree[1].maxv; if( newmx > mx ){ mx = newmx , ansl = i , ansr = Sgtree.tree[1].maxr; assert( Sgtree.ask( ansr , ansr , 1 ) == newmx ); } for(int j = 0 ; j < del[i].size() ; ++ j){ int l = del[i][j].l; int r = del[i][j].r; Sgtree.Modify( l , r , -1 , 1 ); } } printf("%d\n" , mx ); vector < int > out; for(int i = 1 ; i <= N ; ++ i) if( Base[i].first <= ansl && Base[i].second >= ansr && V[i] <= ansr && V[i] >= ansl ) out.push_back( i ); for(int i = 0 ; i < out.size() ; ++ i) printf("%d " ,out[i]); printf("\n"); return 0;}

转载地址:http://njsdx.baihongyu.com/

你可能感兴趣的文章
android开发(49) android 使用 CollapsingToolbarLayout ,可折叠的顶部导航栏
查看>>
【ERP】如何在多行数据块中实现仅能勾选唯一的主联系人
查看>>
Oracle 数据库优化的R方法(Method R)
查看>>
CentOS最小化安装系统开启网卡
查看>>
互联网+升级到智能+ 开启万物智联新时代
查看>>
Linux文本编辑器之Nano
查看>>
【原】IOS中KVO模式的解析与应用
查看>>
理解 QEMU/KVM 和 Ceph(3):存储卷挂接和设备名称
查看>>
[MFC] CList
查看>>
[Android Pro] 完美Android Cursor使用例子(Android数据库操作)
查看>>
c++中sizeof的分析
查看>>
线程间操作无效: 从不是创建控件的线程访问它的解决方法
查看>>
hdu 1236 排名
查看>>
PHP面向对象深入研究之【继承】,减少代码重复
查看>>
RBAC权限管理
查看>>
此博客不再发表对自己私事的看法
查看>>
后台(20)——数据库连接池
查看>>
导致Asp.Net站点重启的10个原因
查看>>
【PMP】Head First PMP 学习笔记 第一章 引言
查看>>
抓住云机遇编排工作 搞定复杂IT工作流
查看>>