D. Developing Game

题目连接:

http://www.codeforces.com/contest/377/problem/D

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 <bits/stdc++.h>

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;
}

Codeforces Round #222 (Div. 1) D. Developing Game 扫描线的更多相关文章

  1. Codeforces Round #222 (Div. 1) D. Developing Game 线段树有效区间合并

    D. Developing Game   Pavel is going to make a game of his dream. However, he knows that he can't mak ...

  2. Codeforces Round #222 (Div. 1) D. Developing Game

    D - Developing Game 思路:我们先枚举左边界,把合法的都扣出来,那么对于这些合法的来说值有v 和 r两维了,把v, r看成线段的两端, 问题就变成了,最多能选多少线段 使得不存在这样 ...

  3. Codeforces Round #322 (Div. 2) C. Developing Skills 优先队列

    C. Developing Skills Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/581/p ...

  4. Codeforces Round #222 (Div. 1) C. Captains Mode 对弈+dp

    题目链接: http://codeforces.com/contest/378/problem/E 题意: dota选英雄,现在有n个英雄,m个回合,两支队伍: 每一回合两个选择: b 1,队伍一ba ...

  5. Codeforces Round #222 (Div. 1) C. Captains Mode 状压

    C. Captains Mode 题目连接: http://codeforces.com/contest/377/problem/C Description Kostya is a progamer ...

  6. Codeforces Round #222 (Div. 1) B. Preparing for the Contest 二分+线段树

    B. Preparing for the Contest 题目连接: http://codeforces.com/contest/377/problem/B Description Soon ther ...

  7. Codeforces Round #222 (Div. 1) A. Maze dfs

    A. Maze 题目连接: http://codeforces.com/contest/377/problem/A Description Pavel loves grid mazes. A grid ...

  8. Codeforces Round #222 (Div. 1) Maze —— dfs(连通块)

    题目链接:http://codeforces.com/problemset/problem/377/A 题解: 有tot个空格(输入时统计),把其中k个空格变为wall,问怎么变才能使得剩下的空格依然 ...

  9. Codeforces Round #222 (Div. 1) (ABCDE)

    377A Maze 大意: 给定棋盘, 保证初始所有白格连通, 求将$k$个白格变为黑格, 使得白格仍然连通. $dfs$回溯时删除即可. #include <iostream> #inc ...

随机推荐

  1. 嵌入式linux/android alsa_aplay alsa_amixer命令行用法

    几天在嵌入式linux上用到alsa command,网上查的资料多不给力,只有动手一点点查,终于可以用了,将这个使用方法告诉大家,以免大家少走弯路. 0.先查看系统支持哪几个alsa cmd: ll ...

  2. SVC 工作过程中出现的错误记录(SEO项目)

    1.同一のキーを含む項目が既に追加されています.追加的项目中含有重复主键) /seo' アプリケーションでサーバー エラーが発生しました. 同一のキーを含む項目が既に追加されています. 説明: 現在の ...

  3. 含有ref out 参数 的方法反射 Emit 与 普通

    反射中很多朋友应该屡屡被带有ref out参数的方法折腾 当使用正常反射一个方法时候: 代码如下调用一个后期绑定方法MakeByRefType 就行了 MemberInfo test = typeof ...

  4. MVC Ajax Form & Ajax Valida(笔记)

    1.引入必要的文件 <script src=.min.js")" type="text/javascript"></script> &l ...

  5. python_Appium测试环境搭建

    Android环境搭建 移动端Appium环境部署比Web的selenium环境稍微复杂一些,如用python编写测试用例脚本或者开发测试框架以及UI自动化操作方法是一样的,基本是通用.因两者都是基于 ...

  6. 5 个非常有用的 Laravel Blade 指令,你用过哪些?

    接下来我将带大家认识下五个 Laravel Blade 指令,这些指令将让你在解决特定问题时如虎添翼.如果你是刚接触 Laravel 的用户,这些小技巧能带你认识到 Laravel Blade 模板引 ...

  7. js中的call,apply,bind区别

    在JavaScript中,call.apply和bind是Function对象自带的三个方法,这三个方法的主要作用是改变函数中的this指向. call.apply.bind方法的共同点和区别:app ...

  8. linux nc命令使用详解(转)

    linux nc命令使用详解 功能说明:功能强大的网络工具 语 法:nc [-hlnruz][-g<网关...>][-G<指向器数目>][-i<延迟秒数>][-o& ...

  9. 树莓派GPIO控制RGB彩色LED灯

    树莓派GPIO通过PWM来控制RGB彩色LED灯,可以显示任何我们想要的颜色. RGB模块简介 这个RGB彩色LED里其实有3个灯,分别是红灯.绿灯和蓝灯.控制这三个灯分别发出不同强度的光,混合起来就 ...

  10. html-注册邮箱

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...