作为一个刚学树的萌新,真的不知道这题为什么用二叉
求大佬帮忙找找问题(样例能过)
(PS:注释部分为个人加的调试)
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#define zinf 2147483647
#define finf -2147483647
using namespace std;
typedef long long ll;
ll ans,v[10010],len,q;
void f1(ll x){
ll c=lower_bound(v,v+len,x)-v;
while(v[c-1]==x) --c;
ans=c+1;
return;
}
void f2(ll x){
ans=v[x-1];
return;
}
void f3(ll x){
if(x<=v[0]){
ans=finf;
return;
}
ll c=upper_bound(v,v+len,x)-v;
//printf("%d\n",c);
while(v[c]>=x) --c;
ans=v[c];
return;
}
void f4(ll x){
if(x>=v[len-1]){
ans=zinf;
return;
}
ll c=lower_bound(v,v+len,x)-v;
//printf("%d\n",c);
while(v[c]<=x) ++c;
//printf("%d\n",c);
ans=v[c];
return;
}
void f5(ll x){
if(!len){
v[0]=x;
++len;
return;
}
ll c=lower_bound(v,v+len,x)-v;
for(int k=len;k>c;--k){
v[k+1]=v[k];
}
v[c]=x;
++len;
/*for(int i=0;i<len;++i){
printf("%d ",v[i]);
}
printf("\n\n");*/
return;
}
int main(){
scanf("%d",&q);
for(int i=1;i<=q;++i){
int k;ll y;bool flag=1;
scanf("%d%d",&k,&y);
switch(k){
case 1:{
f1(y);
break;
}
case 2:{
f2(y);
break;
}
case 3:{
f3(y);
break;
}
case 4:{
f4(y);
break;
}
case 5:{
f5(y);
flag=0;
break;
}
}
if(flag) printf("%d\n",ans);
}
return 0;
}