# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
920114 | QioCas | 원숭이와 사과 나무 (IZhO12_apple) | C++14 | 318 ms | 139620 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h> // QioCas
#ifdef LOCAL
#include </home/cas/Cp/Lib/debug.h>
#else
#define console(...) void(202421)
#endif
using namespace std;
using ll = long long;
int Q;
struct node_t {
int sum = 0, lz = 0;
node_t *l = nullptr, *r = nullptr;
};
using pnode = node_t*;
void update_node(pnode& IT, int l, int r) {
if(!IT) IT = new node_t();
IT->sum = r - l + 1;
IT->lz = 1;
}
void push_down(pnode& IT, int l, int r) {
if(IT->lz == 0) return;
int mid = (l + r) / 2;
update_node(IT->l, l, mid);
update_node(IT->r, mid + 1, r);
IT->lz = 0;
}
void update(pnode& IT, int l, int r, int s, int t) {
if(!IT) IT = new node_t();
if(l > t || r < s) return;
if(s <= l && r <= t) {
update_node(IT, l, r);
return;
} push_down(IT, l, r);
int mid = (l + r) / 2;
update(IT->l, l, mid, s, t);
update(IT->r, mid + 1, r, s, t);
IT->sum = IT->l->sum + IT->r->sum;
}
int prod(pnode& IT, int l, int r, int s, int t) {
if(!IT || l > t || r < s) return 0;
if(s <= l && r <= t) return IT->sum;
push_down(IT, l, r);
int mid = (l + r) / 2;
return prod(IT->l, l, mid, s, t) + prod(IT->r, mid + 1, r, s, t);
}
int main() {
cin.tie(NULL)->sync_with_stdio(false);
cin >> Q;
ll c = 0;
pnode root = new node_t();
int L = 1, R = 1e9;
while(Q--) {
int op; ll l, r;
cin >> op >> l >> r;
l += c; r += c;
if(op == 2) {
update(root, L, R, l, r);
} else {
int x = prod(root, L, R, l, r);
cout << x << "\n";
c = x;
}
}
return 0;
}
////////////////////////////////////////////////////////////////////////////
// Nhân quả không nợ chúng ta thức gì, cho nên xin đừng oán giận ////////
// _
// _oo0oo_
// o8888888o
// 88” . “88
// (| -_- |)
// O\ = /O
// ____/'---'\____
// .' \\| |// '.
// / \\||| : |||// \
// / _||||| -:- |||||_ \
// | | \\\ - /'| | |
// | \_| `\`---'// |_/ |
// \ .-\__ `-. -'__/-. /
// ___`. .' /--.--\ `. . '___
// ."" '< `.___\_<|>_/___.' _> \"".
// | | : `- \`. ;`. _/; .'/ / .' ; |
// \ \ `-. \_\_`. _.' _/_/ -' _.' /
//===================`-.`___`-.__\ \___ /__.-'_.'_.-'===================//
// `=--=-'
// Đức Phật nơi đây phù hộ code con chạy không Bugs. Nam mô a di đà Phật.
//
// _.-/`)
// // / / )
// .=// / / / )
// //`/ / / / /
// // / ` /
// || /
// || /
// \\ /
// )) .'
// // /
//
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |