牛客网 牛客练习赛11 A.假的线段树

看不懂题意,而且太菜,写了两道就溜了。。。

 

A.假的线段树

链接: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

 

暴力跑就可以。

 

代码:

 1 //A
 2 #include<iostream>
 3 #include<cstdio>
 4 #include<algorithm>
 5 #include<cstring>
 6 #include<cstdlib>
 7 #include<string.h>
 8 #include<set>
 9 #include<vector>
10 #include<queue>
11 #include<stack>
12 #include<map>
13 #include<cmath>
14 using namespace std;
15 typedef long long ll;
16 const int INF=0x3f3f3f3f;
17 const int maxn=1e5+10;
18 double PI=acos(-1.0);
19 int a[maxn];
20 int main(){
21     int n,m;
22     while(~scanf("%d%d",&n,&m)){
23         memset(a,0,sizeof(a));
24         for(int i=1;i<=n;i++)
25             scanf("%d",&a[i]);
26         while(m--){
27             int t;
28             scanf("%d",&t);
29             if(t==1){
30                 int l,r,x,y;
31                 scanf("%d%d%d%d",&l,&r,&x,&y);
32                 for(int i=l;i<=r;i++){
33                     if(a[i]==x)a[i]=y;
34                 }
35             }
36             else{
37                 int l,r,k;
38                 scanf("%d%d%d",&l,&r,&k);
39                 int s[maxn];int h=0;
40                 for(int i=l;i<=r;i++){
41                     s[h++]=a[i];
42                 }
43                 sort(s,s+h);
44                 printf("%d\n",s[k-1]);
45             }
46         }
47     }
48     return 0;
49 }

 

 

 

转载于:https://www.cnblogs.com/ZERO-/p/8361755.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值