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的时候吧

哎 算了...

 

转载于:https://www.cnblogs.com/radical/p/3954406.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值