http://acm.hdu.edu.cn/showproblem.php?pid=1541 结点更新求最左区间的个数
2010-08-20 17:42
288 查看
/* * 少写一个询问的函数,以为一个更新的函数就够了,结果。。。。 * 就是结点更新求最左区间的个数 */ #include <iostream> #include <cstdio> #include <cstring> #define LL(x) ((x) << 1) #define RR(x) ((x) << 1 | 1) using namespace std; const int N = 32005; struct Seg_tree{ int l, r; int sum; int mid(){ return (l + r) >> 1; } }tree[3 * N]; int pos ; inline void Build(int l, int r, int node){ tree[node].l = l; tree[node].r = r; tree[node].sum = 0; if(l == r) return ; int mid = (l + r) >> 1; Build(l, mid, LL(node)); Build(mid + 1, r, RR(node)); } inline void Update(int node, int dx){ if(tree[node].l == tree[node].r && tree[node].l == dx){ //pos[tree[node].sum]++; tree[node].sum += 1; //printf("dx :: %d tree[node].sum :: %d/n", dx, tree[node].sum); return ; } /* if(tree[node].sum){ tree[LL(node)].sum = tree[RR(node)].sum = tree[node].sum; } */ int mid = tree[node].mid(); if(dx <= mid) Update(LL(node), dx); else Update(RR(node), dx); tree[node].sum += 1; } inline int Query(int l, int r, int node){ if(l <= tree[node].l && tree[node].r <= r){ return tree[node].sum; } int mid = tree[node].mid(); if(r <= mid){ return Query(l , r, LL(node)); } else if(l > mid){ return Query(l, r, RR(node)); } else{ return Query(l, mid, LL(node))+ Query(mid + 1, r, RR(node)); } } int main(){ int n; while(scanf("%d", &n) != EOF){ int x, y; Build(0, 32000, 1); //memset(pos, 0, sizeof(pos)); for(int i = 0 ;i < n; i++) pos[i] = 0; int temp = n; while(temp--){ scanf("%d %d", &x, &y); pos[Query(0, x, 1)]++; Update(1, x); } //puts("==="); for(int i = 0; i < n; i++) printf("%d/n", pos[i]); } }
相关文章推荐
- http://acm.hdu.edu.cn/showproblem.php?pid=1779 线段树 求区间最大值 结点更新
- http://acm.hdu.edu.cn/showproblem.php?pid=2871 更新最左区间
- http://acm.hdu.edu.cn/showproblem.php?pid=1540 更新节点,询问节点所在的位置有多少连续的区间
- http://acm.hdu.edu.cn/showproblem.php?pid=1754 更新节点,区间最值
- http://acm.hdu.edu.cn/showproblem.php?pid=1166 更新节点,区间求和
- 二分查找求函数的区间最小值&&http://acm.hdu.edu.cn/showproblem.php?pid=2899
- http://acm.hdu.edu.cn/showproblem.php?pid=1698 成段更新,总区间求和
- http://acm.hdu.edu.cn/showproblem.php?pid=2795 更新节点构造线段数很关键,询问特殊
- http://acm.hdu.edu.cn/showproblem.php?pid=2795&&线段树之求最小区间端点值
- http://acm.hdu.edu.cn/showproblem.php?pid=3836
- http://acm.hdu.edu.cn/showproblem.php?pid=1039(水~)
- http://acm.hdu.edu.cn/showproblem.php?pid=1333
- Buy the Ticket&&http://acm.hdu.edu.cn/showproblem.php?pid=1133
- http://acm.hdu.edu.cn/showproblem.php?pid=1269
- http://acm.hdu.edu.cn/showproblem.php?pid=1255 扫描线 + 线段树 +离散化
- http://acm.hdu.edu.cn/showproblem.php?pid=1010
- http://acm.hdu.edu.cn/showproblem.php?pid=2602
- N! http://acm.hdu.edu.cn/showproblem.php?pid=1042
- http://acm.hdu.edu.cn/showproblem.php?pid=1040。。。
- http://acm.hdu.edu.cn/showproblem.php?pid=1124 N!末尾0的个数