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.

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 liviri (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.

Examples
input
4
2 8 9
1 4 7
3 6 8
5 8 10
output
3
1 3 4
 题意:
  给你n个人的 位置v[i],同时每个人有一个可接受范围 l[i], r[i];
  现在让你选尽量多的人,使得被选的人 都能互相接受
  输出人数及选择方案
题解
  这个题看到不太会
  对于两个人来说要让它们相互接受可以有以下情况
          l1          v1              r1
                  l2  v2      r2
             l2            v2     r2 
            l2           v2              r2
           l2                     v2     r2
  发现一些规则
  就是相交范围就是l1 v1 与 l2 v2的相交的一段,但是当v2超过r1的时候,就不可行了
  所有我们可以想到一种 加上,减去的操作,
  当v1 出现我们在线段树上加入l1,v1的这段有效的区间
  当走过r1的时候 把l1 v1在线段树上减去即可 
  显然对于一条线段要拆成两条线段, l1 v1 1 v1 和   l1 v1 -1 v2
  再在线段树上操作就可以了
  统计答案的时候呢,也可以利用线段树有效区间出来
  @doubility
#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 线段树有效区间合并的更多相关文章

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

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

  2. Codeforces Round #603 (Div. 2) E. Editor(线段树)

    链接: https://codeforces.com/contest/1263/problem/E 题意: The development of a text editor is a hard pro ...

  3. 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 ...

  4. Codeforces Round #530 (Div. 2) F (树形dp+线段树)

    F. Cookies 链接:http://codeforces.com/contest/1099/problem/F 题意: 给你一棵树,树上有n个节点,每个节点上有ai块饼干,在这个节点上的每块饼干 ...

  5. Codeforces Round #222 (Div. 1) D. Developing Game 扫描线

    D. Developing Game 题目连接: http://www.codeforces.com/contest/377/problem/D Description Pavel is going ...

  6. Codeforces Round #546 (Div. 2) E 推公式 + 线段树

    https://codeforces.com/contest/1136/problem/E 题意 给你一个有n个数字的a数组,一个有n-1个数字的k数组,两种操作: 1.将a[i]+x,假如a[i]+ ...

  7. Codeforces Round #275 Div.1 B Interesting Array --线段树

    题意: 构造一个序列,满足m个形如:[l,r,c] 的条件. [l,r,c]表示[l,r]中的元素按位与(&)的和为c. 解法: 线段树维护,sum[rt]表示要满足到现在为止的条件时该子树的 ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. 【Beta】Scrum03

    Info 时间:2016.12.01 21:30 时长:15min 地点:大运村1号公寓5楼楼道 类型:日常Scrum会议 NXT:2016.12.04 21:30 Task Report Name ...

  2. BZOJ 4569 萌萌哒

    题目传送门 4569: [Scoi2016]萌萌哒 Time Limit: 10 Sec Memory Limit: 256 MB Submit: 483 Solved: 221 [Submit][S ...

  3. 面试题目——《CC150》递归与动态规划

    面试题9.1:有个小孩正在上楼梯,楼梯有n个台阶,小孩一次可以上1阶.2阶或者3阶.实现一个方法,计算小孩有多少种上楼梯的方式. 思路:第4个数是前三个数之和 注意:能不能使用递归,能不能建立一个很大 ...

  4. Java学习笔记12

    循环 打印一个字符串(例如: "Welcome to Java!") 100次,就需要吧下面的输出语句重复写100遍,这是相当繁琐的: System.out.println(&qu ...

  5. sqilite学习

    1,用代码插入数据 for (int i = 0; i < 100; i++) {        NSString *nameStr = [NSString stringWithFormat:@ ...

  6. 转 C# 只允许运行一个实例

    来源:http://blog.csdn.net/jin20000/article/details/3136791 互斥进程(程序), 简单点说,就是在系统中只能有该程序的一个实例运行. 现在很多软件都 ...

  7. PHP输出XML文件函数

    PHP输出XML文件函数 function xml_out($content, $charset = 'utf-8') { @header("Expires: -1"); @hea ...

  8. composer的安装以及laravel框架的安装(一)

    laravel号称世界上最好的php框架,没有之一,下面介绍它的安装 laravel学习交流qq群:293798134 composer的安装 : php开发者很多,并且在web开发领域占据绝对统治地 ...

  9. java抽象-老师的生日-逻辑思维-有趣的面试题-遁地龙卷风

    (-1)写在前面 都快去北京了,硬生生的安排一场java考试,对于那些特别细节的东西我忘了吧也不觉得有什么不好,以前都记得,也都见过,只不过平时不常用连接断了,但是你死记硬背是没用的,一段时间后还是会 ...

  10. C++ 异常机制

    程序在运行的时候可能产生各种可预料到的异常,例如磁盘不足,内存不足,或是数学运算溢出,数组越界之类的.为了解决这些问题,C++提供了异常处理机制,它一般是由try语句和catch语句构成. 一.try ...