CF377D Developing Game
题目链接:
题目分析:
把每个人当成一个三元组\([l_i, r_i, v_i]\)
考虑每个人对哪个能力区间\([L, R]\)有贡献
应该是左端点在\([l_i, v_i]\),右端点在\([v_i, r_i]\)的区间
拍到一个二维平面上,求最多有多少个矩形交一起
线段树维护扫描线即可
代码:
#include<bits/stdc++.h>
#define N (600000 + 10)
using namespace std;
inline int read() {
int cnt = 0, f = 1; char c = getchar();
while (!isdigit(c)) {if (c == '-') f = -f; c = getchar();}
while (isdigit(c)) {cnt = (cnt << 3) + (cnt << 1) + (c ^ 48); c = getchar();}
return cnt * f;
}
int n, Y[N], cnt, ans = 0, ansx, ansy, tot;
int l[N], r[N], v[N];
struct node2 {
int x, Y1, Y2, tag;
}seg[N << 1];
struct node {
int l, r;
int tag, gmax, pos;
#define l(p) tree[p].l
#define r(p) tree[p].r
#define tag(p) tree[p].tag
#define gmax(p) tree[p].gmax
#define pos(p) tree[p].pos
} tree[N << 2];
void pushdown(int p) {
tag(p << 1) += tag(p);
tag(p << 1 | 1) += tag(p);
gmax(p << 1) += tag(p);
gmax(p << 1 | 1) += tag(p);
tag(p) = 0;
}
void pushup(int p) {
if (gmax(p << 1) > gmax(p << 1 | 1)) {
pos(p) = pos(p << 1);
gmax(p) = gmax(p << 1);
} else {
pos(p) = pos(p << 1 | 1);
gmax(p) = gmax(p << 1 | 1);
}
}
void build (int p, int l, int r) {
l(p) = l, r(p) = r;
if (l == r) {pos(p) = Y[l]; return;}
int mid = (l + r) >> 1;
build (p << 1, l, mid);
build (p << 1 | 1, mid + 1, r);
pos(p) = pos(p << 1);
}
void modify(int p, int l, int r, int k) {
pushdown(p);
if (l <= Y[l(p)] && r >= Y[r(p)]) {tag(p) += k, gmax(p) += k; return;}
int mid = (l(p) + r(p)) >> 1;
if (l <= Y[mid]) modify(p << 1, l, r, k);
if (r > Y[mid]) modify(p << 1 | 1, l, r, k);
pushup(p);
}
bool cmp(node2 a, node2 b) {
return a.x == b.x ? a.tag > b.tag : a.x < b.x;
}
int main() {
// freopen("data.in", "r", stdin);
// freopen("myself.out", "w", stdout);
n = read();
for (register int i = 1; i <= n; ++i) {
l[i] = read(), v[i] = read(), r[i] = read();
seg[++tot].x = l[i], seg[tot].Y1 = v[i], seg[tot].Y2 = r[i], seg[tot].tag = 1, Y[tot] = v[i];
seg[++tot].x = v[i], seg[tot].Y1 = v[i], seg[tot].Y2 = r[i], seg[tot].tag = -1, Y[tot] = r[i];
}
sort (Y + 1, Y + tot + 1);
for (register int i = 1; i <= tot; ++i) if (Y[i] != Y[i + 1]) Y[++cnt] = Y[i];
build (1, 1, cnt);
sort (seg + 1, seg + tot + 1, cmp);
// for (register int i = 1; i <= cnt; ++i) cout<<Y[i]<<" "; return 0;
for (register int i = 1; i <= tot; ++i) {
modify(1, seg[i].Y1, seg[i].Y2, seg[i].tag);
// cout<<gmax(1)<<" ";
if (gmax(1) > ans) {
ans = gmax(1);
ansx = seg[i].x;
ansy = pos(1);
}
}
// return 0;
printf("%d\n", ans);
// cout<<ansx<<" "<<ansy<<endl; return 0;
for (register int i = 1; i <= n; ++i)
if (v[i] <= ansy && r[i] >= ansy && l[i] <= ansx && v[i] >= ansx) printf("%d ", i);
return 0;
}
CF377D Developing Game的更多相关文章
- 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 ...
- [C# WPF]MoeEroViewer Developing Log
[C# WPF]MoeEroViewer Developing Log 1st - Base Document run on Https://github.com/Amarillys/MoeEroVi ...
- Google Developing for Android 三 - Performance最佳实践
Google Developing for Android 三 - Performance最佳实践 发表于 2015-06-07 | 分类于 Android最佳实践 原文 Developing ...
- Google Developing for Android 二 - Memory 最佳实践 // lightSky‘Blog
Google Developing for Android 二 - Memory 最佳实践 | 分类于 Android最佳实践 原文:Developing for Android, II Th ...
- Google Developing for Android 一 - 相关上下文介绍
前几天在G+上看到Google Developers站点,有一个Android系列的文章,分享到个人微博,周末闲来没事就学写了下,把它们简单的翻译了下,没想到一发不可收拾,六篇文章全部都翻译完了,有些 ...
- AX7: Get started developing
This blog will show how you can start making a customization in AX 7 by showing you the steps needed ...
- Spark(2) - Developing Application with Spark
Exploring the Spark shell Spark comes bundled with a PERL shell, which is a wrapper around the Scala ...
- 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 ...
- Developing iOS8 Apps with Swift——iOS8概览
iOS 8 概览 斯坦福公开课--Developing iOS8 Apps with Swift学习笔记 想学习Swift,但是相应的教程不是很多,在CoCoaChina社区闲逛时恰好发现了这门课程, ...
随机推荐
- GC线程是否为守护线程?
GC是垃圾收集的意思,Java提供的GC功能可以自动监测对象是否超过作用域从而达到自动回收内存的目的,从而有效的防止内存泄露.要请求垃圾收集,可以调用下面的方法之一:System.gc()或Runti ...
- vue组件基础之父子传值
可以看出数据从后端获取过来,最外层的父组件接收数据,子组件不能直接获取,必须由父组件传递,此时使用props,并且父组件的值更新后,子组件的值也会随之更新,但是反过来通过修改子组件props来影响父组 ...
- python中模块和包的概念
1.模块 一个.py文件就是一个模块.这个文件的名字是:模块名.py.由此可见在python中,文件名和模块名的差别只是有没有后缀.有后缀是文件名,没有后缀是模块名. 每个文件(每个模块)都是一个独立 ...
- Batch - FOR %%a %%b
总结 %%a refers to the name of the variable your for loop will write to. Quoted from for /?: FOR %vari ...
- 解决MySQL登录密码正确却提示错误-1045的方法
MySQL密码正确却无法本地登录-1045 Access denied for user 'root'@'localhost' (using password:YES MySQL密码正确却无法本地登录 ...
- ul -- li 模拟select下拉框
在写项目中 用到下拉框,一般用 <select name="" id=""> <option value=</option> &l ...
- 0928CSP-S模拟测试赛后总结
依旧跌落.昨天只是偶然诈尸.我依旧是那个第二机房垫底大垃圾. 赛时打的很放松.因为T1想到了正解.对拍也打了.尽管用了大约一半的考试时间. 但是对拍拍了很久没有出错.如果你在2019年9月28日晚一下 ...
- Delphi实现屏幕截图、窗口截图、指定区域截图
Use Jpeg procedure TForm1.snapscreen(a,b,c,d:Integer); var bmpscreen:Tbitmap; jpegscreen:Tjpegimage; ...
- NX二次开发-NXOpen::WCS Class Reference
NX11+VS2013 #include <NXOpen/Part.hxx> #include <NXOpen/PartCollection.hxx> #include < ...
- Dll注入技术之ComRes注入
DLL注入技术之ComRes注入 ComRes注入的原理是利用Windows 系统中C:\WINDOWS\system32目录下的ComRes.dll这个文件,当待注入EXE如果使用CoCreateI ...