假的线段树

链接:https://www.nowcoder.com/acm/contest/59/A
来源:牛客网

时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 32768K,其他语言65536K
64bit IO Format: %lld
题目描述
给你一个长为n的序列a,有m次操作
1.把区间[l,r]内所有x变成y
2.查询区间[l,r]内第k小值
输入描述:
第一行两个数n,m
第二行n个数表示序列a
后面m行
1 l r x y :把区间[l,r]中所有x变成y
2 l r k :查询区间[l,r]中的第k小值
输出描述:
对于每个询问,输出一个数表示答案
示例1
输入

3 3
2 3 3
2 1 3 1
1 1 3 3 1
2 1 3 2
输出

2
1
备注:
对于100%的数据,1 <= n, m , ai <= 1000

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<set>
using namespace std;
const int MAX = 1e6+100;
const int INF = 0x3fffffff;
int a[MAX];
multiset<int >se;
int n,m;
int main(){
    while(scanf("%d%d",&n,&m)!=EOF){
        se.clear();
        for(int i=1;i<=n;i++){
            scanf("%d",&a[i]);
        }
        int l,r,x,y,t,k;
        while(m--){
            scanf("%d",&t);
            if(t==1){
                scanf("%d%d%d%d",&l,&r,&x,&y);
                for(int i=l;i<=r;i++){
                    if(a[i]==x) a[i]=y;
                }
            }
            else{
                se.clear();
                int temp=0;
                scanf("%d%d%d",&l,&r,&k);
                for(int i=l;i<=r;i++){
                    se.insert(a[i]);
                }
                int i=1;
                set<int>::iterator it;
                for(it=se.begin();it!=se.end();it++,i++){
                    if(i==k) {
                       cout<<*(it)<<endl;
                       break;
                    }
                }
            }
        }
    }
    return 0;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值