标签:lan clu net class open bsp sum highlight pen
POJ2352 非常裸的树状数组的题。 注意数组下标不能从0开始 因为lowbit(0)==0 所以 所有横坐标统一加1 数组要开的够大 就酱
#include<cstdio> #include<iostream> #include<cstdlib> #include<cstring> #include<cmath> #include<vector> using namespace std; const int maxn=15000,maxx=64000+1; int Tree[maxx],ans[maxn]; inline int lowbit(int x) { return x&(-x); } void add(int x,int value) { for(int i=x;i<=maxx;i+=lowbit(i)) { Tree[i]+=value; } } int get(int x) { int sum=0; for(int i=x;i;i-=lowbit(i)) sum+=Tree[i]; return sum; } int main() {freopen("t.txt","r",stdin); memset(ans,0,sizeof(ans));memset(Tree,0,sizeof(Tree)); int n; scanf("%d",&n); int x,y; for(int i=0;i<n;i++) { scanf("%d%d",&x,&y); x++; ans[get(x)]++; add(x,1); } for(int i=0;i<n;i++) printf("%d\n",ans[i]); return 0; }
标签:lan clu net class open bsp sum highlight pen
原文地址:http://www.cnblogs.com/heisenberg-/p/6511719.html