# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
593527 | no_namee | 원숭이와 사과 나무 (IZhO12_apple) | C++14 | 614 ms | 230684 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define MIN_P 1
#define MAX_P 1000000000
using namespace std;
struct AINT
{
struct node
{
bool lazy;
int sum;
node *left, *right;
};
node *getNode()
{
node* nod = new(node);
nod->lazy = false;
nod->sum = 0;
nod->left = nod->right = NULL;
return nod;
}
node *root = getNode();
void update( node *nod, int l, int r, int lu, int ru )
{
int mid = (l + r) / 2;
if ( nod->lazy )
{
nod->sum = r - l + 1;
if ( l != r )
{
if ( nod->left == NULL ) nod->left = getNode();
if ( nod->right == NULL ) nod->right = getNode();
nod->left->lazy = nod->right->lazy = true;
}
nod->lazy = false;
}
if ( l > ru || r < lu ) return;
if ( lu <= l && r <= ru )
{
nod->sum = r - l + 1;
if ( l != r )
{
if ( nod->left == NULL ) nod->left = getNode();
if ( nod->right == NULL ) nod->right = getNode();
nod->left->lazy = nod->right->lazy = true;
}
nod->lazy = false;
return;
}
if ( nod->left == NULL ) nod->left = getNode();
if ( nod->right == NULL ) nod->right = getNode();
update( nod->left, l, mid, lu, ru );
update( nod->right, mid + 1, r, lu, ru );
nod->sum = nod->left->sum + nod->right->sum;
}
void update( int l, int r )
{
update( root, MIN_P, MAX_P, l, r );
}
int query( node *nod, int l, int r, int lq, int rq )
{
int mid = (l + r) / 2;
int sum;
if ( nod->lazy )
{
nod->sum = r - l + 1;
if ( l != r )
{
if ( nod->left == NULL ) nod->left = getNode();
if ( nod->right == NULL ) nod->right = getNode();
nod->left->lazy = nod->right->lazy = true;
}
nod->lazy = false;
}
if ( lq <= l && r <= rq ) return nod->sum;
sum = 0;
if ( mid >= lq )
{
if ( nod->left == NULL ) nod->left = getNode();
sum += query( nod->left, l, mid, lq, rq );
}
if ( mid + 1 <= rq )
{
if ( nod->right == NULL ) nod->right = getNode();
sum += query( nod->right, mid + 1, r, lq, rq );
}
return sum;
}
int query( int l, int r )
{
return query( root, MIN_P, MAX_P, l, r );
}
};
AINT apples;
int main()
{
int m, t, l, r, a, c;
c = 0;
cin >> m;
while ( m-- )
{
cin >> t >> l >> r;
l += c;
r += c;
if ( t == 1 )
{
a = apples.query( l, r );
cout << a << "\n";
c = a;
}
else apples.update( l, r );
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |