# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
331367 | ronnith | Monkey and Apple-trees (IZhO12_apple) | C++14 | 695 ms | 262148 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>
#define FOR(i,a,b) for(int i = (a);i < (b);i ++)
#define FORd(i,b,a) for(int i = (b);i >= (a);i --)
#define trav(a,b) for(auto a:b)
#define pb push_back
#define mk make_pair
#define f first
#define s second
#define sz(a) (a).size()
#define maxn 100000
using ll = long long;
using namespace std;
ll modF = 1e9 + 7;
void setIO(string s = ""){
ios::sync_with_stdio(0);cin.tie(0);
if(sz(s)){
freopen((s + ".in").c_str(),"r",stdin);
freopen((s + ".out").c_str(),"w",stdout);
}
}
int MX = 1e9 + 10;
struct node{
int val, lazy;
node *right, *left;
node():val(0), lazy(0){}
};
struct Segtree{
node* root;
Segtree(){
root = new node();
}
void extend(node* crr){
if(crr->left != nullptr)return;
crr->left = new node();
crr->right = new node();
}
void propogate(node* crr, int l, int r){
if(crr->lazy == 0)return;
crr->val = r - l + 1;
crr->left->lazy = crr->right->lazy = 1;
crr->lazy = 0;
}
void pull(node* crr){
if(crr->left == nullptr)return;
crr->val = crr->left->val + crr->right->val;
}
void update(node* crr, int l, int r, int lx, int rx){
extend(crr);propogate(crr, lx, rx);
if(rx < l or r < lx)return;
if(l <= lx and rx <= r){
crr->lazy = 1;propogate(crr, lx, rx);return;
}
int mid = lx + (rx - lx) / 2;
update(crr->left, l, r, lx, mid);
update(crr->right, l, r, mid + 1, rx);
pull(crr);
}
int query(node* crr, int l, int r, int lx, int rx){
extend(crr);propogate(crr, lx, rx);
if(rx < l or lx > r)return 0;
if(l <= lx and rx <= r)return crr->val;
int mid = lx + (rx - lx) / 2;
return query(crr->left, l, r, lx, mid) + query(crr->right, l, r, mid + 1, rx);
}
};
int M;
int main(){
setIO();
cin >> M;
Segtree sg;
int prev = 0;
while(M --){
int t;
cin >> t;
if(t == 1){
int x, y;
cin >> x >> y;
x += prev, y += prev;
cout << (prev = sg.query(sg.root, x, y, 1, MX)) << '\n';
} else {
int x, y;
cin >> x >> y;
x += prev, y += prev;
sg.update(sg.root, x, y, 1, MX);
}
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |