標籤: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--我太天真了