po167_library

This documentation is automatically generated by online-judge-tools/verification-helper

View the Project on GitHub potato167/po167_library

:warning: test/ds/segtree.cpp

Depends on

Code

#define PROBLEM "https://judge.yosupo.jp/problem/point_add_range_sum"

#include "../../ds/Segtree.hpp"
#include <iostream>
using ll = long long;
ll op(ll a, ll b){
    return a + b;
}
ll e(){
    return 0ll;
}

int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    
    int N, Q;
    std::cin >> N >> Q;
    std::vector<ll> A(N);
    for (auto &a : A) std::cin >> a;
    po167::segtree<ll, op, e> seg(A);
    while (Q--){
        int t, a, b;
        std::cin >> t >> a >> b;
        if (t == 0){
            seg.updl(a, b);
        }
        else{
            std::cout << seg.prod(a, b) << "\n";
        }
    }
}
#line 1 "test/ds/segtree.cpp"
#define PROBLEM "https://judge.yosupo.jp/problem/point_add_range_sum"

#line 2 "ds/Segtree.hpp"
#include <atcoder/segtree>

namespace po167{
template <class S, S (*op)(S, S), S (*e)()>
struct segtree : atcoder::segtree<S, op, e> {
    using atcoder::segtree<S, op, e>::segtree;
    void updr(int ind, S x) {
        this->set(ind, op(this->get(ind), x));
    }
    void updl(int ind, S x) {
        this->set(ind, op(x, this->get(ind)));
    }
};
}
#line 4 "test/ds/segtree.cpp"
#include <iostream>
using ll = long long;
ll op(ll a, ll b){
    return a + b;
}
ll e(){
    return 0ll;
}

int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    
    int N, Q;
    std::cin >> N >> Q;
    std::vector<ll> A(N);
    for (auto &a : A) std::cin >> a;
    po167::segtree<ll, op, e> seg(A);
    while (Q--){
        int t, a, b;
        std::cin >> t >> a >> b;
        if (t == 0){
            seg.updl(a, b);
        }
        else{
            std::cout << seg.prod(a, b) << "\n";
        }
    }
}
Back to top page