| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 18612 | mindol | 원숭이와 사과 나무 (IZhO12_apple) | C++14 | 676 ms | 260324 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<cstdio>
struct Node
{
int value = 0; bool lazy = false;
Node *left = nullptr, *right = nullptr;
};
void lazydown(Node *now,int now_l,int now_r)
{
if(!now->lazy) return;
now->value = now_r-now_l+1;
now->lazy = false;
if(now_l==now_r) return;
if(now->left == nullptr) now->left = new Node();
now->left->lazy = true;
if(now->right == nullptr) now->right = new Node();
now->right->lazy = true;
}
void check(int l,int r,Node *now,int now_l,int now_r)
{
lazydown(now,now_l,now_r);
if(now_l>r || now_r<l) return;
else if(l<=now_l && now_r<=r) now->lazy = true, lazydown(now,now_l,now_r);
else
{
int mid=(now_l+now_r)/2;
if(now->left == nullptr) now->left = new Node();
if(now->right == nullptr) now->right = new Node();
check(l,r,now->left,now_l,mid);
check(l,r,now->right,mid+1,now_r);
now->value = now->left->value + now->right->value;
}
}
int rangeSum(int l,int r,Node *now,int now_l,int now_r)
{
lazydown(now,now_l,now_r);
if(now_l>r || now_r<l) return 0;
else if(l<=now_l && now_r<=r) return now->value;
else
{
int mid=(now_l+now_r)/2;
if(now->left == nullptr) now->left = new Node();
if(now->right == nullptr) now->right = new Node();
return rangeSum(l,r,now->left,now_l,mid)+rangeSum(l,r,now->right,mid+1,now_r);
}
}
int main()
{
int m;
scanf("%d",&m);
int C=0;
Node *root = new Node();
while(m--)
{
int a,b,c;
scanf("%d %d %d",&a,&b,&c);
if(a==1) printf("%d\n",C=rangeSum(b+C,c+C,root,1,1e9));
else check(b+C,c+C,root,1,1e9);
}
return 0;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
