# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
888539 | dwuy | 원숭이와 사과 나무 (IZhO12_apple) | C++14 | 343 ms | 139700 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
struct Node{
bool lz;
int sum;
Node *l, *r;
Node(){
this->lz = 0;
this->sum = 0;
this->l = this->r = NULL;
}
};
struct SMT{
int n;
Node *root;
SMT(int n=0){
this->n = n;
this->root = new Node();
}
void down(Node *cur, int l, int r){
if(cur->lz == 0) return;
int mid = (l+r)>>1;
cur->l->lz = cur->r->lz = 1;
cur->l->sum = mid-l+1;
cur->r->sum = r-mid;
cur->lz = 0;
}
void update(Node *cur, int l, int r, const int &u, const int &v){
if(l>v || r<u) return;
if(l>=u && r<=v){
cur->lz = 1;
cur->sum = (r-l+1);
return;
}
if(!cur->l) cur->l = new Node();
if(!cur->r) cur->r = new Node();
down(cur, l, r);
int mid = (l+r)>>1;
update(cur->l, l, mid, u, v);
update(cur->r, mid+1, r, u, v);
cur->sum = cur->l->sum + cur->r->sum;
}
void update(int l, int r){
update(root, 1, n, l, r);
}
int get(Node *cur, int l, int r, const int &u, const int &v){
if(l>v || r<u) return 0;
if(l>=u && r<=v) return cur->sum;
if(!cur->l) cur->l = new Node();
if(!cur->r) cur->r = new Node();
down(cur, l, r);
int mid = (l+r)>>1;
return get(cur->l, l, mid, u, v) + get(cur->r, mid+1, r, u, v);
}
int get(int l, int r){
return get(root, 1, n, l, r);
}
};
void solve(){
int q;
cin >> q;
SMT smt(1000000000);
int C = 0;
while(q--){
int oper, l, r;
cin >> oper >> l >> r;
l += C; r += C;
if(oper == 2) smt.update(l, r);
else{
C = smt.get(l, r);
cout << C << endl;
}
}
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
solve();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |