# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
888539 | dwuy | Monkey and Apple-trees (IZhO12_apple) | C++14 | 343 ms | 139700 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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... |