# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
872803 | AndreiBOTO | 원숭이와 사과 나무 (IZhO12_apple) | C++14 | 193 ms | 262144 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#pragma optimize GCC ("Ofast")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
///#include <tryhardmode>
///#include <GODMODE::ON>
///Hey I heard you like the wild ones
///Wild Ones - Flo Rida, Sia
using namespace std;
const int INF=1e9;
struct SegTree{
public:
int s;
bool lazy;
SegTree *left;
SegTree *right;
SegTree()
{
s=0;
lazy=false;
left=right=NULL;
}
};
void propag(SegTree *aint,int st,int dr)
{
if(aint==NULL)
return ;
else
{
if(aint->lazy)
{
aint->s=dr-st+1;
if(st!=dr)
{
if(aint->left==NULL)
aint->left=new SegTree();
if(aint->right==NULL)
aint->right=new SegTree();
aint->left->lazy=true;
aint->right->lazy=true;
}
aint->lazy=false;
}
}
}
void update(SegTree *aint,int st,int dr,int a,int b)
{
propag(aint,st,dr);
if(a<=st && dr<=b)
{
aint->lazy=true;
propag(aint,st,dr);
return ;
}
else
{
int mij=st+dr;
mij/=2;
if(aint->left==NULL)
aint->left=new SegTree();
if(aint->right==NULL)
aint->right=new SegTree();
if(a<=mij)
update(aint->left,st,mij,a,b);
if(mij<b)
update(aint->right,mij+1,dr,a,b);
aint->s=(aint->left->s)+(aint->right->s);
}
}
int query(SegTree *aint,int st,int dr,int a,int b)
{
if(aint==NULL)
return 0;
propag(aint,st,dr);
if(a<=st && dr<=b)
return aint->s;
else
{
int kon=0;
int mij=st+dr;
mij/=2;
if(a<=mij)
kon+=query(aint->left,st,mij,a,b);
if(mij<b)
kon+=query(aint->right,mij+1,dr,a,b);
return kon;
}
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
SegTree *aint=new SegTree();
int t,c=0;
cin>>t;
while(t--)
{
int type,x,y;
cin>>type>>x>>y;
if(type==1)
{
c=query(aint,1,INF,x+c,y+c);
cout<<c<<"\n";
}
else
update(aint,1,INF,x+c,y+c);
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |