社区讨论
这两份代码,为什么一份过了,一份没过
P5076【深基16.例7】普通二叉树(简化版)参与者 2已保存回复 1
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 1 条
- 当前快照
- 1 份
- 快照标识符
- @m1apa2i1
- 此快照首次捕获于
- 2024/09/20 20:31 去年
- 此快照最后确认于
- 2025/11/04 20:49 4 个月前
这两份代码,为什么一份过了,一份没过```cpp
#include<bits/stdc++.h>
#include<bits/extc++.h>
#define IOS std::ios::sync_with_stdio(false);std::cin.tie(nullptr);std::cout.tie(nullptr);
#define all(x) (x).begin(),(x).end()
#define Yes(x,y) cout<<((x)?"Yes":"No")<<y
#define YES(x,y) cout<<((x)?"YES":"NO")<<y
#define ls ((u)<<1)
#define rs ((u)<<1|1)
#define mid (((l)+(r))>>1)
#define lowbit(x) ((x)&(-(x)))
#define itn int
#define asn ans
#define reisze resize
#define pdd pair<double,double>
#define pll pair<LL,LL>
#define pii pair<int,int>
#define tll tuple<LL,LL,LL>
#define tii tuple<int,int,int>
#define plll pair<LLL,LLL>
#define ULL unsigned long long
#define LL long long
#define LLL __int128
#define ld long double
#define ui64 uint64_t
#define ui32 uint32_t
using namespace std;
using namespace __gnu_pbds;
template
using RBTree = tree<T, null_type, less, rb_tree_tag, tree_order_statistics_node_update>;
template
T fang(const T& a){
return a*a;
}
template<typename T,typename Q>
bool chmax(T& u1,T& u2,const Q& v){
if(v>u1) { u2 = u1, u1 = v;return true;}
if(v>u2){u2=v;return true;}
return false;
}
template<typename T,typename Q>
bool chmin(T& u1,T& u2,const Q& v){
if(v<u1) { u2 = u1, u1 = v;return true;}
if(v<u2){u2=v;return true;}
return false;
}
template<typename T,typename Q>
bool chmin(T& a,const Q& b){
return a > b && (a = b, true);
}
template<typename T,typename Q>
bool chmax(T& a,const Q& b){
return a<b&&(a=b,true);
}
template<typename t1,typename t2>
istream& operator>>(istream& in,pair<t1,t2>& pa){
in>>pa.first>>pa.second;
return in;
}
template<typename t1,typename t2>
ostream& operator<<(ostream& out,const pair<t1,t2>& pa){
out<<pa.first<<' '<<pa.second;
return out;
}
template
istream& operator>>(istream& in,vector& arr){
for(auto& v:arr)in>>v;
return in;
}
template
ostream& operator<<(ostream& out,const vector& arr){
for(auto& v:arr)out<<v<<' ';
return out;
}
const ld eps=1e-9;
const int N=6e5+5;
const int SIZ=1e7;
const LL inf=1e17;
signed main(){
IOS;
int q;
cin>>q;
RBTree A;
int cnt=1;
while(q--){
int op;
LL x;
cin>>op>>x;
if(op==1) {
cout<<A.order_of_key({x,0})+1<<'\n';
}else if(op==2){
cout<<A.find_by_order(x-1)->first<<'\n';
}else if(op==3){
int rk=A.order_of_key({x,0});
if(rk==0)cout<<"-2147483647\n";
else cout<<A.find_by_order(rk-1)->first<<'\n';
}else if(op==4){
if(A.upper_bound({x,inf})==A.end())cout<<"2147483647\n";
else cout<<A.upper_bound({x,inf})->first<<'\n';
}else{
A.insert({x,++cnt});
}
}
}
CPP```cpp
#include<bits/stdc++.h>
#include<bits/extc++.h>
#define IOS std::ios::sync_with_stdio(false);std::cin.tie(nullptr);std::cout.tie(nullptr);
#define all(x) (x).begin(),(x).end()
#define Yes(x,y) cout<<((x)?"Yes":"No")<<y
#define YES(x,y) cout<<((x)?"YES":"NO")<<y
#define ls ((u)<<1)
#define rs ((u)<<1|1)
#define mid (((l)+(r))>>1)
#define lowbit(x) ((x)&(-(x)))
#define itn int
#define asn ans
#define reisze resize
#define pdd pair<double,double>
#define pll pair<LL,LL>
#define pii pair<int,int>
#define tll tuple<LL,LL,LL>
#define tii tuple<int,int,int>
#define plll pair<LLL,LLL>
#define ULL unsigned long long
#define LL long long
#define LLL __int128
#define ld long double
#define ui64 uint64_t
#define ui32 uint32_t
using namespace std;
using namespace __gnu_pbds;
template<typename T>
using RBTree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T>
T fang(const T& a){
return a*a;
}
template<typename T,typename Q>
bool chmax(T& u1,T& u2,const Q& v){
if(v>u1) { u2 = u1, u1 = v;return true;}
if(v>u2){u2=v;return true;}
return false;
}
template<typename T,typename Q>
bool chmin(T& u1,T& u2,const Q& v){
if(v<u1) { u2 = u1, u1 = v;return true;}
if(v<u2){u2=v;return true;}
return false;
}
template<typename T,typename Q>
bool chmin(T& a,const Q& b){
return a > b && (a = b, true);
}
template<typename T,typename Q>
bool chmax(T& a,const Q& b){
return a<b&&(a=b,true);
}
template<typename t1,typename t2>
istream& operator>>(istream& in,pair<t1,t2>& pa){
in>>pa.first>>pa.second;
return in;
}
template<typename t1,typename t2>
ostream& operator<<(ostream& out,const pair<t1,t2>& pa){
out<<pa.first<<' '<<pa.second;
return out;
}
template<typename T>
istream& operator>>(istream& in,vector<T>& arr){
for(auto& v:arr)in>>v;
return in;
}
template<typename T>
ostream& operator<<(ostream& out,const vector<T>& arr){
for(auto& v:arr)out<<v<<' ';
return out;
}
const ld eps=1e-9;
const int N=6e5+5;
const int SIZ=1e7;
const LL inf=1e17;
signed main(){
IOS;
int q;
cin>>q;
RBTree<pll> A;
int cnt=1;
while(q--){
int op;
LL x;
cin>>op>>x;
switch(op){
case 1:{
cout<<A.order_of_key({x,0})+1<<'\n';
break;
}
case 2:{
cout<<A.find_by_order(x-1)->first<<'\n';
break;
}
case 3:{
int rk=A.order_of_key({x,0});
if(rk==0)cout<<"−2147483647\n";
else cout<<A.find_by_order(rk-1)->first<<'\n';
break;
}
case 4:{
if(A.upper_bound({x,inf})==A.end())cout<<"2147483647\n";
else cout<<A.upper_bound({x,inf})->first<<'\n';
break;
}
case 5:{
A.insert({x,++cnt});
break;
}
}
}
}
回复
共 1 条回复,欢迎继续交流。
正在加载回复...