This documentation is automatically generated by online-judge-tools/verification-helper
View the Project on GitHub ebi-fly13/icpc_library
#define PROBLEM "https://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_2_E" #include "../../template/template.hpp" #include "../../data_structure/dualsegtree.hpp" using namespace lib; int op(int a, int b) { return a + b; } int e() { return 0; } int main() { int n,q; std::cin >> n >> q; dualsegtree<int, op, e> seg(n); while(q--) { int flag; std::cin >> flag; if(flag == 0) { int s,t,x; std::cin >> s >> t >> x; s--; seg.apply(s, t, x); } else { int t; std::cin >> t; t--; std::cout << seg.get(t) << '\n'; } } }
#line 1 "test/data_structure/Range_Add_Point_Get.test.cpp" #define PROBLEM "https://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_2_E" #line 2 "template/template.hpp" #include <bits/stdc++.h> #define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++) #define rrep(i, s, n) for (int i = (int)(n)-1; i >= (int)(s); i--) #define all(v) v.begin(), v.end() using ll = long long; using ld = long double; using ull = unsigned long long; template <typename T> bool chmin(T &a, const T &b) { if (a <= b) return false; a = b; return true; } template <typename T> bool chmax(T &a, const T &b) { if (a >= b) return false; a = b; return true; } namespace lib { using namespace std; } // namespace lib // using namespace lib; #line 2 "data_structure/dualsegtree.hpp" #line 5 "data_structure/dualsegtree.hpp" namespace lib { template <class S, S (*op)(S, S), S (*e)()> struct dualsegtree { public: dualsegtree(int n) : n(n) { sz = 1; while (sz < n) sz <<= 1; data.assign(2 * sz, e()); } dualsegtree(const std::vector<S> &vec) : n(vec.size()) { sz = 1; while (sz < n) sz <<= 1; data.assign(2 * sz, e()); std::copy(vec.begin(), vec.end(), data.begin() + sz); } S get(int p) const { assert(0 <= p && p < n); p += sz; S val = e(); while (p > 0) { val = op(val, data[p]); p >>= 1; } return val; } void apply(int l, int r, S x) { assert(0 <= l && l <= r && r <= n); l += sz; r += sz; while (l < r) { if (l & 1) { data[l] = op(data[l], x); l++; } if (r & 1) { r--; data[r] = op(data[r], x); } l >>= 1; r >>= 1; } return; } private: std::vector<S> data; int n; int sz; }; } // namespace ebi #line 5 "test/data_structure/Range_Add_Point_Get.test.cpp" using namespace lib; int op(int a, int b) { return a + b; } int e() { return 0; } int main() { int n,q; std::cin >> n >> q; dualsegtree<int, op, e> seg(n); while(q--) { int flag; std::cin >> flag; if(flag == 0) { int s,t,x; std::cin >> s >> t >> x; s--; seg.apply(s, t, x); } else { int t; std::cin >> t; t--; std::cout << seg.get(t) << '\n'; } } }