UVALive 6261 Jewel heist
题意:珠宝大盗Arsen Lupin偷珠宝。在展厅内,每颗珠宝有个一个坐标为(xi,yi)和颜色ci。
Arsen Lupin发明了一种设备,可以抓取平行x轴的一条线段下的所有珠宝而不触发警报,
唯一的限制是抓取的珠宝不能不能有所有的m种颜色。询问能抓取的最大珠宝数量。
分析:要决策的东西有两个,一是这条线段的y坐标,二是线段的x的范围。
枚举线段的y坐标,线段宽度要保证下方不能有所有的颜色,这需要知道颜色的关于x的坐标信息,
为了x的坐标信息的重复利用,从小到大枚举y。
对于一个固定的yi,怎么找到合适的区间呢?一个简单且正确的想法是枚举不要的颜色,
对于每种不要的颜色,只要选择不包含这种颜色的区间就可以保证符号要求了。
但是这样做太慢了,枚举颜色是O(n)的。
幸运的是,这里面有大量的重复计算,在枚举yi-1的时候,有很多的区间是不会变的,已经计算过的了,
只要枚举发生了改变的区间。
关于颜色的区间信息可以用set保存,在枚举的区间合法的情况下只是一个区间询问单点更新可用BIT,下标范围需要离散。
/*********************************************************
* ---------------------------- *
* author AbyssalFish *
**********************************************************/
#include<bits/stdc++.h>
using namespace std; typedef long long ll; const int maxn = 2e5+; set<int> S[maxn]; int x[maxn],y[maxn],c[maxn];
int r[maxn], xs[maxn]; int *cmp_c;
bool cmp_id(int i,int j){ return cmp_c[i] < cmp_c[j]; } int C[maxn];
int ns; void add(int x)
{
while(x <= ns){
C[x]++; x += x&-x;
}
} int sum(int x)
{
int re = ;
while(x > ){
re += C[x]; x &= x-;
}
return re;
} void solve()
{
int n, m, i, j, k;
scanf("%d%d",&n,&m);
for(i = ; i < n; i++) {
scanf("%d%d%d",x+i,y+i,c+i);
r[i] = i;
} cmp_c = x;
sort(r,r+n,cmp_id);
ns = ;
xs[r[]] = ns;
for(i = ; i < n; i++){
xs[r[i]] = (x[r[i]] == x[r[i-]]) ? ns:++ns;
} for(i = ; i <= m; i++){
S[i].clear();
S[i].insert();
S[i].insert(ns+);
} cmp_c = y;
for(i = ; i < n; i++) r[i] = i;
sort(r,r+n,cmp_id); memset(C+,,sizeof(int)*ns); int ans = , p, q, cur_y;
for(i = ; i < n; i = k){
cur_y = y[r[i]];
for(j = i; j < n && y[k = r[j]] == cur_y; j++){
auto it = S[c[k]].lower_bound(xs[k]);
p = *it-;
q = *--it;
if(p > q)
ans = max(ans,sum(p)-sum(q));
}
k = j;
while(--j >= i){
p = r[j];
S[c[p]].insert(xs[p]);
add(xs[p]);
}
}
for(i = ; i <= m; i++){
auto it = S[i].begin();
q = ;
for(it++; it != S[i].end(); it++){
p = *it-;
if(p > q) ans = max(ans, sum(p) - sum(q));
q = *it;
}
}
printf("%d\n", ans);
} //#define LOCAL
int main()
{
#ifdef LOCAL
freopen("in.txt","r",stdin);
#endif
int T; scanf("%d",&T);
while(T--) solve();
return ;
}
UVALive 6261 Jewel heist的更多相关文章
- 要back的题目 先立一个flag
要back的题目 目标是全绿!back一题删一题! acmm7 1003 1004 acmm8 1003 1004 sysu20181013 Stat Origin Title Solved A Gy ...
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
- UVALive - 4108 SKYLINE[线段树]
UVALive - 4108 SKYLINE Time Limit: 3000MS 64bit IO Format: %lld & %llu Submit Status uDebug ...
- UVALive - 3942 Remember the Word[树状数组]
UVALive - 3942 Remember the Word A potentiometer, or potmeter for short, is an electronic device wit ...
- UVALive - 3942 Remember the Word[Trie DP]
UVALive - 3942 Remember the Word Neal is very curious about combinatorial problems, and now here com ...
- HDU 3727 Jewel 可持久化线段树
Jewel Problem Description Jimmy wants to make a special necklace for his girlfriend. He bought man ...
- 思维 UVALive 3708 Graveyard
题目传送门 /* 题意:本来有n个雕塑,等间距的分布在圆周上,现在多了m个雕塑,问一共要移动多少距离: 思维题:认为一个雕塑不动,视为坐标0,其他点向最近的点移动,四舍五入判断,比例最后乘会10000 ...
- UVALive 6145 Version Controlled IDE(可持久化treap、rope)
题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...
- UVALive 6508 Permutation Graphs
Permutation Graphs Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit ...
随机推荐
- VUE项目引入微信jssdk
npm i -S weixin-js-sdkimport wx from 'weixin-js-sdk'
- C# 判读取得字符编码格式
FileStream fs1 = new FileStream(folder + strPath, FileMode.Open); byte[] bytes = new byte[fs1.Length ...
- [Activator- HelloAkka] Define our Messages
An Actor does not have a public API in terms of methods that you can invoke. Instead its public API ...
- windows下libcurl+openssl编译与使用配置
之前使用过libcurl, 编译也是最简单的版本, 不需要openssl, 即不需要支持https, 所以编译和使用都很正常. 但要使用openssl就很麻烦了, 我花了差不多两天去编译和调用, 记录 ...
- 【Ubuntu】设置静态ip地址
一.Ubuntu16.04设置静态IP1.获取网卡的名字 ip route show 2.获取网卡的名字 vim /etc/network/interfaces auto ens33 iface ...
- 循环结构 while
while 循环语句可以根据某些条件重复执行一条t-sql 语句或一个语句块 语法: while (条件) begin 语句或语句块 end 程序调试 alt+f5 启动调试 f9 切换断点 f10 ...
- SpringSecurity 3.2入门(2)环境搭建
由于目前Spring官方只提供Meven的下载方式,为了能以最快的速度入门使用框架,这里提供百度网盘下载链接. 注:本入门教程默认已经配置成功SpringMVC框架. 1.web.xml配置 < ...
- node.js发邮件
在node上使用第三方类库(nodemailer)发邮件是一件很esay的事情:) app.js 以QQ邮箱为例 var nodemailer = require('nodemailer'); v ...
- 类数组arguments
var isArray = function(){ return arguments; } isArray(1,2,3); // 返回[1,2,3] isArray.call(null,1,2,3); ...
- bean 的生命周期
就是在new ClassPathXMLApplicationContext 的时候是否就直接在内存中new 出来,如果是对象比较的情景下 ,为了提高程序初始化的速度,可以用用. 如果设置为 true ...