题意:珠宝大盗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. Linux-密码复杂度限制

    前言 设置一个复杂的密码,可以有效的提升系统的安全性.在Linux上有PAM(Pluggable Authentication Modules)里面有一个pam_cracklib.so来控制密码的复杂 ...

  2. Flutter编程:Flutter命令行的学习

    1.创建 Flutter 工程 flutter create <output directory> D:\notebook\flutter\projects\ui_tutorial\lay ...

  3. js动态给textarea赋值

    document.getElementById("new_analysed_news").value=datas.weatherContent;

  4. Ansible 命令相关模块command, shell, raw, expect, script, telnet[转]

    本文主要介绍Ansible的几个命令模块,包括: command - 在远程节点上执行命令 shell - 让远程主机在shell进程下执行命令 script - 将本地script传送到远程主机之后 ...

  5. python 爬虫系列02-小说

    本爬虫为网络上的.. # # -*- coding:UTF-8 -*- # from bs4 import BeautifulSoup # import requests # if __name__ ...

  6. easyUI--datagrid 实现按键控制( enter tab 方向键 )

    1.表格定义时加上 onClickCell: onClickCell,2.定义列时加入编辑器3.引入 key.js 即可使用 enter 键 或者向下箭头 选中单元格下移 选中单元格上移 tab键 选 ...

  7. mongodb常用语句(集合操作)

    mongodb常用语句(集合操作) 查看集合帮助 db.songs.help(); 查看集合总数据量 db.songs.count(); 查看表空间大小 db.songs.dataSize(); 查看 ...

  8. Prestashop使用心得

    如果对Prestashop好奇的小伙伴快点进来看看吧,我开始接触了Prestashop这个开源的系统,这个一个非常棒的电商系统.因为我对这个Prestashop系统完全没有了解,但是上网却看不到太多的 ...

  9. [Modelsim] 仿真的基本操作

    切换路径,建立库并编译所有源文件之后, 键入命令: vopt +acc topmodulename -o top vsim top 其中topmodulename是顶层模块的名称.

  10. 《C#高效编程》读书笔记02-用运行时常量(readonly)而不是编译期常量(const)

    C#有两种类型的常量:编译期常量和运行时常量.两者有截然不同的行为,使用不当的话,会造成性能问题,如果没法确定,则使用慢点,但能保证正确的运行时常量. 运行时常量使用readonly关键字声明,编译期 ...