# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
870638 | NoLove | 원숭이와 사과 나무 (IZhO12_apple) | C++14 | 0 ms | 500 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/**
* author : Lăng Trọng Đạt
* created: 08-11-2023
**/
#include <bits/stdc++.h>
using namespace std;
#ifndef LANG_DAT
#define db(...) ;
#endif // LANG_DAT
#define int int64_t
#define mp make_pair
#define f first
#define s second
#define pb push_back
#define all(v) (v).begin(), (v).end()
using pii = pair<int, int>;
const int MAXN = 2e5 + 5;
struct Node {
int val, lazy;
int lc, rc; // left child, right child
int lb, rb; // left border, right border
} st[MAXN];
ostream& operator<<(ostream& os, Node& v) {
os << "[" << v.val << " " << v.lb << " " << v.rb << "]";
}
int q, type, l, r;
int id = 2;
void extend(int v) {
if (!st[v].lc) {
int mid = (st[v].lb + st[v].rb) / 2;
st[id].lb = st[v].lb;
st[id].rb = mid;
st[v].lc = id++;
st[id].lb = mid + 1;
st[id].rb = st[v].rb;
st[v].rc = id++;
}
}
void push(int v) {
if (st[v].lazy) {
if (st[v].lb < st[v].rb) {
extend(v);
st[st[v].lc].lazy = st[st[v].rc].lazy = 1;
}
st[v].val = st[v].rb - st[v].lb + 1;
// db(st[v])
st[v].lazy = 0;
}
}
void upd(int v = 1) {
push(v);
if (st[v].lb > r or l > st[v].rb) return;
else if (l <= st[v].lb && st[v].rb <= r) {
st[v].lazy = 1;
} else {
int mid = (st[v].lb + st[v].rb) / 2;
extend(v);
upd(st[v].lc); upd(st[v].rc);
push(st[v].lc); push(st[v].rc);
st[v].val = st[st[v].lc].val + st[st[v].rc].val;
}
}
int get(int v = 1) {
push(v);
if (st[v].lb > r or l > st[v].rb) return 0;
else if (l <= st[v].lb && st[v].rb <= r) {
// db(v, st[v])
return st[v].val;
} else {
int mid = (st[v].lb + st[v].rb) / 2;
extend(v);
return get(st[v].lc) + get(st[v].rc);
}
}
int32_t main() {
cin.tie(0)->sync_with_stdio(0);
if (fopen("hi.inp", "r")) {
freopen("hi.inp", "r", stdin);
// freopen("hi.out", "w", stdout);
}
st[1].lb = 1; st[1].rb = 1e9;
cin >> q;
int c = 0;
while (cin >> type >> l >> r) {
// db(l, r)
l += c; r += c;
if (type == 2) {
upd();
} else {
int tmp = get();
cout << tmp << "\n";
c += tmp;
}
}
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |