# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1008945 | krit3379 | Monkey and Apple-trees (IZhO12_apple) | C++14 | 133 ms | 77140 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |