Download benchmarks/Data_structures/binary_indexed_tree/solution.c from PV-SJTU/PV-Bench: direct link, hf CLI and curl.
- Browser
- Download file 303 Bytes
-
https://huggingface.co/datasets/PV-SJTU/PV-Bench/resolve/main/benchmarks/Data_structures/binary_indexed_tree/solution.c
- Command line
-
hf download hf://datasets/PV-SJTU/PV-Bench/benchmarks/Data_structures/binary_indexed_tree/solution.c
-
curl -L -o solution.c https://huggingface.co/datasets/PV-SJTU/PV-Bench/resolve/main/benchmarks/Data_structures/binary_indexed_tree/solution.c
303 Bytes
| int lowbit(int x) | |
| { | |
| return x & (-x); | |
| } | |
| void add(int *bit, int n, int pos, int delta) | |
| { | |
| while (pos <= n) { | |
| bit[pos] += delta; | |
| pos += lowbit(pos); | |
| } | |
| } | |
| int query(int *bit, int pos) | |
| { | |
| int sum = 0; | |
| while (pos > 0) { | |
| sum += bit[pos]; | |
| pos -= lowbit(pos); | |
| } | |
| return sum; | |
| } | |