zoukankan      html  css  js  c++  java
  • hdu--4947--我太天真了

    这题 我还没有解决

    如果 谁恰好看到这篇 有好的解决方案 不妨底下留言告诉我

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

    我看到时间限制是 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                 else
    54                 {
    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                         else
    63                         {
    64                             update( i , v );
    65                         }
    66                     }
    67                 }
    68             }
    69             else
    70             {
    71                 cin >> n; 
    72                 cout << getSum(n) << endl;
    73             }
    74         }
    75     }
    76     return 0;
    77 }

    应该时间是主要耗在了  update这里 不是函数的问题 而是选取哪些数进行Update的时候吧

    哎 算了...

    just follow your heart
  • 相关阅读:
    MySQL联结查询
    MySQL的一些优化方法
    MySQL 基本操作
    一个关于python定制类的例子
    用python类方法处理参数
    python global的用法
    sqli-libs(29(jspstudy)-31关)
    sqli-libs(23-28a关)
    sqli-libs(11-22关)
    sqli-libs(5-10关)
  • 原文地址:https://www.cnblogs.com/radical/p/3954406.html
Copyright © 2011-2022 走看看