CodeForces 178A3

同时也是 LETTers 2015 Summer II warm-up - B

#include <cstdio>
#include <iostream>

using namespace std;

typedef long long LL;

const int N = 1e5 + 10;

LL rec;

LL a[N], l[20];

int main()
{
    int n;

    //freopen("B.in", "r", stdin);
    scanf("%d", &n);
    for (int i = 1; i <= n; i++)
    {
        scanf("%d", &a[i]);
    }

    for (int i = 0; i < 20; i++)
    {
        l[i] = 1 << i;
    }

    for (int i = 1; i <= 100000; i++)
    {
        for (int j = 19; j >= 0; j--)
        {
            if (i + l[j] <= n)
            {
                a[i+l[j]] += a[i];
                break;
            }
        }
    }

    rec = 0;
    for (int i = 1; i < n; i++)
    {
        rec += a[i];
        printf("%lld\n", rec);
    }

    return 0;
}
添加新评论