# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1091140 | 4QT0R | 원숭이와 사과 나무 (IZhO12_apple) | C++17 | 299 ms | 209544 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
struct node{
node* lft;
node* rght;
ll l;
ll p;
ll sm;
};
node* head=new node;
ll sum(node* now, ll a, ll b){
if (now->p < a || b < now->l){
return 0;
}
if (a <= now->l && now->p <= b){
return now->sm;
}
if ((now->p - now->l + 1) == now->sm){
if (!(now->lft)){
now->lft=new node;
now->lft->l=now->l;
now->lft->p=(now->l+now->p)/2;
now->lft->lft=nullptr;
now->lft->rght=nullptr;
}
if (!(now->rght)){
now->rght=new node;
now->rght->l=(now->l+now->p)/2+1;
now->rght->p=now->p;
now->rght->lft=nullptr;
now->rght->rght=nullptr;
}
now->lft->sm=now->sm/2;
now->rght->sm=now->sm/2;
}
return (now->lft?sum(now->lft,a,b):0)+(now->rght?sum(now->rght,a,b):0);
}
void add(node* now, ll a, ll b){
if (now->p < a || b < now->l)return;
if (a <= now->l && now->p <= b){
now->sm=(now->p - now->l + 1);
return;
}
if (!(now->lft)){
now->lft=new node;
now->lft->l=now->l;
now->lft->p=(now->l+now->p)/2;
now->lft->sm=0;
now->lft->lft=nullptr;
now->lft->rght=nullptr;
}
if (!(now->rght)){
now->rght=new node;
now->rght->l=(now->l+now->p)/2+1;
now->rght->p=now->p;
now->rght->sm=0;
now->rght->lft=nullptr;
now->rght->rght=nullptr;
}
if ((now->p - now->l + 1) == now->sm){
now->lft->sm=now->sm/2;
now->rght->sm=now->sm/2;
}
add(now->lft,a,b);
add(now->rght,a,b);
now->sm=now->lft->sm + now->rght->sm;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
ll m;
cin >> m;
head->l=0;
head->p=INT_MAX>>1;
head->sm=0;
head->lft=nullptr;
head->rght=nullptr;
ll d,a,b,c=0;
for (ll i = 1; i<=m; i++){
cin >> d >> a >> b;
if (d==1){
c=sum(head,a+c,b+c);
cout << c << '\n';
}
else{
add(head,a+c,b+c);
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |