HDU 5517 Triple (2015沈阳站I题&&二维树状数组)
来源:互联网 发布:js如何获取list中的值 编辑:程序博客网 时间:2024/05/15 23:49
题意:给一个
设所有的二元组,三元组组合后得到的新的三元组的集合是
求
分析:学习的这里的做法
首先,对于二元组,相同的
扫一遍所有的三元组:二位线段树维护
代码:
#include <bits/stdc++.h>#define LL long long#define FOR(i,x,y) for(int i = x;i < y;++ i)#define IFOR(i,x,y) for(int i = x;i > y;-- i)using namespace std;typedef vector <int> VT;const int maxn = 100010;const int maxm = 1010;int b[maxn],cnt_b[maxn];struct Point{ int a,c,d; int cnt; Point() {} Point(int x,int y,int z,int k): a(x),c(y),d(z),cnt(k) {} bool operator < (const Point& rhs) const{ if(a == rhs.a){ if(c == rhs.c) return d > rhs.d; return c > rhs.c; } return a > rhs.a; } bool operator == (const Point& rhs) const{ if(a == rhs.a && c == rhs.c && d == rhs.d) return true; return false; }}point[maxn],pp[maxn];int n,m;void init(){ scanf("%d%d",&n,&m); FOR(i,0,maxn) b[i] = cnt_b[i] = 0; int x,y,z; FOR(i,0,n){ scanf("%d%d",&x,&y); if(b[y] == x) cnt_b[y] ++; else if(b[y] < x) {b[y] = x; cnt_b[y] = 1;} } n = 0; FOR(i,0,m){ scanf("%d%d%d",&x,&y,&z); if(b[z]){ pp[++n] = Point(b[z],x,y,cnt_b[z]); } } sort(pp+1,pp+n+1); int len = 0; point[++len] = pp[1]; FOR(i,2,n+1){ if(point[len] == pp[i]){ point[len].cnt += pp[i].cnt; } else{ point[++len] = pp[i]; } } n = len;}int tree[maxm][maxm];int lowbit(int x) {return x & (-x);}void Modify(int x,int y,int val){ int rt_x = x,rt_y = y; for(rt_x = x;rt_x < maxm;rt_x += lowbit(rt_x)){ for(rt_y = y;rt_y < maxm;rt_y += lowbit(rt_y)){ tree[rt_x][rt_y] += val; } }}int query(int x,int y){ int res = 0; int rt_x,rt_y; for(rt_x = x;rt_x;rt_x -= lowbit(rt_x)){ for(rt_y = y;rt_y ;rt_y -= lowbit(rt_y)){ res += tree[rt_x][rt_y]; } } return res;}void work(){ FOR(i,0,maxm) FOR(j,0,maxm) tree[i][j] = 0; int ans = 0; FOR(i,1,n+1){ if(!query(1001-point[i].c,1001-point[i].d)){ ans += point[i].cnt; } Modify(1001-point[i].c,1001-point[i].d,1); } printf("%d\n",ans);}int main(){ //freopen("test.in","r",stdin); int T,tCase = 0; scanf("%d",&T); while(T--){ printf("Case #%d: ",++tCase); init(); work(); } return 0;}
0 0
- HDU 5517 Triple (2015沈阳站I题&&二维树状数组)
- [HDU 5517][2015ACM/ICPC亚洲区沈阳站] Triple 二维树状数组
- hdu 5517 Triple(二维树状数组)
- HDU 5517 (ACM 2015 沈阳) Triple [树状数组]
- hdu 5517 Triple 二维树状数组
- 2015ACM/ICPC亚洲区沈阳站 HDU 5517 Triple (二维线段树)
- HDU 5517 Triple ACM/ICPC 2015 Shenyang(二维树状数组)
- HDU 5517 2015沈阳现场赛(二维树状数组)
- HDU 5517 Triple(去重+线段树|二维树状数组)
- HDU 5517 Triple (枚举+二维树状数组解决三维点数)
- hdu 5892 沈阳网络赛 二维树状数组+状态压缩
- 【hdu 5517】【2015ACM/ICPC亚洲区沈阳站】Triple 题意&题解&代码(C++)
- hdu 5517(二维树状数组)
- HDU 5517 二维树状数组
- HDU 5517 (二维树状数组)
- HDU 5517 二维树状数组
- HDU5517 沈阳现场赛 二维树状数组
- HDU 2642 Stars(二维树状数组 模板题)
- 编程珠玑——取样总结
- 用户需求、功能需求与业务需求的区别
- Tomcat热部署的三种方式
- Lucene学习总结
- LeetCode Two Sum
- HDU 5517 Triple (2015沈阳站I题&&二维树状数组)
- lua 模式匹配
- C++ 用libcurl库进行http 网络通讯编程
- 毕设第二周(GraphX环境搭建 GraphX API 以及对Pregel的熟悉)
- iOS中Bitcode的介绍及配置
- 灰度图直方图均衡化(matlab练习程序)
- 重启网站
- STM32中SYSTICK定时器、端口复用和重映射
- 最好用的pe系统