ACM-ICPC 2015 沈阳赛区现场赛 I. Triple && HDU 5517(二维BIT)
2024-08-31 14:56:54
题目链接: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 ;
}
最新文章
- Python开发程序:学员管理系统(mysql)
- TextVeiw 的 No package identifier when getting value for resource numb
- jQuery外链新窗口打开
- php报错日志:PHP Deprecated:Automatically populating $HTTP_RAW_POST_DATA is deprecated
- zabbix监控nginx
- 18)Java八股文名词
- Android studio 安装和使用
- c++ 中关于int,unsigned int , short的关系与应用
- RT: TCP connection close
- VS2012 中使用Emacs布局
- 【LCA求最近公共祖先+vector构图】Distance Queries
- JAVA 练习 找出素数
- 社团的CTF逆向题WriteUp
- C语言权威指南和书单 - 专家级别
- 创建安全客户端Socket
- pygame 笔记-1 按键控制方块移动
- Python IO内核交互了解
- jupyter notebook 在mac OS上的安装
- 【转】微信公众号h5网页被嵌入广告 不知道什么原因
- Ivan and Burgers CodeForces - 1100F (线性基)