# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
548638 | krit3379 | Monkey and Apple-trees (IZhO12_apple) | C++17 | 220 ms | 58952 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;
#define N 200005
class node{
public:
int sum;
node *tl,*tr;
node():tl(NULL),tr(NULL),sum(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&&!(l>rr||ll>mid))tl = new node();
if(tl)tl->update(l,mid,ll,rr);
if(!tr&&!(mid+1>rr||ll>r))tr = new node();
if(tr)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 main(){
int m,op,x,y,c=0;
scanf("%d",&m);
root = new node();
while(m--){
scanf("%d %d %d",&op,&x,&y);
if(op==1){
c=root->sol(1,1e9,x+c,y+c);
printf("%d\n",c);
}
else root->update(1,1e9,x+c,y+c);
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |