# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
890260 | Justin1 | 원숭이와 사과 나무 (IZhO12_apple) | C++17 | 344 ms | 262144 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define f first
#define s second
// #define int long long
using namespace std;
class dynamicSeg { //range max query, range set update
int lzy, val;
int l, r;
dynamicSeg *L = NULL, *R = NULL;
void extend(dynamicSeg *&node, int l, int r) {
if (node == NULL) node = new dynamicSeg(l, r);
}
void push() {
int mid = (l + r) / 2;
extend(L, l, mid), extend(R, mid + 1, r);
if (!lzy) return;
L-> val = L->r - L->l + 1;
R-> val = R->r - R->l + 1;
L-> lzy = R->lzy = !(lzy = 0);
}
public:
dynamicSeg (int sz) : l(1), r(sz) {}
dynamicSeg (int l, int r) : l(l), r(r) {}
void upd(int l, int r) {
push();
if (this->r < l || r < this->l) return;
if (l <= this->l && this->r <= r) {
val = this->r - this->l + 1;
lzy = 1;
return;
}
L->upd(l, r), R->upd(l, r);
val = L->val + R->val;
}
int qry(int l, int r) {
push();
if (this->r < l || r < this->l) return 0;
if (l <= this->l && this->r <= r) return val;
return L->qry(l, r) + R->qry(l, r);
}
};
int n, m, k, x, y, z;
dynamicSeg seg(1'000'000'000);
void solve() {
int C = 0;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> x >> y >> z;
if (x == 1) cout << (C = seg.qry(y + C, z + C)) << "\n";
else seg.upd(y + C, z + C);
}
}
signed main() {
cin.tie(0), cout.tie(0) -> sync_with_stdio(0);
cout << fixed << setprecision(10);
int T = 1;
// cin >> T;
while (T--) {
solve();
}
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |