# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
83726 | mra2322001 | Monkey and Apple-trees (IZhO12_apple) | C++14 | 2 ms | 376 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 f0(i, n) for(int i(0); i < (n); i++)
#define f1(i, n) for(int i(1); i <= n; i++)
using namespace std;
typedef long long ll;
const int N = 100002;
struct data{
int l, r, ln, lazy;
data() {}
data(int l_, int r_, int ln_) : l(l_), r(r_), ln(ln_) {}
} t[40000000];
int cnt = 1;
int n = 1000000000;
void push(int k, int l, int r){
int x = t[k].lazy;
if(x==0) return ;
t[k].ln = (r - l + 1);
if(l != r){
if(t[k].l==0) t[k].l = ++cnt;
if(t[k].r==0) t[k].r = ++cnt;
t[t[k].l].lazy = 1;
t[t[k].r].lazy = 1;
}
}
void up(int k, int l, int r, int i, int j){
push(k, l, r);
if(r < i || l > j) return ;
if(l >= i && r <= j){
t[k].lazy = 1;
push(k, l, r);
return ;
}
int m = (l + r)/2;
if(t[k].l==0) t[k].l = ++cnt;
if(t[k].r==0) t[k].r = ++cnt;
up(t[k].l, l, m, i, j);
up(t[k].r, m + 1, r, i, j);
t[k].ln = t[t[k].l].ln + t[t[k].r].ln;
}
int get1(int k, int l, int r, int i, int j){
push(k, l, r);
if(r < i || l > j) return 0;
if(l >= i && r <= j){
return t[k].ln;
}
int res = 0;
int m = (l + r)/2;
if(t[k].l==0) t[k].l = ++cnt;
if(t[k].r==0) t[k].r = ++cnt;
res = get1(t[k].l, l, m, i, j) + get1(t[k].r, m + 1, r, i, j);
return res;
}
int main(){
ios_base::sync_with_stdio(0);
int q; cin >> q;
int c = 0;
while(q--){
int type, l, r; cin >> type >> l >> r;
if(type==2) up(1, 1, n, l + c, r + c);
else{
int x = get1(1, 1, n, l + c, r + c);
cout << x << endl;
c += x;
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |