标签:style blog color os io for div amp
第一题树状数组 模板题
#include <cstdio> #include <iostream> using namespace std; int c[32002],lv[15002],n; int lowbit(int x){return x&(-x);} int sum(int b){ int sum=0; while(b>0){ sum+=c[b]; b-=lowbit(b); } return sum; } void add(int x){ while(x<=32002){ ++c[x]; x+=lowbit(x); } } int main(){ int x,y; while(scanf("%d",&n)!=EOF){ for(int i=0;i<n;i++){ scanf("%d%d",&x,&y); ++x; //x=0时会进入死循环,所以要+1; ++lv[sum(x)]; add(x); } for(int i=0;i<n;i++){ printf("%d\n",lv[i]); } } return 0; }
标签:style blog color os io for div amp
原文地址:http://www.cnblogs.com/Mr-Xu-JH/p/3896042.html