rope RE求助
查看原帖
rope RE求助
467107
Cap1taL楼主2023/1/28 19:53

本来想练练使用rope,做好了MLE和TLE的心理准备,发现却RE了,包括题解区第一页的rope题解我也测试了,并不是题解所说的80pts,而是84pts(2RE+1TLE),想请教为啥我这份代码和题解区的那个rope题解都有RE的情况?是迭代器处理的不合法访问到非法内存了吗?

写的基本调的和题解那个差不多了,只有一些语法细节不大一样

#include <bits/stdc++.h>
#include <bits/extc++.h>
using namespace std;
using namespace __gnu_cxx;
inline int read(){
	int x=0,w=1;
	char ch=0;
	while(ch<'0'||ch>'9'){ 
	if(ch=='-') w=-1;
	ch=getchar();
	}
	while(ch>='0'&&ch<='9'){
	x=x*10+(ch-'0');
	ch=getchar();
	}
	return x*w;
}
rope<int> *a[500005];
int n;
signed main(){
	n=read();
	a[0]=new rope<int>();
	for(int i=1;i<=n;i++){
		int v=read(),opt=read(),x=read();
		a[i]=new rope<int>(*a[v]);
		if(opt==1){
			a[i]->insert(lower_bound(a[i]->begin(),a[i]->end(),x)-a[i]->begin(),x);
		}else if(opt==2){
			auto it=lower_bound(a[i]->begin(),a[i]->end(),x);
			if(*it==x){
				a[i]->erase(it-a[i]->begin(),1);
			}
		}else if(opt==3){
			printf("%d\n",lower_bound(a[i]->begin(),a[i]->end(),x)-a[i]->begin()+1);
		}else if(opt==4){
			printf("%d\n",a[i]->at(x-1));
		}else if(opt==5){
			auto it=lower_bound(a[i]->begin(),a[i]->end(),x);
			if(it==a[i]->begin()){
				printf("-2147483647\n");
			}else{
				printf("%d\n",*prev(it));
			}
		}else if(opt==6){
			auto it=upper_bound(a[i]->begin(),a[i]->end(),x);
			if(it==a[i]->end()+1){
				printf("2147483647\n");
			}else{
				printf("%d\n",*it);
			}
		}
	}
	return 0;
}
2023/1/28 19:53
加载中...