题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5517

题意:有二元组(a,b),三元组(c,d,e)。当b == e时它们能构成(a,c,d)然后,当不存在(u,v,w)!=(a,b,c)且u>=a,v>=b,w>=c时,则是一个better集合里的元素。问这个better集合有几个元素。

题解:当 c、d 相同时对于当前 e 只有 a 最大的时候才有可能是 better 集合里的元素,所以记录相同的 b 中 最大的 a 以及它出现的次数,然后可以生成一个新的三元组。将三元组排序并去重之后,从后往前更新二维树状数组即可统计答案。

 #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define mst(a,b) memset((a),(b),sizeof(a))
#define mp(a,b) make_pair(a,b)
#define pi acos(-1)
#define pii pair<int,int>
#define pb push_back
const int INF = 0x3f3f3f3f;
const double eps = 1e-;
const int MAXN = 1e5 + ;
const int MAXM = 1e3 + ; int bx[MAXN],cntb[MAXN]; struct node {
int a,c,d;
ll num;
bool operator == (const node &x) {
if(a == x.a && c == x.c && d == x.d) return true;
return false;
}
}p[MAXN]; bool cmp(node x,node y) {
if(x.a != y.a) return x.a < y.a;
else if(x.c != y.c) return x.c < y.c;
else if(x.d != y.d) return x.d < y.d;
return x.num < y.num;
} int lowbit(int x) {
return x & (-x);
} ll bit[MAXM][MAXM]; void update(int x,int y,ll val) {
for(int i = x; i <= ; i+= lowbit(i))
for(int j = y; j <= ; j += lowbit(j))
bit[i][j] += val;
} ll get(int x,int y) {
ll ans = ;
for(int i = x; i > ; i -= lowbit(i))
for(int j = y; j > ; j -= lowbit(j))
ans += bit[i][j];
return ans;
} ll query(int x1,int y1,int x2,int y2) {
return get(x2,y2) - get(x1 - ,y2) - get(x2, y1 - ) + get(x1 - , y1 - );
} int main() {
#ifdef local
freopen("data.txt", "r", stdin);
#endif
int cas = ;
int t;
scanf("%d", &t);
while(t--) {
mst(bx, );
mst(cntb, );
mst(bit, );
int n,m;
scanf("%d%d",&n,&m);
for(int i = ; i <= n; i++) {
int a,b;
scanf("%d%d",&a,&b);
if(a > bx[b]) bx[b] = a, cntb[b] = ;
else if(a == bx[b]) cntb[b]++;
}
for(int i = ; i <= m; i++) {
int c,d,e;
scanf("%d%d%d",&c,&d,&e);
p[i] = {bx[e],c,d,cntb[e]};
}
sort(p + , p + + m, cmp);
int tot = ;
for(int i = ; i <= m; i++) {
if(!p[i].num) continue;
if(p[i] == p[tot]) p[tot].num += p[i].num;
else p[++tot] = p[i];
}
ll ans = ;
for(int i = tot; i >= ; i--) {
if(!query(p[i].c,p[i].d,,)) ans += p[i].num;
update(p[i].c,p[i].d,p[i].num);
}
printf("Case #%d: %lld\n",cas++,ans);
}
return ;
}

最新文章

  1. Python开发程序:学员管理系统(mysql)
  2. TextVeiw 的 No package identifier when getting value for resource numb
  3. jQuery外链新窗口打开
  4. php报错日志:PHP Deprecated:Automatically populating $HTTP_RAW_POST_DATA is deprecated
  5. zabbix监控nginx
  6. 18)Java八股文名词
  7. Android studio 安装和使用
  8. c++ 中关于int,unsigned int , short的关系与应用
  9. RT: TCP connection close
  10. VS2012 中使用Emacs布局
  11. 【LCA求最近公共祖先+vector构图】Distance Queries
  12. JAVA 练习 找出素数
  13. 社团的CTF逆向题WriteUp
  14. C语言权威指南和书单 - 专家级别
  15. 创建安全客户端Socket
  16. pygame 笔记-1 按键控制方块移动
  17. Python IO内核交互了解
  18. jupyter notebook 在mac OS上的安装
  19. 【转】微信公众号h5网页被嵌入广告 不知道什么原因
  20. Ivan and Burgers CodeForces - 1100F (线性基)

热门文章

  1. springboot+JPA 整合redis
  2. python学习-8 用户有三次机会登陆
  3. python学习-6 猜拳小游戏
  4. ~ android与ios的区别
  5. 牛客 P21336 和与或 (数位dp)
  6. JArray
  7. Apache开启.htaccess 支持
  8. 一个SDL2.0程序的分析
  9. scrapy增量爬取
  10. 启动tomcat提示某个端口被占用