社区讨论
零分求调:=
P5076【深基16.例7】普通二叉树(简化版)参与者 3已保存回复 3
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 3 条
- 当前快照
- 1 份
- 快照标识符
- @lo7spvh0
- 此快照首次捕获于
- 2023/10/27 07:08 2 年前
- 此快照最后确认于
- 2023/10/27 07:08 2 年前
甚至普通的过了简化的没过
CPP#include<bits/stdc++.h>
using namespace std;
int n,opt,tmp;
vector<int>tree;
void opt2(){
printf("%d\n",tree[tmp-1]);
}
int opt3(){
static auto it1=lower_bound(tree.begin(),tree.end(),tmp);
if(it1==tree.end())return -2147483647;
else{
--it1;
return*(it1);
}
}
void opt4(){
static auto it2=upper_bound(tree.begin(),tree.end(),tmp);
if(it2==tree.end())puts("2147483647");
else printf("%d\n",*(it2));
}
void opt5(){
tree.insert(lower_bound(tree.begin(),tree.end(),tmp),tmp);
}
void opt1(){
bool f=0;
if(opt3()==-2147483647)
tree.insert(lower_bound(tree.begin(),tree.end(),tmp),tmp),f=1;
printf("%d\n",*(lower_bound(tree.begin(),tree.end(),tmp))-*(tree.begin())+1);
if(f)tree.erase(lower_bound(tree.begin(),tree.end(),tmp));
}
int main(){
scanf("%d",&n);
while(n--){
scanf("%d%d",&opt,&tmp);
switch(opt){
case 2:
opt2();
break;
case 3:
printf("%d\n",opt3());
break;
case 4:
opt4();
break;
case 5:
opt5();
break;
case 1:
opt1();
break;
}
}
return 0;
}
回复
共 3 条回复,欢迎继续交流。
正在加载回复...