結果
| 問題 |
No.789 範囲の合計
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-09-02 23:59:59 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 192 ms / 1,000 ms |
| コード長 | 2,951 bytes |
| コンパイル時間 | 3,607 ms |
| コンパイル使用メモリ | 231,876 KB |
| 実行使用メモリ | 34,816 KB |
| 最終ジャッジ日時 | 2024-11-16 06:42:31 |
| 合計ジャッジ時間 | 6,371 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 15 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using pii = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define repr(i, n) for (int i = (int)(n - 1); i >= 0; --i)
namespace baLoon {
struct S {
ll val;
S() : val(0) {}
S(ll val) : val(val){};
S &operator*=(const S &x) {
val += x.val;
return *this;
}
S operator*(const S &x) const {
S ret = *this;
ret *= x;
return ret;
}
};
struct OnlineSegTree {
OnlineSegTree(int lowerbound, int upperbound) : lowerbound(lowerbound), upperbound(upperbound), root(nullptr) {}
void set(int x, const S &val) {
assert(lowerbound <= x && x < upperbound);
set(root, lowerbound, upperbound, x, val);
}
S get(int x) {
assert(lowerbound <= x && x < upperbound);
return get(root, lowerbound, upperbound, x);
}
S prod(int l, int r) {
assert(lowerbound <= l && l <= r && r <= upperbound);
return prod(root, lowerbound, upperbound, l, r);
}
private:
struct node {
node(S val) : val(val), left(nullptr), right(nullptr) {}
S val;
node *left;
node *right;
};
int lowerbound;
int upperbound;
node *root;
void set(node *&v, int a, int b, const int x, const S &val) {
if (!v) v = new node(S());
if (b - a == 1) {
v->val = val;
} else {
int c = (a + b) / 2;
if (x < c) {
set(v->left, a, c, x, val);
} else {
set(v->right, c, b, x, val);
}
v->val = S();
if (v->left) v->val *= v->left->val;
if (v->right) v->val *= v->right->val;
}
}
S get(node *&v, int a, int b, int x) {
if (!v) return S();
if (b - a > 1) {
int c = (a + b) / 2;
if (x < c) {
return get(v->left, a, c, x);
} else {
return get(v->right, c, b, x);
}
}
return v->val;
}
S prod(node *&v, int a, int b, int l, int r) {
if (!v || b <= l || r <= a) return S();
if (l <= a && b <= r) return v->val;
int c = (a + b) / 2;
return prod(v->left, a, c, l, r) * prod(v->right, c, b, l, r);
}
};
} // namespace baLoon
int main() {
baLoon::OnlineSegTree seg(0, 1001001001);
int n;
cin >> n;
baLoon::S ret = baLoon::S();
while (n--) {
int type;
cin >> type;
if (type == 0) {
int x, y;
cin >> x >> y;
seg.set(x, seg.get(x) * baLoon::S(y));
}
if (type == 1) {
int l, r;
cin >> l >> r;
ret *= seg.prod(l, r + 1);
}
}
cout << ret.val << endl;
return 0;
}