Skip to content

Commit

Permalink
Fenwick update + test point add range sum
Browse files Browse the repository at this point in the history
  • Loading branch information
adamant-pwn committed Nov 14, 2024
1 parent dc7b822 commit bee5f9d
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cp-algo/structures/fenwick.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace cp_algo::structures {
Container data;

fenwick(auto &&range) {
assign(range);
assign(move(range));
}
void to_prefix_sums() {
for(size_t i = 1; i < n; i++) {
Expand Down
35 changes: 35 additions & 0 deletions verify/structures/fenwick/point_add_range_sum.test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// @brief Point Add Range Sum
#define PROBLEM "https://judge.yosupo.jp/problem/point_add_range_sum"
#pragma GCC optimize("Ofast,unroll-loops")
#include "cp-algo/structures/fenwick.hpp"
#include <bits/stdc++.h>

using namespace std;

void solve() {
int n, q;
cin >> n >> q;
vector<int64_t> a(n + 1);
for(auto &it: a | views::drop(1)) {cin >> it;}
cp_algo::structures::fenwick<int64_t> me(move(a));
for(int i = 0; i < q; i++) {
int t, x, y;
cin >> t >> x >> y;
if(t == 0) {
me.add(x, y);
} else {
cout << me.range_sum(x, y) << '\n';
}
}
}

signed main() {
//freopen("input.txt", "r", stdin);
ios::sync_with_stdio(0);
cin.tie(0);
int t;
t = 1;// cin >> t;
while(t--) {
solve();
}
}

0 comments on commit bee5f9d

Please sign in to comment.