#line 1 "test/yuki/No-789.test.cpp" #define PROBLEM "https://yukicoder.me/problems/no/789" #line 2 "src/template.hpp" #include using namespace std; #define rep(i, N) for(int i=0;i<(N);i++) #define all(x) (x).begin(),(x).end() #define popcount(x) __builtin_popcount(x) using i128=__int128_t; using ll = long long; using ld = long double; using graph = vector>; using P = pair; constexpr int inf = 1e9; constexpr ll infl = 1e18; constexpr ld eps = 1e-6; const long double pi = acos(-1); constexpr uint64_t MOD = 1e9 + 7; constexpr uint64_t MOD2 = 998244353; constexpr int dx[] = { 1,0,-1,0 }; constexpr int dy[] = { 0,1,0,-1 }; templateinline void chmax(T&x,T y){if(xinline void chmin(T&x,T y){if(x>y)x=y;} #line 1 "src/data-structure/BIT.hpp" /// @brief Binary Index Tree /// @tparam Type 要素の型 /// @tparam SumType "和が" 収まるような型 /// @docs docs/data-structure/BIT.md template class BIT { int _n; vector _dat; public: explicit BIT(int _n) : _n(_n), _dat(_n, SumType()) {} inline void add(int p, Type v) { p++; for (; p <= _n; p += p & (-p)) { _dat[p - 1] += SumType(v); } } inline SumType sum(int p) { SumType res = 0; for (; p > 0; p -= p & -p) { res += _dat[p - 1]; } return res; } inline SumType sum(int l, int r) { return sum(r) - sum(l); } }; #line 5 "test/yuki/No-789.test.cpp" int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; ll s = 0; vector idx; idx.reserve(2 * n); vector> query(n); for (auto& [t, a, b] : query) { cin >> t >> a >> b; idx.emplace_back(a); if (t == 1) idx.emplace_back(b); } sort(all(idx)); idx.erase(unique(all(idx)), idx.end()); BIT sg(n + 1); for (auto& [t, a, b] : query) { if (t == 0) { a = lower_bound(all(idx), a) - idx.begin(); sg.add(a, b); } else { a = lower_bound(all(idx), a) - idx.begin(); b = lower_bound(all(idx), b) - idx.begin(); s += sg.sum(a, b + 1); } } cout << s << '\n'; }