Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- #include <stdlib.h>
- #include <string.h>
- #include <ctype.h>
- #include <bitset>
- #include <iostream>
- #include <stack>
- #include <queue>
- #include <set>
- #include <map>
- #include <string>
- #include <algorithm>
- using namespace std;
- int h(int t) {
- int r = 0;
- while (t % (1 << r) == 0)
- r++;
- return --r;
- }
- int l(int t) {
- return 1 << h(t);
- }
- int n;
- long long int a[100100];
- void solve(int v) {
- int lV = l(v);
- if (lV == 1) return;
- long long int s = 0;
- for(int i = v-lV+1; i < v - 1; ++i) {
- s += a[i];
- }
- a[v-1] = -s;
- }
- int main() {
- //freopen("input.txt", "r", stdin);
- //freopen("output.txt", "w", stdout);
- freopen("fenwick.in", "r", stdin);
- freopen("fenwick.out", "w", stdout);
- scanf("%d", &n);
- for(int i = 1; i <= n; ++i) scanf("%lld", &(a[i]));
- for(int i = 1; i <= n; ++i) {
- solve(i);
- }
- for(int i = 1; i <= n; ++i) {
- printf("%lld ", a[i]);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement