题意:珠宝大盗Arsen Lupin偷珠宝。在展厅内,每颗珠宝有个一个坐标为(xi,yi)和颜色ci。

Arsen Lupin发明了一种设备,可以抓取平行x轴的一条线段下的所有珠宝而不触发警报,

唯一的限制是抓取的珠宝不能不能有所有的m种颜色。询问能抓取的最大珠宝数量。

分析:要决策的东西有两个,一是这条线段的y坐标,二是线段的x的范围。

枚举线段的y坐标,线段宽度要保证下方不能有所有的颜色,这需要知道颜色的关于x的坐标信息,

为了x的坐标信息的重复利用,从小到大枚举y。

对于一个固定的yi,怎么找到合适的区间呢?一个简单且正确的想法是枚举不要的颜色,

对于每种不要的颜色,只要选择不包含这种颜色的区间就可以保证符号要求了。

但是这样做太慢了,枚举颜色是O(n)的。

幸运的是,这里面有大量的重复计算,在枚举yi-1的时候,有很多的区间是不会变的,已经计算过的了,

只要枚举发生了改变的区间。

关于颜色的区间信息可以用set保存,在枚举的区间合法的情况下只是一个区间询问单点更新可用BIT,下标范围需要离散。

  1. /*********************************************************
  2. * ---------------------------- *
  3. * author AbyssalFish *
  4. **********************************************************/
  5. #include<bits/stdc++.h>
  6. using namespace std;
  7.  
  8. typedef long long ll;
  9.  
  10. const int maxn = 2e5+;
  11.  
  12. set<int> S[maxn];
  13.  
  14. int x[maxn],y[maxn],c[maxn];
  15. int r[maxn], xs[maxn];
  16.  
  17. int *cmp_c;
  18. bool cmp_id(int i,int j){ return cmp_c[i] < cmp_c[j]; }
  19.  
  20. int C[maxn];
  21. int ns;
  22.  
  23. void add(int x)
  24. {
  25. while(x <= ns){
  26. C[x]++; x += x&-x;
  27. }
  28. }
  29.  
  30. int sum(int x)
  31. {
  32. int re = ;
  33. while(x > ){
  34. re += C[x]; x &= x-;
  35. }
  36. return re;
  37. }
  38.  
  39. void solve()
  40. {
  41. int n, m, i, j, k;
  42. scanf("%d%d",&n,&m);
  43. for(i = ; i < n; i++) {
  44. scanf("%d%d%d",x+i,y+i,c+i);
  45. r[i] = i;
  46. }
  47.  
  48. cmp_c = x;
  49. sort(r,r+n,cmp_id);
  50. ns = ;
  51. xs[r[]] = ns;
  52. for(i = ; i < n; i++){
  53. xs[r[i]] = (x[r[i]] == x[r[i-]]) ? ns:++ns;
  54. }
  55.  
  56. for(i = ; i <= m; i++){
  57. S[i].clear();
  58. S[i].insert();
  59. S[i].insert(ns+);
  60. }
  61.  
  62. cmp_c = y;
  63. for(i = ; i < n; i++) r[i] = i;
  64. sort(r,r+n,cmp_id);
  65.  
  66. memset(C+,,sizeof(int)*ns);
  67.  
  68. int ans = , p, q, cur_y;
  69. for(i = ; i < n; i = k){
  70. cur_y = y[r[i]];
  71. for(j = i; j < n && y[k = r[j]] == cur_y; j++){
  72. auto it = S[c[k]].lower_bound(xs[k]);
  73. p = *it-;
  74. q = *--it;
  75. if(p > q)
  76. ans = max(ans,sum(p)-sum(q));
  77. }
  78. k = j;
  79. while(--j >= i){
  80. p = r[j];
  81. S[c[p]].insert(xs[p]);
  82. add(xs[p]);
  83. }
  84. }
  85. for(i = ; i <= m; i++){
  86. auto it = S[i].begin();
  87. q = ;
  88. for(it++; it != S[i].end(); it++){
  89. p = *it-;
  90. if(p > q) ans = max(ans, sum(p) - sum(q));
  91. q = *it;
  92. }
  93. }
  94. printf("%d\n", ans);
  95. }
  96.  
  97. //#define LOCAL
  98. int main()
  99. {
  100. #ifdef LOCAL
  101. freopen("in.txt","r",stdin);
  102. #endif
  103. int T; scanf("%d",&T);
  104. while(T--) solve();
  105. return ;
  106. }

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. nginx 地址重写

    例如, www.baidu.com    跳到   www.baidu.com/index.html #if ( $http_host ~* "^(.*)\.baidu\.com$" ...

  2. cas aqs lock之间的关系

    CAS 对应cpu的硬件指令, 是最原始的原子操作 cas主要是在AtomicInteger AtomicXXX类中使用, 用于实现线程安全的自增操作 ++. 对应一个unsafe对象, 根据os平台 ...

  3. rsync 参数配置说明[转]

    rsync 特性 可以镜像保存整个目录树和文件系统. 可以很容易做到保持原来文件的权限.时间.软硬链接等等. 无须特殊权限即可安装. 快速:第一次同步时 rsync 会复制全部内容,但在下一次只传输修 ...

  4. 用PHP实现同一个帐号不允许同时登陆,只允许一个帐号登录?

    数据库表 user_login_info 字段:id,user_ip,user_id,last_access_time user_id 做唯一性索引 1. 用户登录后 如果没有当前用户的数据,插入一条 ...

  5. <div>里用display:block有用么?

    对所有的块元素都没有意义,块元素的dispaly属性默认值为block,没必要再显式定义--除非你之前对块元素的display属性重新定义过. =========================== ...

  6. JS常用的设计模式(2)——简单工厂模式

    简单工厂模式是由一个方法来决定到底要创建哪个类的实例, 而这些实例经常都拥有相同的接口. 这种模式主要用在所实例化的类型在编译期并不能确定, 而是在执行期决定的情况. 说的通俗点,就像公司茶水间的饮料 ...

  7. WAMP环境配置-Mysql安装

    1.下载并解压MySQL5.6.36压缩包(顺便重命名一下子). 2.将my-default.ini文件复制一份改名为my.ini,然后修改下面红框标注的地方 3.安装与启动服务. 以管理员的身份运行 ...

  8. 两个三汇API使用的坑

    最近呼叫中心走火入魔了,我的<一步一步开发呼叫中心>系列编写过程中,遇到各种的问题,今天晚上,来记录一下纠结了我N久的一个问题: 内线通过板卡外呼时,如果对方的呼叫中心需要发送按键响应(如 ...

  9. linux安装lua_nginx_module模块

    ngx_lua_module 是一个nginx http模块,它把 lua 解析器内嵌到 nginx,用来解析并执行lua 语言编写的网页后台脚本,可以用来实现灰度发布.另外淘宝的OpenResty也 ...

  10. mvc中RedirectToAction()如何传参?

    今天在做一个功能的时,使用RedirectToAction()需要从这里传几个参数,从网上查了一下,这样解决.真好. Return RedirectToAction("Index" ...