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

转载于:https://www.cnblogs.com/qscqesze/p/5541837.html

Codeforces Round #222 (Div. 1) D. Developing Game 扫描线相关推荐

  1. Codeforces Round #222 (Div. 2)

    链接:http://codeforces.com/contest/378 A:模拟 B:http://codeforces.com/contest/378/problem/B C:BFS/DFS 写挂 ...

  2. Codeforces Round #222 (Div. 2): C. Maze(BFS)

    题意: 给你一个n*m的迷宫,'.'是路,'#'是墙,输入保证所有的'.'构成一个联通块,要求为这个迷宫再添加k面墙,使得剩下所有的'.'仍然构成一个联通块 思路:反过来处理,先将所有的'.'全部变成 ...

  3. Codeforces Round #672 (Div. 2)D. Rescue Nibel![扫描线解决区间问题]

    题目链接 题目大意:就是给你n个区间,从中选出k个区间,这k个区间共同覆盖了同一个点,问有多少种选法?结果mod 998244353 解题思路:1.首先我们可以这么想:我们把区间左端点赋值为1,右端点 ...

  4. Codeforces Round #696 (Div. 2) (A ~ E)超高质量题解(每日训练 Day.16 )

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Codeforces Round #696 (Div. 2) (A ~ E)超高质量题解 比赛链接:h ...

  5. Codeforces Round #734 (Div. 3) 题解

    Hello大家好,今天给大家带来的是 Codeforces Round #734 (Div. 3) 的全题目讲解. 本文链接:https://www.lanqiao.cn/questions/2040 ...

  6. Codeforces Round #739 (Div. 3)(AK实况)

    Codeforces Round #739 (Div. 3) A. Dislike of Threes 找到第kkk个既不是333的倍数,个位数上也不是333的数,也已预处理然后O(1)O(1)O(1 ...

  7. Codeforces Round #653 (Div. 3)(A, B, C, D, E1详解)

    Codeforces Round #653 (Div. 3) Required Remainder Thinking(binary search) 既然是找最大值问题,我又懒得去推式子,于是我直接就上 ...

  8. Codeforces Round #731 (Div. 3) G. How Many Paths? dfs + 拓扑 + 思维

    传送门 题意: 给你一张nnn个点mmm条边的图,让你对每个点确定一个编号,规则如下: (1)(1)(1) 对于不能到的点编号为000. (2)(2)(2) 对于只有一条路径能到这个点的点编号为111 ...

  9. Codeforces Round #586 (Div. 1 + Div. 2) D. Alex and Julian 数学 + 思维

    传送门 文章目录 题意: 思路: 题意: 给你一个无限个点的坐标轴,一个集合BBB,如果存在∣i−j∣=bk|i-j|=b_k∣i−j∣=bk​的话,那么i,ji,ji,j之间就连边.现在问你至少要从 ...

  10. Codeforces Round #730 (Div. 2) D2. RPD and Rap Sheet (Hard Version) 交互 + k进制的转换

    传送门 文章目录 题意: 思路: 题意: 定义a⊕kba\oplus_k ba⊕k​b为a,ba,ba,b在kkk进制下的不进位加法.系统会随机生成一个数xxx,你猜这个数,假设当前猜的数为yyy,如 ...

最新文章

  1. 传统CV和深度学习方法的比较
  2. 转载 干货 | 陪伴我学习NLP、知识图谱的那些资源(教程+书籍+网站+工具+论文...可以说很全面了)
  3. 皮一皮:误删了一段代码后系统还能跑起来!
  4. happens-before俗解
  5. jQuery插件 -- Cookie插件
  6. 火热招募中 | PMCAFF产品经理社区志愿者计划火热开启
  7. pandas loc 正则匹配字符串_一场pandas与SQL的巅峰大战(二)
  8. 深度学习之 BP 算法
  9. Unexpected end of JSON input while parsing near '...解决方法
  10. 69讲入门python_Python入门,一定要吃透这69个内置函数
  11. 前端开发工程师---技术路线图
  12. uploadify插件可选参数的详细介绍
  13. naked 函数调用
  14. 关于MyBatis一级缓存、二级缓存那些事
  15. InstallShield教程-打包.NET程序
  16. python键盘输入字典类型_python数据类型——字典类型
  17. 孤儿进程与僵尸进程产生及其处理
  18. 夜神模拟器+Burp抓包(简直是后端复现调试的福音)
  19. Java中hash算法细述
  20. C++ Bulider6.0下string类型问题

热门文章

  1. BS与CS的联系与区别【简】
  2. 20170216--PYthon 类 +面向对象编程+(文件的处理+echo小程序的实现)
  3. hive启动debug问题
  4. nagios介绍及Server安装(三)
  5. [转]哈希算法(Hash Algorithm)初探
  6. 大数据比海量数据多了什么
  7. 15_实现浏览器记录
  8. 旅游后台管理系列——使用maven tomcat插件启动web工程
  9. [笔记]如何解决Your project contains C++ files but it is not using a supported native build system
  10. js基础-17-解析url的函数,字符串出现的次数最多,并统计它出现几次