题意:珠宝大盗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的更多相关文章

  1. 要back的题目 先立一个flag

    要back的题目 目标是全绿!back一题删一题! acmm7 1003 1004 acmm8 1003 1004 sysu20181013 Stat Origin Title Solved A Gy ...

  2. bzoj AC倒序

    Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...

  3. UVALive - 4108 SKYLINE[线段树]

    UVALive - 4108 SKYLINE Time Limit: 3000MS     64bit IO Format: %lld & %llu Submit Status uDebug ...

  4. UVALive - 3942 Remember the Word[树状数组]

    UVALive - 3942 Remember the Word A potentiometer, or potmeter for short, is an electronic device wit ...

  5. UVALive - 3942 Remember the Word[Trie DP]

    UVALive - 3942 Remember the Word Neal is very curious about combinatorial problems, and now here com ...

  6. HDU 3727 Jewel 可持久化线段树

    Jewel Problem Description   Jimmy wants to make a special necklace for his girlfriend. He bought man ...

  7. 思维 UVALive 3708 Graveyard

    题目传送门 /* 题意:本来有n个雕塑,等间距的分布在圆周上,现在多了m个雕塑,问一共要移动多少距离: 思维题:认为一个雕塑不动,视为坐标0,其他点向最近的点移动,四舍五入判断,比例最后乘会10000 ...

  8. UVALive 6145 Version Controlled IDE(可持久化treap、rope)

    题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...

  9. UVALive 6508 Permutation Graphs

    Permutation Graphs Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit ...

随机推荐

  1. Python异常基础

    一.常见异常及场景举例 1.AssertionError 断言失败,断言是调试中常用(表示自己并不常用┑( ̄Д  ̄)┍)手段 举例: def foo(s): n = int(s) assert n ! ...

  2. Linux混杂设备驱动

    1. Linux混杂设备驱动模型 ① 在Linux系统中,存在一类字符设备,它们拥有相同的主设备号(10),但次设备号不同,我们称这类设备为混杂设备(miscdevice).所有混杂设备形成一个链表, ...

  3. Spring Cload

    Spring Cloud 从入门到精通 转载: https://blog.csdn.net/valada/article/details/80892573 https://gitbook.cn/git ...

  4. redis安装配置远程连接

    一.安装redis linux上直接yum安装 yum install redis windows版本下载地址 https://github.com/ServiceStack/redis-window ...

  5. javascript中for in与in的用法

    1.For...In 声明用于对数组或者对象的属性进行循环/迭代操作. 对于数组 ,迭代出来的是数组元 素,对于对象 ,迭代出来的是对象的属性: var x var mycars = new Arra ...

  6. nopCommerce 3.9 版本发行

    NopCommerce中文信息地址:http://www.nopcn.com/nopcommerce39-blog-release-notes.html NopCommerce英文地址:http:// ...

  7. 微信小程序支付c#后台实现

    今天为大家带来比较简单的支付后台处理 首先下载官方的c#模板(WxPayAPI),将模板(WxPayAPI)添加到服务器上,然后在WxPayAPI项目目录中添加两个“一般处理程序” (改名为GetOp ...

  8. 2017年9月22日 关于JS数组

    JS数组 JS数组的定义方法 var arr = []; var arr = new Array() JS数组属性 长度 arr.length 遍历数组 索引值:从0开始数 第一种方法 for(var ...

  9. Java 匿名内部类 & 内部类

    一.JAVA中内部类和匿名内部类的区别 内部类:内部类可以是static的或者非static的,static内部类只能包含静态方法和静态类变量,只能访问外部类的静态元素,内部类可以实例化,多次使用. ...

  10. [LeetCode]26. Remove Duplicates from Sorted Array删除排序数组中的重复项

    Given a sorted array nums, remove the duplicates in-place such that each element appear only once an ...