Newcoder 59 A.假的线段树(水~)

Description

给你一个长为nnn的序列aaa,有mmm次操作

1.1.1.把区间[l,r][l,r][l,r]内所有xxx变成yyy

2.2.2.查询区间[l,r][l,r][l,r]内第kkk小值

Input

第一行两个数n,mn,mn,m

第二行nnn个数表示序列aaa

后面mmm

1 l r x y:1\ l\ r\ x\ y :1 l r x y:把区间[l,r][l,r][l,r]中所有xxx变成yyy

2 l r k:2\ l\ r\ k :2 l r k:查询区间[l,r][l,r][l,r]中的第kkk小值

(1≤n,m,ai≤103)(1\le n,m,a_i\le 10^3)(1n,m,ai103)

Output

对于每个询问,输出一个数表示答案

Sample Input

3 3
2 3 3
2 1 3 1
1 1 3 3 1
2 1 3 2

Sample Output

3 3
2 3 3
2 1 3 1
1 1 3 3 1
2 1 3 2

Solution

暴力,时间复杂度O(mnlogn)O(mnlogn)O(mnlogn)

Code

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<ctime>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const int INF=0x3f3f3f3f,maxn=1005;
int n,m,a[maxn],b[maxn];
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	while(m--)
	{
		int op,l,r,x,y;
		scanf("%d%d%d%d",&op,&l,&r,&x);
		if(op==1)
		{
			scanf("%d",&y);
			for(int i=l;i<=r;i++)
				if(a[i]==x)a[i]=y;
		}
		else
		{
			for(int i=l;i<=r;i++)b[i-l]=a[i];
			sort(b,b+r-l+1);
			printf("%d\n",b[x-1]);
		}
	}
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值