hdu--4947--我太天真了

來源:互聯網
上載者:User

標籤:style   blog   color   os   io   for   div   問題   sp   

這題 我還沒有解決

如果 誰恰好看到這篇 有好的解決方案 不妨底下留言告訴我

-----------------------

我看到時間限制是 5500ms 總覺得肯定能過的

 1 #include <iostream> 2 #include <cstring> 3 using namespace std; 4  5 const int size = 50010; 6 int tree[size]; 7 int lowbit( int x ) 8 { 9     return x & -x;10 }11 12 void update( int x , int val )13 {14     while(x<size)15     {16         tree[x] += val;17         x += lowbit(x);18     }19 }20 21 int getSum( int x )22 {23     int sum = 0;24     while( x )25     {26         sum += tree[x];27         x -= lowbit(x);28     }29     return sum;30 }31 32 int main()33 {34     cin.sync_with_stdio(false);35     int len , m , n , d , v , oper , k = 1;36     while( cin >> len >> m &&(len||m) )37     {38         memset( tree , 0 , sizeof(tree) );39         cout << "Case #" << k++ << ":" << endl;40         while(m--)41         {42             cin >> oper;43             if( oper==1 )44             {45                 cin >> n >> d >> v;// gcd(n,x) = d    tree[x] += v;46                 if( n==d )47                 {48                     for( int i = n ; i<=len ; i+=n )49                     {50                         update( i , v );51                     }52                 }53                 else54                 {55                     update( d , v );56                     for( int i = d ; i<=len ; i+=d )57                     {58                         if( n%i==0 || i%n==0 )59                         {60                             continue;61                         }62                         else63                         {64                             update( i , v );65                         }66                     }67                 }68             }69             else70             {71                 cin >> n; 72                 cout << getSum(n) << endl;73             }74         }75     }76     return 0;77 }

應該時間是主要耗在了  update這裡 不是函數的問題 而是選取哪些數進行Update的時候吧

哎 算了...

 

hdu--4947--我太天真了

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.