# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
37338 | IvanC | Deda (COCI17_deda) | C++14 | 336 ms | 5188 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 1;
typedef struct node* pnode;
struct node{
pnode l,r;
int key,puro,junta,prior;
node(int _key,int _puro) : l(NULL),r(NULL),key(_key),puro(_puro),junta(_puro),prior(rand() ^ (rand() << 16)){}
};
inline int jnt(pnode t){return t ? t->junta : INF;}
inline void update(pnode t){if(t) t->junta = min(min(jnt(t->l),t->puro),jnt(t->r));}
void split(pnode t,int key,pnode &l,pnode &r){
if(t == NULL){
l = r = NULL;
}
else if(key < t->key){
split(t->l,key,l,t->l);
r = t;
}
else{
split(t->r,key,t->r,r);
l = t;
}
update(t);
}
void merge(pnode &t,pnode l,pnode r){
if(l == NULL){
t = r;
}
else if(r == NULL){
t = l;
}
else if(l->prior > r->prior){
merge(l->r,l->r,r);
t = l;
}
else{
merge(r->l,l,r->l);
t = r;
}
update(t);
}
void insert(pnode &t,int key,int puro){
pnode L,R;
pnode aux = new node(key,puro);
split(t,key,L,R);
merge(t,L,aux);
merge(t,t,R);
}
int find(pnode t,int y){
if(jnt(t->l) <= y) return find(t->l,y);
if(t->puro <= y) return t->key;
return find(t->r,y);
}
int query(pnode &t,int y,int b){
pnode L,R;
split(t,b-1,L,R);
int ret = -1;
if(jnt(R) <= y) ret = find(R,y);
merge(t,L,R);
return ret;
}
int main(){
int N,M;
pnode raiz = NULL;
scanf("%d %d",&N,&M);
while(M--){
char op;
scanf(" %c",&op);
if(op == 'M'){
int a,b;
scanf("%d %d",&a,&b);
insert(raiz,b,a);
}
else{
int y,b;
scanf("%d %d",&y,&b);
printf("%d\n",query(raiz,y,b));
}
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |