题目链接:

luogu

题目分析:

把每个人当成一个三元组\([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的更多相关文章

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

  2. [C# WPF]MoeEroViewer Developing Log

    [C# WPF]MoeEroViewer Developing Log 1st - Base Document run on Https://github.com/Amarillys/MoeEroVi ...

  3. Google Developing for Android 三 - Performance最佳实践

    Google Developing for Android 三 - Performance最佳实践 发表于 2015-06-07   |   分类于 Android最佳实践 原文 Developing ...

  4. Google Developing for Android 二 - Memory 最佳实践 // lightSky‘Blog

    Google Developing for Android 二 - Memory 最佳实践   |   分类于 Android最佳实践 原文:Developing for Android, II Th ...

  5. Google Developing for Android 一 - 相关上下文介绍

    前几天在G+上看到Google Developers站点,有一个Android系列的文章,分享到个人微博,周末闲来没事就学写了下,把它们简单的翻译了下,没想到一发不可收拾,六篇文章全部都翻译完了,有些 ...

  6. AX7: Get started developing

    This blog will show how you can start making a customization in AX 7 by showing you the steps needed ...

  7. Spark(2) - Developing Application with Spark

    Exploring the Spark shell Spark comes bundled with a PERL shell, which is a wrapper around the Scala ...

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

  9. Developing iOS8 Apps with Swift——iOS8概览

    iOS 8 概览 斯坦福公开课--Developing iOS8 Apps with Swift学习笔记 想学习Swift,但是相应的教程不是很多,在CoCoaChina社区闲逛时恰好发现了这门课程, ...

随机推荐

  1. 5.1中容器(Container)和门面(Facade)的实现

    tp5.1中引入了容器(Container)和门面(Facade)这两个新的类 官方文档已经给出了定义: 容器(Container)实现类的统一管理,确保对象实例的唯一性. 门面(Facade)为容器 ...

  2. VS2012在win7 64位机中x86和x64下基本类型的占用空间大小(转)

    VS2012在win7 64位机中x86和x64下基本类型的占用空间大小 #include "stdafx.h" #include <windows.h> int _t ...

  3. Tomcat爆破

    把输入的账户和密码包起来 选择第三个模式 第一个添加用户名 第二个添加: 第三个添加密码 选择编码格式 取消打钩

  4. API Gateway和Route 53及CloudFront的连携使用

    API Gateway部署出来之后的url网址对于普通用户并不友好,所以肯定是需要一个正常的域名来作为url进行访问. 主要有以下几点, API Gateway可以自定义域名 自定义的域名要从Rout ...

  5. robotframework+python3+selenium之创建第一个项目---第三集

    1.新建一个project 选择Directory,则是文件夹 2.选择文件,创建new suite    test_1 3.创建test case   baidu_test 4.此时界面如图: 5. ...

  6. -bash: docker-compose: command not found、linux 安装 docker-compose

    方式1:https://blog.csdn.net/qq_32447321/article/details/76512137 方式2: curl -L https://get.daocloud.io/ ...

  7. 16. 继承(extends)

    1.语法 class 类名1 extends 类名2{ //成员变量和成员方法 } 2.继承要注意的事项: 1)千万不要为了减少重复代码而去继承,只有真正存在着继承关系的时候才去继承. 2)父类私有的 ...

  8. PHP获取远程客户端真实IP的办法!

    (1).REMOTE_ADDR:浏览当前页面的用户计算机的ip地址 (2).HTTP_X_FORWARDED_FOR: 浏览当前页面的用户计算机的网关 (3).HTTP_CLIENT_IP:客户端的i ...

  9. js基础用法 ,基础语法

    js用法: HTML 中的脚本必须位于 <script> 与 </script> 标签之间. 脚本可被放置在 HTML 页面的 <body> 和 <head& ...

  10. vue-为什么子组件中的data选项必须是函数?

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...