题解 | #wyh的天鹅#

wyh的天鹅

https://ac.nowcoder.com/acm/problem/15449

思路

学艺不精,交splay结果WA了,还找不到问题。
所以我还是用了vector写。保持vector是有序的,插入和删除的时候二分,复杂度很优。
记得要清空vector。

代码

#include<bits/stdc++.h>
//#define int long long
using namespace std;

int t,n,m,x;
string str;
vector<int>vt;

signed main(){
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin>>t;
    while(t--){
        vt.clear();
        cin>>n>>m;
        for(int i=1;i<=n;i++){
            cin>>x;
            vt.push_back(x);    
        }
        sort(vt.begin(),vt.end());
        for(int i=1;i<=m;i++){
            cin>>str>>x;
            if(str[0]=='q'){
                printf("%d\n",vt[vt.size()-x]);
            }    
            if(str[0]=='i'){
                vt.insert(lower_bound(vt.begin(),vt.end(),x),x);
            }
            if(str[0]=='d') vt.erase(lower_bound(vt.begin(),vt.end(),x));
        }
    }
    return 0;
}


全部评论

相关推荐

完美的潜伏者许愿简历...:隐藏信息被你提取出来了,暗示,这就是暗示
点赞 评论 收藏
分享
牛客刘北:如果暑期实习是27届的话,你要晚一年才会毕业,企业为什么会等你呢?要搞清时间逻辑呀!27届现在实习只能是在暑假实习,这是日常实习,不是暑期实习。所以多去投日常实习吧,暑期实习肯定不会要你的
点赞 评论 收藏
分享
评论
1
1
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务