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 ...
随机推荐
- 电商网站中价格的精确计算(使用BigDecimal进行精确运算(实现加减乘除运算))
使用BigDecimal的String的构造器.商业计算中,使用bigdecimal的String构造器,一定要用. 重要的事情说三遍: 商业计算中,使用bigdecimal的String构造器! 商 ...
- Cyrus SASL介绍(翻译)
http://blog.sina.com.cn/s/blog_7695e9f40100pnpa.html Cyrus SASL介绍 1. 综述 这篇文档讲述的是系统管理员配置SASL的方法,其中详细的 ...
- NOIP模拟赛11
T1 [HAOI2016]放棋子 https://daniu.luogu.org/problem/show?pid=3182 障碍交换行不影响 所以第i列有障碍的行换到第i行 然后错排公式 本校自测要 ...
- k8s+docker学习连接汇总
http://guide.daocloud.io/dcs/docker-9153982.html http://www.dczou.com/viemall/802.html https://wangl ...
- Shell编程——vim常用命令
[vim]工作模式切换: 在普通模式下输入 i(插入).c(修改).o(另起一行) 命令时进入编辑模式:按 esc 键退回到普通模式. 在普通模式下输入冒号(:)可以进入命令模式.输入完命 ...
- python 版本zabbix_sender
python版本的zabbix_sender: 使用方法: 1.导入 : from zbx_send import info 2.实例化: test=info() 3.支持 ...
- python初步学习-python模块之 os
os os 模块在运维工作中是很常用的一个模块.通过os模块调用系统命令.os模块可以跨平台使用. 在 import os的时候,建议使用import os而非from os import *.这样可 ...
- IDEA常见错误
1. inspects a maven model for resolution problems 在添加Maven依赖的时候,报了inspects a maven model for resolut ...
- .net APIHelper client获取数据
using Newtonsoft.Json; using System.Net.Http.Headers; public static class APIHepler { public static ...
- 导航狗IT周报第十五期(July 8, 2018)
摘要:Seclists.Org: 微信支付SDK存在XXE漏洞:WordPress 4.9.6存在文件删除漏洞:linux中常用的文件打包/解包与压缩/解压缩命令总结… 安全播报 Seclists.O ...