Codeforces Round #222 (Div. 1) D. Developing Game
思路:我们先枚举左边界,把合法的都扣出来,那么对于这些合法的来说值有v 和 r两维了,把v, r看成线段的两端,
问题就变成了,最多能选多少线段 使得不存在这样两条(l1 r1) (l2 r2) l2 > r1,我们把线段l1 r1 看成二维平面内的点(l1, r1)
那么答案就变成了分别在(1, 1), (2, 2), (3, 3), (4, 4), ....., (n, n)的左上的点的个数的最大值,我们用这个建
线段树然后就变成了区间加减问题。
#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define PII pair<int, int>
#define y1 skldjfskldjg
#define y2 skldfjsklejg using namespace std; const int N = 3e5 + ;
const int M = 1e7 + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = ; int n;
struct segmentTree {
int mx[N << ], lazy[N << ], id[N << ]; void pushdown(int rt) {
if(lazy[rt]) {
lazy[rt << ] += lazy[rt];
lazy[rt << | ] += lazy[rt];
mx[rt << ] += lazy[rt];
mx[rt << | ] += lazy[rt];
lazy[rt] = ;
}
} void pushup(int rt) {
if(mx[rt << ] >= mx[rt << | ]) {
mx[rt] = mx[rt << ];
id[rt] = id[rt << ];
} else {
mx[rt] = mx[rt << | ];
id[rt] = id[rt << | ];
}
} void build(int l, int r, int rt) {
mx[rt] = lazy[rt] = ;
if(l == r) {
id[rt] = l;
return;
}
int mid = l + r >> ;
build(l, mid, rt << );
build(mid + , r, rt << | );
pushup(rt);
} void update(int L, int R, int val, int l, int r, int rt) {
if(l >= L && r <= R) {
mx[rt] += val;
lazy[rt] += val;
return;
}
int mid = l + r >> ;
pushdown(rt);
if(L <= mid) update(L, R, val, l, mid, rt << );
if(R > mid) update(L, R, val, mid + , r, rt << | );
pushup(rt);
}
} seg; struct node {
int l, v, r, id;
bool operator < (const node &rhs) const {
return l < rhs.l;
}
} a[N]; int main() {
seg.build(, , );
scanf("%d", &n);
for(int i = ; i <= n; i++)
scanf("%d%d%d", &a[i].l, &a[i].v, &a[i].r), a[i].id = i;
sort(a + , a + + n); int ans = , ret1, ret2;
priority_queue<PII, vector<PII>, greater<PII> > que;
for(int i = , j = ; i <= ; i++) { while(j <= n && a[j].l <= i) {
int x = a[j].v, y = a[j].r;
que.push(mk(x, y));
seg.update(x, y, , , , );
j++;
} while(!que.empty() && que.top() < mk(i, )) {
PII now = que.top(); que.pop();
seg.update(now.fi, now.se, -, , , );
} if(ans < seg.mx[]) {
ans = seg.mx[];
ret1 = i;
ret2 = seg.id[];
}
} vector<int> vec;
for(int i = ; i <= n; i++) {
if(a[i].l <= ret1 && a[i].v >= ret1 && a[i].v <= ret2 && a[i].r >= ret2)
vec.push_back(a[i].id);
} sort(vec.begin(), vec.end());
printf("%d\n", vec.size());
for(int i = ; i < vec.size(); i++)
printf("%d ", vec[i]);
puts("");
return ;
} /*
*/
Codeforces Round #222 (Div. 1) D. Developing Game的更多相关文章
- 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 #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 ...
- 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 ...
- Codeforces Round #222 (Div. 1) C. Captains Mode 对弈+dp
题目链接: http://codeforces.com/contest/378/problem/E 题意: dota选英雄,现在有n个英雄,m个回合,两支队伍: 每一回合两个选择: b 1,队伍一ba ...
- Codeforces Round #222 (Div. 1) C. Captains Mode 状压
C. Captains Mode 题目连接: http://codeforces.com/contest/377/problem/C Description Kostya is a progamer ...
- 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 ...
- Codeforces Round #222 (Div. 1) A. Maze dfs
A. Maze 题目连接: http://codeforces.com/contest/377/problem/A Description Pavel loves grid mazes. A grid ...
- Codeforces Round #222 (Div. 1) Maze —— dfs(连通块)
题目链接:http://codeforces.com/problemset/problem/377/A 题解: 有tot个空格(输入时统计),把其中k个空格变为wall,问怎么变才能使得剩下的空格依然 ...
- Codeforces Round #222 (Div. 1) (ABCDE)
377A Maze 大意: 给定棋盘, 保证初始所有白格连通, 求将$k$个白格变为黑格, 使得白格仍然连通. $dfs$回溯时删除即可. #include <iostream> #inc ...
随机推荐
- php网摘收藏
1.thinkphp3.2.3开发手册: http://document.thinkphp.cn/manual_3_2.html 2.ThinkPHP3.2.3的函数汇总:http://www.thi ...
- ZooKeeper在线迁移
在至少有一个Leader存在的前提下,进行Zookeeper的在线增量.在线减量.在线迁移 在全过程中ZooKeeper不停止服务 注意事项 首先,当我们要从3台扩充到5台时,应保证集群不停止服务. ...
- CCPC2018-A-Buy and Resell
Problem Description The Power Cube is used as a stash of Exotic Power. There are n cities numbered 1 ...
- 2015/10/9 Python基础(21):可调用和可执行对象
在Python中有多种运行外部程序的方法,比如,运行操作系统命令或另外的Python脚本,或执行一个磁盘上的文件,或通过网络来运行文件.这完全取决于想要干什么.特定的环境包括: 在当前脚本继续运行 创 ...
- LintCode 532: Reverse Pairs
LintCode 35: Reverse Linked List 题目描述 翻转一个链表. 样例 给出一个链表1->2->3->null,这个翻转后的链表为3->2->1 ...
- Linux下搜索命令
linux下用于查找文件的5个命令,有需要的朋友可以参考下.包括find,whereis,locate,which与type. linux下用于查找文件的5个命令,有需要的朋友可以参考下.包括find ...
- kippo蜜罐搭建
kippo蜜罐搭建 总结一下kippo蜜罐搭建的方法,centos系统.kippo-master.zip的安装包 (gcc,python-devel,pip,twisted==13.10,pycryp ...
- Python os模块和sys模块 操作系统的各种接口
一.os模块 这个模块提供了一个便携式去使用操作系统的相关功能,如果只是想操作路径,请参阅os.path模块. ''' os.getcwd() 获取当前工作目录,即当前python脚本工作的目录路径 ...
- css给奇数行或偶数行添加指定样式
odd表示奇数行,even表示偶数行; tr:nth-child(odd); .table-striped > tbody > tr:nth-child(odd) { background ...
- openssh升级步骤
1下载openssh最新版本 2 configure ./configure --prefix= /ssh先配置一下 再在本地安装. make &makeinstall 3 按照/ssh包含内 ...