結果

問題 No.789 範囲の合計
ユーザー AC2KAC2K
提出日時 2023-03-27 20:18:43
言語 C++23(draft)
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,312 bytes
コンパイル時間 4,024 ms
コンパイル使用メモリ 258,412 KB
実行使用メモリ 5,860 KB
最終ジャッジ日時 2023-10-19 19:10:24
合計ジャッジ時間 5,715 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
4,348 KB
testcase_02 WA -
testcase_03 AC 41 ms
5,824 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 34 ms
5,560 KB
testcase_08 AC 45 ms
5,560 KB
testcase_09 AC 43 ms
5,824 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#line 1 "test/yuki/No-789.test.cpp"
#define PROBLEM "https://yukicoder.me/problems/no/789"

#line 2 "src/template.hpp"
#include<bits/stdc++.h>
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<vector<int>>;
using P = pair<int, int>;
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 };
template<class T>inline void chmax(T&x,T y){if(x<y)x=y;}
template<class T>inline 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 <typename Type, typename SumType = Type>
class BIT {
    int _n;
    vector<SumType> _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<int> idx;
    idx.reserve(2 * n);
    vector<tuple<int, int, int>> 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<ll> 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';
}
0