在 c++ 扩展库中,有一个叫 rope 的东西。
对于 rope 的内置函数介绍:
l.append(x):向数列后面添加一个数,时间复杂度 。
l.insert(l,r):在 位置后面插入 ,时间复杂度 。
查询第 个元素只需要输出 即可。
所以说就能解决此题了。
#include<bits/stdc++.h>
#include<bits/extc++.h>
using namespace std;
using namespace __gnu_cxx;
rope<int>lt;
int opt,n,a,l,r,c;
int main(){
cin>>n;
lt.append(-1);
for(int i=1;i<=n;i++){
scanf("%d",&a);
lt.append(a);
}
while(n--){
cin>>opt;
cin>>l>>r>>c;
if(opt==1){
printf("%d\n",lt[r]);
}else{
lt.insert(l,r);
}
}
}
暂无评论