logo AlgoBeat OnlineJudge
登录 注册

题解

作者: _ZXY_  ·  发布于 2026-05-17 19:58:46  ·  最后修改于 2026-05-17 21:26:30
已通过
审核员:AlgoBeat 官方账号 · 2026-05-17 21:26:30

在 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);
        }
    }
}

暂无评论

登录 后即可评论。