-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfenwickTree.cpp
More file actions
68 lines (55 loc) · 2.41 KB
/
Copy pathfenwickTree.cpp
File metadata and controls
68 lines (55 loc) · 2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
- Science is knowledge which we understand so well
that we can teach it to a computer; and if we don’t
fully understand something, it is an art to deal with it.
- El trabajo duro supera al talento cuando el talento no trabaja duro.
- Los desafios son los que hacen la vida interesante y superarlos es
lo que hace a la vida significativa.
- Para sentirse vivo se necesita una meta en la que trabajar.
*/
typedef long long ll;
#define srt(a) sort((a).begin(),(a).end());
#define srtR(a) sort((a).rbegin(),(a).rend());
#include <bits/stdc++.h>
using namespace std;
struct BIT { // 1-indexed, your first element of the array is at index 1
vector<ll> bit;
ll n;
BIT(int n) : bit(n+1), n(n) {}
ll lsb(int i) { return i & -i; } // least significant bit
void add(int i, ll x) {
for (; i <= n; i += lsb(i)) bit[i] += x;
}
ll sum(int r) {
ll res = 0;
for (; r > 0; r -= lsb(r)) res += bit[r];
return res;
}
ll sum(int l, int r) {
return sum(r) - sum(l-1);
}
void set(int i, ll x) {
add(i, x - sum(i, i));
}
};
signed main (){
ios::sync_with_stdio(false);cin.tie(0);
return 0;
}
// :-==-. .:..
// .+%@@@@@@#- -*%@@@@#+.
// .%@@@@@@@@@@%*=--:.....::--+#@@@@@@@@@@@=
// +@@@@@@@%*-. .-*%@@@@@@@%
// +@@@@@%=. .=%@@@@@@.
// -@@@@*. .+@@@@%
// +@@+ .. =@@%:
// -* :*%@@@*. :+#%#+. +#:
// =. =@@@*=+@% :%@##@@@+ .+
// + -@@@@. #@: :----- *@= +@@@+ +
// .+ #@@@@#+*@%. *@@@@%. +@#:-#@@@@: =.
// .= @@@@@@@@+ .=*: :@@@@@@@@= -:
// + :**%@%*: .-=+-- :#@@%**+ +
// +.---:. .----- .=
// := +.
// :=-. .-=:
// .:-----------:.