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 ...
随机推荐
- laravel5.1 使用中间表的多对多关联
用户表user 标签表tag 中间表user_tag(user_id,tag_id) 在user模型中定义tags关联如下: public function tags() { return $this ...
- mac和linux下sed使用的不同
http://note.youdao.com/noteshare?id=84a6a0eb3e3f1698c9de4f48db24226e
- 「Django」rest_framework学习系列-权限认证
权限认证:1.项目下utils文件写permissions.py文件 from rest_framework.permissions import BasePermission class SVIPP ...
- Bootsrap 直接使用
Bootstrap3 直接使用 <!DOCTYPE html> <html> <head> <title>Bootstrap3</title> ...
- Oracle用imp导入dmp 提示遇到 ORACLE 错误 12560 TNS: 协议适配器错误 解决方法
用imp命令导入dmp文件时提示以下错误: IMP-00058: 遇到 ORACLE 错误 12560 : ORA-12560: TNS: 协议适配器错误 : IMP-00000: 未成功终止导入 : ...
- 条件转化,2-sat BZOJ 1997
http://www.lydsy.com/JudgeOnline/problem.php?id=1997 1997: [Hnoi2010]Planar Time Limit: 10 Sec Memo ...
- 30款基于 jQuery & CSS3 的加载动画和进度条插件
我们所生活每一天看到的新技术或新设计潮流的兴起,Web 开发正处在上升的时代.HTML5 & CSS3 技术的发展让 Web 端可以实现的功能越来越强大. 加载动画和进度条使网站更具吸引力.该 ...
- 【BZOJ】1576 [Usaco2009 Jan]安全路经Travel
[算法]最短路树+(树链剖分+线段树)||最短路树+并查集 [题解] 两种方法的思想是一样的,首先题目限制了最短路树唯一. 那么建出最短路树后,就是询问对于每个点断掉父边后重新找路径的最小值,其它路径 ...
- 【BZOJ】1426: 收集邮票 期望DP
[题意]有n种不同的邮票,第i次可以花i元等概率购买到一种邮票,求集齐n种邮票的期望代价.n<=10^4. [算法]期望DP [题解]首先设g[i]表示已拥有i张邮票集齐的期望购买次数,根据全期 ...
- 【leetcode 简单】第三十四题 只出现一次的数字
给定一个非空整数数组,除了某个元素只出现一次以外,其余每个元素均出现两次.找出那个只出现了一次的元素. 说明: 你的算法应该具有线性时间复杂度. 你可以不使用额外空间来实现吗? 示例 1: 输入: [ ...