# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
706871 | nhuang685 | 원숭이와 사과 나무 (IZhO12_apple) | C++17 | 551 ms | 262144 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const ll DEFID2 = -1;
template <class T, T ID2 = DEFID2>
class Seg {
private:
int sz;
T ID = 0;
T comb(T i, T j) { return i + j; }
struct node {
T val, lazy;
node *l, *r;
node() : val(0), lazy(ID2) { l = r = nullptr; }
node(T _val) : val(0), lazy(_val) { l = r = nullptr; }
};
node *root;
void push(node *n, int l, int r) {
assert(n != nullptr);
if (l != r) {
if (n->l == nullptr) n->l = new node();
if (n->r == nullptr) n->r = new node();
}
if (n->lazy == ID2) return;
n->val = (r - l + 1) * n->lazy;
if (l != r) {
n->l->lazy = n->lazy;
n->r->lazy = n->lazy;
}
n->lazy = ID2;
}
void pull(node *n) { n->val = comb(n->l->val, n->r->val); }
void set(int a, int b, T c, int l, int r, node *n) {
assert(n != nullptr);
push(n, l, r);
if (b < l || r < a) return;
if (a <= l && r <= b) {
n->lazy = c;
push(n, l, r);
return;
}
int mid = (l + r) / 2;
set(a, b, c, l, mid, n->l);
set(a, b, c, mid + 1, r, n->r);
pull(n);
}
T query(int a, int b, int l, int r, node *n) {
assert(n != nullptr);
push(n, l, r);
if (b < l || r < a) return ID;
if (a <= l && r <= b) {
return n->val;
}
int mid = (l + r) / 2;
return comb(query(a, b, l, mid, n->l), query(a, b, mid + 1, r, n->r));
}
public:
Seg() {}
Seg(int _sz) {
for (sz = 1; sz < _sz; sz *= 2)
;
root = new node();
}
~Seg() { delete root; }
void set(int a, int b, T c) { set(a, b, c, 0, sz - 1, root); }
T query(int a, int b) { return query(a, b, 0, sz - 1, root); }
};
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
#ifdef LOCAL
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
Seg<int> seg((ll)1e9 + 1);
int M;
cin >> M;
ll C = 0;
while (M--) {
int D;
ll X, Y;
cin >> D >> X >> Y;
if (D == 1)
cout << (C = seg.query(X + C, Y + C)) << '\n';
else
seg.set(X + C, Y + C, 1);
}
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |