# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1008945 | krit3379 | Monkey and Apple-trees (IZhO12_apple) | C++14 | 133 ms | 77140 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;
class node{
public:
int sum;
node *tl,*tr;
node():sum(0),tl(0),tr(0){}
void upd(){
sum=max(sum,(tl?tl->sum:0)+(tr?tr->sum:0));
}
void update(int l,int r,int ll,int rr){
if(l>rr||ll>r)return ;
if(ll<=l&&r<=rr){
sum=r-l+1;
return ;
}
int mid=(l+r)/2;
if(!tl)tl=new node();
if(!tr)tr=new node();
tl->update(l,mid,ll,rr);
tr->update(mid+1,r,ll,rr);
upd();
}
int sol(int l,int r,int ll,int rr){
if(l>rr||ll>r)return 0;
if(ll<=l&&r<=rr)return sum;
if(sum==r-l+1)return min(r,rr)-max(l,ll)+1;
int mid=(l+r)/2;
return (tl?tl->sol(l,mid,ll,rr):0)+(tr?tr->sol(mid+1,r,ll,rr):0);
}
};
using pnode = node*;
pnode root;
int c;
int main(){
int q,op,l,r;
scanf("%d",&q);
root = new node();
while(q--){
scanf("%d %d %d",&op,&l,&r);
if(op==1){
printf("%d\n",c=root->sol(1,1e9,l+c,r+c));
}
else{
root->update(1,1e9,l+c,r+c);
}
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |