# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
878610 | PagodePaiva | Monkey and Apple-trees (IZhO12_apple) | C++17 | 456 ms | 262144 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e9;
struct Node{
int value;
int lazy;
Node *lc, *rc;
Node(){
value = 0;
lazy = 0;
lc = NULL;
rc = NULL;
}
void newnode(){
if(lc == NULL) lc = new Node();
if(rc == NULL) rc = new Node();
}
};
Node* seg = new Node();
void unlazy(Node *current, int l, int r){
if(current -> lazy == 0) return;
current -> value = (r-l+1)*(current -> lazy);
if(l < r){
current -> newnode();
current -> lc -> lazy = current -> lazy;
current -> rc -> lazy = current -> lazy;
}
current -> lazy = 0;
return;
}
void update(Node *current, int l, int r, int val, int tl, int tr){
// cout << tl << ' ' << tr << '\n';
unlazy(current, tl, tr);
if(tl > r or tr < l) return;
if(l <= tl and tr <= r){
current -> lazy = val;
// cout << tl << ' ' << tr << '\n';
// cout << current -> value << ' ' << current -> lazy << '\n';
unlazy(current, tl, tr);
// cout << current -> value << ' ' << current -> lazy << '\n';
return;
}
int mid = (tl+tr)/2;
current -> newnode();
update(current -> lc, l, r, val, tl, mid);
update(current -> rc, l, r, val, mid+1, tr);
current -> value = current -> lc -> value + current -> rc -> value;
return;
}
int query(Node *current, int l, int r, int tl, int tr){
// cout << tl << ' ' << tr << '\n';
unlazy(current, tl, tr);
if(tl > r or tr < l) return 0;
if(l <= tl and tr <= r) {
// cout << tl << ' ' << tr << '\n';
// cout << current -> value << ' ' << current -> lazy << '\n';
return current -> value;
}
int mid = (tl+tr)/2;
current -> newnode();
return query(current -> lc, l, r, tl, mid) + query(current -> rc, l, r, mid+1, tr);
}
int32_t main(){
int q;
cin >> q;
int c = 0;
while(q--){
int d, l, r;
cin >> d >> l >> r;
l += c;
r += c;
if(d == 1){
int res = query(seg, l, r, 1, N);
c = res;
cout << res << '\n';
}
else{
update(seg, l, r, 1, 1, N);
}
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |