标签:忘记 void inpu 输入 ted end contest ssi 接下来
Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 22122 Accepted Submission(s): 10715
#include<stdio.h> #include<string.h> #include<algorithm> #include<iostream> #define ls (u<<1) #define rs (u<<1|1) using namespace std; int ans[1000000],n; struct node{ int l,r,n; } node[1000000]; void build(int u,int l,int r){ node[u].l = l; node[u].r = r; node[u].n = 0; if(l!=r){ int mid = (l+r)>>1; build(ls,l,mid); build(rs,mid+1,r); } } void update(int u,int x,int y){ if(node[u].l == x && node[u].r == y)//找到要刷的气球区间,更新其被刷的次数+1 node[u].n++; else{ int mid = (node[u].l+node[u].r)>>1; if(y<=mid) update(ls,x,y); else if(x>mid) update(rs,x,y); else{ update(ls,x,mid); update(rs,mid+1,y); } } } void query(int u){ for(int i = node[u].l; i<=node[u].r; i++)//该区间所有编号都被刷了一次 ans[i]+=node[u].n;//求单结点 if(node[u].l == node[u].r) return; query(ls); query(rs); } int main(){ int x,y; while(cin >> n,n){ build(1,1,n); for(int i = 1; i<=n; i++){ cin >> x >> y; update(1,x,y); } memset(ans,0,sizeof(ans)); query(1); cout << ans[1]; for(int i = 2; i<=n; i++) cout << " " << ans[i]; cout << endl; } return 0; }
线段树(求单结点) hdu 1556 Color the ball
标签:忘记 void inpu 输入 ted end contest ssi 接下来
原文地址:http://www.cnblogs.com/l609929321/p/7277023.html