Pagini recente » Cod sursa (job #2490958) | Cod sursa (job #665216) | Cod sursa (job #2456501) | Cod sursa (job #536305) | Cod sursa (job #2975043)
#pragma region BRUH
#ifdef CLI
#include "iostream"
std::istream& in = std::cin;
std::ostream& out = std::cout;
#else
#include "fstream"
std::ifstream ________a ("datorii.in");
std::ofstream ________b ("datorii.out");
std::istream& in = ________a;
std::ostream& out = ________b;
#endif
#pragma endregion
#pragma region FENWICK
#include <vector>
namespace DataStructures {
template < typename T, typename OT >
class Fenwick {
private:
const int size;
std::vector<T> store;
public:
explicit Fenwick(int len) : size(len), store(len + 1, {}) { }
void update(const int position, const T& val) {
for(int i = position; i <= size; i += LSB(i))
store[i] += val;
}
OT query(const int position) const {
OT ans{};
for(int i = position; i > 0; i -= LSB(i))
ans += (OT)store[i];
return ans;
}
OT query(const int left, const int right) const {
return query(right) - query(left);
}
void resetStore() { std::fill(store.begin(), store.end(), {}); }
inline static int LSB(const int i) { return (i & -i); }
void print(std::ostream& out, const char split, const bool newLine = true) const {
for(auto c: store) out << c << split;
if(newLine) out << '\n';
}
void print(std::ostream& out) const { print(out, ' ', true); }
};
} // DataStructures
#pragma endregion
int main() {
int n, m; in >> n >> m;
DataStructures::Fenwick<int, int> fenwick(n);
for(int i = 0, a; i < n; i++) { in >> a; fenwick.update(i + 1, a); }
for(int op, a, b; m; --m) {
in >> op >> a >> b;
if(op == 0) fenwick.update(a, -b);
else out << fenwick.query(--a, b) << '\n';
}
return 0;
}