Skip to content

Commit a9771ef

Browse files
committed
Fixed some indexes to align correctly with testing conventions
1 parent 349374a commit a9771ef

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/data_structures/fenwick.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,12 @@ struct FenwickTree {
127127

128128
FenwickTree(vector<int> const &a) : FenwickTree(a.size()) {
129129
for (size_t i = 1; i <= a.size(); i++)
130-
add(i, a[i-1]);
130+
add(i-1, a[i-1]);
131131
}
132132

133133
int sum(int r) {
134134
int ret = 0;
135-
for (; r > 0; r -= (r & -r))
135+
for (++r; r > 0; r -= (r & -r))
136136
ret += bit[r];
137137
return ret;
138138
}
@@ -142,7 +142,7 @@ struct FenwickTree {
142142
}
143143

144144
void add(int idx, int delta) {
145-
for (; idx <= n; idx += (idx & -idx))
145+
for (++idx; idx <= n; idx += (idx & -idx))
146146
bit[idx] += delta;
147147
}
148148
};
@@ -185,18 +185,18 @@ struct FenwickTreeMin {
185185

186186
FenwickTreeMin(vector<int> a) : FenwickTreeMin(a.size()) {
187187
for (size_t i = 1; i <= a.size(); i++)
188-
update(i, a[i-1]);
188+
update(i-1, a[i-1]);
189189
}
190190

191191
int getmin(int r) {
192192
int ret = INF;
193-
for (; r > 0; r -= (r & -r))
193+
for (++r; r > 0; r -= (r & -r))
194194
ret = min(ret, bit[r]);
195195
return ret;
196196
}
197197

198198
void update(int idx, int val) {
199-
for (; idx <= n; idx += (idx & -idx))
199+
for (++idx; idx <= n; idx += (idx & -idx))
200200
bit[idx] = min(bit[idx], val);
201201
}
202202
};

0 commit comments

Comments
 (0)