首页 > 代码库 > hdu 1541 Stars 树状数组

hdu 1541 Stars 树状数组

 不写几个字好奇怪……

 

 1 #include<cstdio> 2 #include<iostream> 3 #include<algorithm> 4 #include<cmath> 5 #include<cstring> 6 #include<string> 7 #include<ctime> 8 #include<map> 9 #include<set>10 #include<vector>11 #include<queue>12 #include<cstdlib>13 #include<cassert>14 #include<sstream>15 #include<stack>16 #include<list>17 #include<bitset>18 #define cl(a,b) memset(a,b,sizeof(a))19 #define debug(x) cerr<<#x<<"=="<<(x)<<endl20 using namespace std;21 typedef long long ll;22 typedef long double ldb;23 typedef pair<int,int> pii;24 25 const int inf=0x3f3f3f3f;26 const int maxn=15000+10;27 const int maxm=32000+10;28 const int mod=1e7+7;29 const double eps=1e-8;30 const double pi=acos(-1);31 32 int dx[8]= {-1,0,1,0,0};33 int dy[8]= {0,1,0,-1,0};34 35 int n,ans[maxn],c[maxm];36 37 int lowbit(int x)38 {39     return x&(-x);40 }41 42 int sum(int x)43 {44     int s=0;45     while(x>0)46     {47         s+=c[x];48         x-=lowbit(x);49     }50     return s;51 }52 53 int add(int x)54 {55     while(x<maxm)56     {57         c[x]++;58         x+=lowbit(x);59     }60 }61 62 63 int main()64 {65     while(~scanf("%d",&n))66     {67         cl(c,0),cl(ans,0);68         for(int i=0;i<n;i++)69         {70             int x,y;71             scanf("%d%d",&x,&y);72             x++;73             ans[sum(x)]++;74             add(x);75         }76         for(int i=0;i<n;i++)77         {78             printf("%d\n",ans[i]);79         }80     }81     return 0;82 }83 84 /*85 86 587 1 188 5 189 7 190 3 391 5 592 93 */

 

hdu 1541 Stars 树状数组