# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
971781 | NoLove | 원숭이와 사과 나무 (IZhO12_apple) | C++14 | 86 ms | 65796 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/**
* author : Lăng Trọng Đạt
* created: 29-04-2024
**/
#include <bits/stdc++.h>
using namespace std;
#ifndef LANG_DAT
#define db(...) ;
#endif // LANG_DAT
#define int long long
#define mp make_pair
#define f first
#define se second
#define pb push_back
#define all(v) (v).begin(), (v).end()
using pii = pair<int, int>;
using vi = vector<int>;
#define FOR(i, a, b) for (int (i) = a; (i) <= (b); i++)
void mx(int& a, int b) { if (b > a) a = b; }
void mi(int& a, int b) { if (b < a) a = b; }
#define si(x) (int)(x.size())
const int INF = 1e18;
const int MOD = 1e9 + 7;
struct Data {
int cnt = 0, l = -1, r;
int red = false;
};
vector<Data> st(2);
int n, type, x, y;
void cre(Data& v) {
if (v.l != -1) return;
v.l = si(st);
st.pb(Data());
v.r = si(st);
st.pb(Data());
}
void push(Data& v, int l, int r) {
if (v.red) {
v.cnt = v.red*(r - l + 1);
if (l < r) {
cre(v);
st[v.l].red = v.red;
st[v.r].red = v.red;
}
v.red = false;
}
}
void upd(int v = 1, int l = 1, int r = 1e9) {
if (l > y or x > r) return;
push(st[v], l, r);
if (x <= l && r <= y) {
// db(v, l, r)
st[v].red = true;
} else {
int mid = (l + r) / 2;
cre(st[v]);
upd(st[v].l, l, mid);
upd(st[v].r, mid + 1, r);
push(st[st[v].l], l, mid);
push(st[st[v].r], mid + 1, r);
st[v].cnt = st[st[v].l].cnt + st[st[v].r].cnt;
// if (st[v].cnt > 0)
// db(v, l, r, st[v].cnt)
}
}
int get(int v = 1, int l = 1, int r = 1e9) {
if (l > y or x > r) return 0;
push(st[v], l, r);
// db(st[v].cnt, l, r)
if (x <= l && r <= y) {
return st[v].cnt;
} else {
int mid = (l + r) / 2;
cre(st[v]);
return get(st[v].l, l, mid) +
get(st[v].r, mid + 1, r);
}
}
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);
}
cin >> n;
st.reserve(20*n);
int c = 0;
FOR(i, 1, n) {
cin >> type >> x >> y;
// db(i, si(st), x, y)
x += c; y += c;
if (type == 2) upd();
else {
c = get();
cout << c << "\n";
}
}
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |