# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
955824 | ZoTH | 원숭이와 사과 나무 (IZhO12_apple) | C++14 | 323 ms | 157260 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define N "\n"
#define all(object) object.begin(), object.end()
#define sz(object) (int)object.size()
#define ph push_back
#define pp pop_back
#define ss second
#define ff first
inline void ZoTH(string name = "")
{
ios_base::sync_with_stdio(false),
cin.tie(nullptr),
cout.tie(nullptr);
if (sz(name))
{
freopen((name + ".in").c_str(), "r", stdin);
freopen((name + ".out").c_str(), "w", stdout);
}
}
struct node
{
int sum , lft , rgt ;
bool lazy ;
node * left , * right ;
node (int s,int _lft,int _rgt,node * l=nullptr, node* r=nullptr)
{
sum= s ;
lft = _lft;
rgt = _rgt ;
left = l ;
right = r ;
lazy=0;
}
void mrg()
{
if(!lazy)
sum =(left?left->sum:0)+(right?right->sum:0);
else sum = rgt-lft+1;
if(left) left->lazy |=lazy;
if(right) right->lazy |=lazy ;
}
};
void update(node * at , ll lq,ll rq)
{
if(lq<=at->lft&&at->rgt<=rq)
{
at->lazy=1;
at->mrg();
}
else
{
int m =(at->lft+at->rgt)/2;
int l = at->lft ;
int r= at->rgt;
if(lq<=m)
{
if(!at->left)at->left=new node(0,l,m);
at->mrg();
update(at->left,lq,rq);
}
if(m+1<=rq)
{
if(!at->right)at->right=new node(0,m+1,r);
at->mrg();
update(at->right,lq,rq) ;
}
at->mrg();
}
}
int take(node*at,int lq,int rq)
{
if(lq<=at->lft&&at->rgt<=rq)
{
at->mrg();
return at->sum;
}
int m =(at->lft+at->rgt)/2;
int l = at->lft ;
int r= at->rgt;
int ret =0 ;
if(lq<=m)
{
if(!at->left)at->left=new node(0,l,m);
at->mrg();
ret+=take(at->left,lq,rq) ;
}
if(m+1<=rq)
{
if(!at->right)at->right=new node(0,m+1,r);
at->mrg();
ret+=take(at->right,lq,rq) ;
}
at->mrg();
return ret ;
}
void solve(int t)
{
// Goooo
const int n = (int)1e9+2;
int m ;
cin>>m ;
node *root = new node (0,1,n);
int c=0 ;
while(m--)
{
int x ,t, y ;
cin>>t>> x >> y ;
if(t==1)
{
c = take(root,x+c,y+c);
cout << c << N ;
}else{
update(root,x+c,y+c);
}
}
// stooo
}
int main()
{
ZoTH("");
// T_BEGIN
int t = 1;
// cin >> t;
for (int i = 1; i <= t; i++)
{
// cout << "Case " << i << ": ";
solve(i);
cout << N;
}
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |