# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1117914 | gdragon | 원숭이와 사과 나무 (IZhO12_apple) | C++17 | 288 ms | 87032 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define TASK "long"
#define fi first
#define se second
#define ll long long
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define GETBIT(mask, i) ((mask) >> (i) & 1)
#define MASK(i) ((1LL) << (i))
#define SZ(x) ((int)(x).size())
#define mp make_pair
#define CNTBIT(mask) __builtin_popcount(mask)
template<class X, class Y> bool maximize(X &x, Y y){ if (x < y) {x = y; return true;} return false;};
template<class X, class Y> bool minimize(X &x, Y y){ if (x > y) {x = y; return true;} return false;};
typedef pair<int, int> ii;
const int N = 1e5 + 5;
const int INF = 1e9 + 7;
const int mod = 1e9 + 7;
struct Node {
int lz = 0;
long long val = 0;
Node* left = NULL, *right = NULL;
} *root;
int q;
void read() {
cin >> q;
}
void update(Node* &head, int l, int r, int u, int v, int lz) {
if (u > r || v < l) return;
if (head == NULL) head = new Node();
if (u <= l && r <= v) {
// cout << "UPD: " << l << ' ' << r << ' ' << r - l + 1 << endl;
head->lz = 1;
head->val = r - l + 1;
return;
}
// cerr << "RUN: " << l << ' ' << r << ' ' << u << ' ' << v << endl;
int mid = (l + r) >> 1;
lz |= head->lz;
if (v <= mid) update(head->left, l, mid, u, v, lz);
else if (u > mid) update(head->right, mid + 1, r, u, v, lz);
else {
update(head->left, l, mid, u, v, lz);
update(head->right, mid + 1, r, u, v, lz);
}
head->val = (head->left != NULL ? head->left->val : 0) +
(head->right != NULL ? head->right->val : 0);
if (lz) {
head->val = r - l + 1;
head->lz = 1;
}
// cout << l << ' ' << r << ' ' << head->val << endl;
}
long long getSum(Node* &head, int l, int r, int u, int v, int lz) {
if (u > r || v < l) return 0;
if (head == NULL) {
if (lz) {
// if (u == 8 && v == 11) cerr << l << ' ' << r << ' ' << min(v, r) - max(u, l) + 1 << endl;
return min(v, r) - max(u, l) + 1;
}
return 0;
}
lz |= head->lz;
if (lz) head->val = r - l + 1;
// cerr << l << ' ' << r << ' ' << u << ' ' << v << endl;
if (u <= l && r <= v) {
// if (u == 8 && v == 11) cerr << l << ' ' << r << ' ' << lz << ' ' << head->val << endl;
// cout << l << ' ' << r << ' ' << head->val << endl;
return head->val;
}
int mid = (l + r) >> 1;
if (v <= mid) return getSum(head->left, l, mid, u, v, lz);
else if (u > mid) return getSum(head->right, mid + 1, r, u, v, lz);
else {
return getSum(head->left, l, mid, u, v, lz) + getSum(head->right, mid + 1, r, u, v, lz);
}
}
void solve() {
root = new Node();
long long C = 0;
while(q--) {
long long type, l, r; cin >> type >> l >> r;
l += C; r += C;
if (type == 2) update(root, 1, (int)1e9, l, r, root->lz);
else {
C = getSum(root, 1, (int)1e9, l, r, 0);
cout << C << endl;
}
}
}
signed main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
if (fopen(TASK".inp", "r")) {
freopen(TASK".inp", "r", stdin);
freopen(TASK".out", "w", stdout);
}
int test = 1;
// cin >> test;
while(test--) {
read();
solve();
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |