Subsegments

Programmer Sasha has recently begun to study data structures. His coach Stas told him to solve the problem of finding a minimum on the segment of the array in , which Sasha coped with. For Sasha not to think that he had learned all, Stas gave him a new task. For each segment of the fixed length Sasha must find the maximum element of those that occur on the given segment exactly once. Help Sasha solve this problem.

Input

The first line contains two positive integers n and k (1 ≤ n ≤ 105, 1 ≤ k ≤ n) — the number of array elements and the length of the segment.

Then follow n lines: the i-th one contains a single number ai ( - 109 ≤ ai ≤ 109).

Output

Print n–k + 1 numbers, one per line: on the i-th line print of the maximum number of those numbers from the subarray ai ai + 1 … ai + k - 1 that occur in this subarray exactly 1 time. If there are no such numbers in this subarray, print “Nothing”.

Examples
Input

5 3
1
2
2
3
3

Output

1
3
2

Input

6 4
3
3
3
4
4
2

Output

4
Nothing
3

题目含义:给定一个数列和一个区间长度m,要求你在每一个长度为 m 的区间内找到一个没有重复数字的最大值。

历程:开始我想着用单调队列优化来解决这个问题的,但是发现并不可行,因为要使用单调队列必须要满足一个非常重要的点,就是下一个区间不会再使用上一个区间所丢弃的值,这道题目显然不满足这个点。

题解:我们取map来记录所在区间内的所有点的个数,另外设置一个set 来表示符合条件的点的集合,由于set 中是已经是按照值的大小进行排序,所以我们只需要选取set末尾的值就好,顺便说一下,map 中是按照第一关键字进行排序的对于int 来说。

以后就变的紧了,要认真了。

#include <iostream>
#include <cstring>
#include <map>
#include <set>

using namespace std;

const int N = 100010;
map<int, int> ma;

set<int> s;

int n, m, a[N];

int main()
{
	cin >> n >> m;
	for (int i = 1; i <= n; i++) scanf("%d", a + i);
	for (int i = 1; i <= n; i++)
	{
		if (i <= m)
		{
			ma[a[i]] ++;
			if (ma[a[i]] == 1) s.insert(a[i]);
			else s.erase(a[i]);

			if (i == m)
			{
				if (s.size()) cout << *(--s.end()) << '\n';

				else cout << "Nothing\n";
			}
		}
		else
		{
			ma[a[i - m]] --;
			if (ma[a[i - m]] == 1) s.insert(a[i - m]);
			else s.erase(a[i - m]);
			ma[a[i]] ++;

			if (ma[a[i]] == 1) s.insert(a[i]);

			else s.erase(a[i]);
			if (s.size()) cout << *(--s.end()) << '\n';
			else cout << "Nothing\n";
		}
	}
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值