题意:珠宝大盗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. C++ GUI Qt4编程(11)-5.1hexSpinbox

    1. hexspinbox.cpp /* * The spin box supports integer values but can be extended to use different str ...

  2. firewall-cmd --reload 防火墙

    防火墙重新加载配置firewall-cmd --reload 查看开放的端口 firewall-cmd --list-ports nano /etc/sysconfig/iptables -A IN_ ...

  3. Tortoise SVN 快速操作手册

    1.库的存储结构 版本库文件结构如图所示: Code文件夹为源码文件夹,doc为文档目录文件夹, 1.1 branch:分枝文件夹 当多个人合作,可能有这样的情况出现:John突然有个想法,跟原先的设 ...

  4. oracle客户端中文乱码问题的解决

    1 查看服务器端编码 select userenv('language') from dual; 我实际查看到的结果为: USERENV('LANGUAGE') ------------------- ...

  5. sourceTree免登陆

    https://www.cnblogs.com/dereckbu/articles/7659674.html

  6. 委托delegate 泛型委托action<> 返回值泛型委托Func<> 匿名方法 lambda表达式 的理解

    1.使用简单委托 namespace 简单委托 { class Program { //委托方法签名 delegate void MyBookDel(int a); //定义委托 static MyB ...

  7. Hashtable和HashMap的区别,Properties类的简单使用

    一.Java Properties类 Java中有个比较重要的类Properties(Java.util.Properties),主要用于读取Java的配置文件,各种语言都有自己所支持的配置文件,配置 ...

  8. 上下文(Context)和作用域(Scope)

    函数的每次调用都有与之紧密相关的作用域和上下文.从根本上来说,作用域是基于函数的,而上下文是基于对象的. 换句话说,作用域涉及到所被调用函数中的变量访问,并且不同的调用场景是不一样的.上下文始终是th ...

  9. CheckBox 样式

    .cb td {             width: 100px;         } .cb label {             display: inline-block;          ...

  10. 希尔排序——Java实现

    一.排序思想 希尔排序(Shell’s Sort)是插入排序的一种,是直接插入排序算法的一种更高版本的改进版本. 把记录按步长gap分组,对每组记录采用直接插入排序方法进行排序: 随着步长逐渐减小,所 ...