标签:turn log nbsp 包括 ash std 抽屉原理 read iostream
1 #include<iostream> 2 #include<cstring> 3 using namespace std; 4 const int maxn=50005; 5 int n,a[maxn],Hash[maxn],l,r; 6 class Tree{ 7 private: 8 int c[maxn],n; 9 public: 10 Tree(int _n){this->n=_n;memset(c,0,sizeof(c));} 11 void add(int k,int num){ 12 while(k<=this->n){ 13 c[k]=(c[k]+num)%n; 14 k+=k&-k; 15 } 16 } 17 int read(int k){ 18 int sum=0; 19 while(k){ 20 sum=(sum+c[k])%n; 21 k-=k&-k; 22 } 23 return sum; 24 } 25 }; 26 int main(){ 27 cin>>n; 28 Tree t(n); 29 memset(Hash,0,sizeof(Hash)); 30 for(int i=1;i<=n;i++){ 31 cin>>a[i]; 32 t.add(i,a[i]%n); 33 } 34 for(int i=1;i<=n;i++){ 35 int k=t.read(i); 36 if(k==0){ 37 l=1;r=i;break; 38 } 39 else if(Hash[k]){ 40 l=Hash[k]+1;r=i;break; 41 }else{ 42 Hash[k]=i; 43 } 44 } 45 cout<<r-l+1<<endl; 46 for(int i=l;i<=r;i++){ 47 cout<<a[i]<<endl; 48 } 49 return 0; 50 }
标签:turn log nbsp 包括 ash std 抽屉原理 read iostream
原文地址:http://www.cnblogs.com/7391-KID/p/6877843.html