Subsegments
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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 nk + 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 - 1that occur in this subarray exactly 1 time. If there are no such numbers in this subarray, print "Nothing".

Examples
input

Copy
5 3
1
2
2
3
3
output

Copy
1
3
2
input

Copy
6 4
3
3
3
4
4
2
output
s
Copy
4
Nothing
3

题意:给一个长度为n的数字,输出i从1到n-k-1,i到i+k-1这个区间内若存在只出现一次的区间最大值则输出这个值,否则输出Nothing

思路:先把前k个数排序并找出只出现一次的那些数,就可以的到第一次询问的答案,
然后从k+1开始,每加入一个数就删去上一个区间的第一个数,并看删去的那个数的个数
是否为1,若为1则加入可行集合,否则就看它是否在可行集合中(因为刚才删了一次,若它在可行集合中那么它的数量就为0了,要把它给删了)
若在就删了它。再看新加进来的那个数的个数是否为1,如果是就加入可行集合,否则就看它是否在可行集合中(如果它在可行集合中,那么它现在的数量为1,现在又加了一次它,它的个数就大于1,不符合条件了),若在就把它给删了
每次输出可行集合中最大的那个数

 #include<bits/stdc++.h>
using namespace std;
const int amn=1e5+;
int a[amn];
map<int,int> mp; ///个数统计,a[i]最大是1e9,故用map统计
set<int> s; ///可行集合
int main(){
int n,k;
ios::sync_with_stdio();
cin>>n>>k;
for(int i=;i<=n;i++){
cin>>a[i];
if(i<=k){
mp[a[i]]++;
if(mp[a[i]]==){
s.insert(a[i]);
}
else{
if(s.find(a[i])!=s.end()){
s.erase(a[i]);
}
}
if(i==k){
if(s.empty())printf("Nothing\n");
else{
printf("%d\n",*(--s.end())); ///set升序排序,输出最后一个
}
}
}
else{
mp[a[i]]++;
mp[a[i-k]]--;
if(mp[a[i-k]]==)s.insert(a[i-k]);
else{ ///可能为0了,如果这个数在可行集合中就要把它删掉
if(s.find(a[i-k])!=s.end()){
s.erase(a[i-k]);
}
}
if(mp[a[i]]==)s.insert(a[i]);
else{
if(s.find(a[i])!=s.end()){
s.erase(a[i]);
}
}
if(s.empty())printf("Nothing\n");
else{
printf("%d\n",*(--s.end()));
}
}
}
}
/***
先把前k个数排序并找出只出现一次的那些数,就可以的到第一次询问的答案,
然后从k+1开始,每加入一个数就删去上一个区间的第一个数,并看删去的那个数的个数
是否为1,若为1则加入可行集合,否则就看它是否在可行集合中(因为刚才删了一次,若它在可行集合中那么它的数量就为0了,要把它给删了)
若在就删了它。再看新加进来的那个数的个数是否为1,如果是就加入可行集合,否则就看它是否在可行集合中(如果它在可行集合中,那么它现在的数量为1,现在又加了一次它,它的个数就大于1,不符合条件了),若在就把它给删了
每次输出可行集合中最大的那个数
***/

[STL] Codeforces 69E Subsegments的更多相关文章

  1. codeforces每日一题1-10

    目录: 1.1093D. Beautiful Graph(DFS染色) 2.514C - Watto and Mechanism(Tire) 3.69E.Subsegments(STL) 4.25C. ...

  2. Codeforces Round #285 (Div. 2) A B C 模拟 stl 拓扑排序

    A. Contest time limit per test 1 second memory limit per test 256 megabytes input standard input out ...

  3. 【中途相遇法】【STL】BAPC2014 K Key to Knowledge (Codeforces GYM 100526)

    题目链接: http://codeforces.com/gym/100526 http://acm.hunnu.edu.cn/online/?action=problem&type=show& ...

  4. 【STL】【模拟】Codeforces 696A Lorenzo Von Matterhorn

    题目链接: http://codeforces.com/problemset/problem/696/A 题目大意: 一个满二叉树,深度无限,节点顺序编号,k的儿子是k+k和k+k+1,一开始树上的边 ...

  5. Codeforces 701C They Are Everywhere(Two pointers+STL)

    [题目链接] http://codeforces.com/problemset/problem/701/C [题目大意] 给出 一个字符串,里面包含一定种类的字符,求出一个最短的子串,使得其包含该字符 ...

  6. Codeforces 799B - T-shirt buying(STL)

    题目链接:http://codeforces.com/problemset/problem/799/B 题目大意:有n件T恤,每件T体恤都分别有价格(每件衣服的价格不重复).前面的颜色.背部的颜色三种 ...

  7. Codeforces Round #595 (Div. 3)D1D2 贪心 STL

    一道用STL的贪心,正好可以用来学习使用STL库 题目大意:给出n条可以内含,相交,分离的线段,如果重叠条数超过k次则为坏点,n,k<2e5 所以我们贪心的想我们从左往右遍历,如果重合部分条数超 ...

  8. [Codeforces 1246B] Power Products (STL+分解质因数)

    [Codeforces 1246B] Power Products (STL+分解质因数) 题面 给出一个长度为\(n\)的序列\(a_i\)和常数k,求有多少个数对\((i,j)\)满足\(a_i ...

  9. STL容器set用法以及codeforces 685B

    以前没怎么用过set,然后挂训练赛的时候发现set的妙用,结合网上用法一边学一边写. 首先set是一种容器,可以跟其他STL容器一样用 set<int > s 来定义, 它包含在STL头文 ...

随机推荐

  1. 产品需求说明书 PRD模版

    XXX产品需求说明书 [版本号:V+数字]                 编  制: 日  期: 评  审:   日  期: 批  准: 日  期:       修订记录 版本 修订章节 修订内容 ...

  2. 在 macOS 上试用 Gentoo/Prefix

    前几天参加了许朋程主讲的Tunight,对Gentoo有了一定的了解,不过看到如此复杂的安装过程和长久的编译时间,又看看我的CPU,只能望而却步了.不过,有Gentoo/Prefix这个工具,使得我们 ...

  3. 印度IT产业今年裁员5.6万,自动化大潮下安有完卵

    [腾讯科技编者按]业界媒体Quatz撰文指出,对于印度科技从业者来说,2017年是噩梦连连的一年.直到几年前,IT业都还是印度提供就业岗位最多的行业之一,但在今年,这个1600亿美元规模的行业裁掉了5 ...

  4. HTTP Continuation or non-HTTP traffic

    发现一个 HTTP      Continuation or non-HTTP traffic的数据包,之前没有碰到过.不懂其意义,一看长度,显示1460,与TCP segment of a reas ...

  5. Ftp Centos · GitBook

    これよくない pyftpdlibをつかおう sudo easy_install pyftpdlib nohup python -m pyftpdlib > pyftpdlib.log 2> ...

  6. 在 LaTeX 中实现缩印效果

    https://liam.page/ 近日大概重拾了一点对 LaTeX 的兴趣,遇见这样一个问题:如何在 LaTeX 中实现缩印效果(即,将两页或更多页排版在一页纸上),并且实现水印效果的页码? 缩印 ...

  7. Samtec大数据技术解决方案

    序言:众所周知,大数据将在AI时代扮演重要角色,拥有海量数据的公司已在多个领域尝试对掌握的数据进行利用,大数据意识和能力进步飞快,体系和工具日趋成熟. Samtec和Molex 是获得许可从而提供 M ...

  8. ES6/JavaScript一些‘巧用’

    前言 第一次发表文章,如有不好的地方请见谅/ 在编写JavaScript代码的时候存在的一些方法和技巧,虽然有时候条条大路都通向罗马,但是也许总会有那么一条最短的路径可走.本文将一些都知道却不怎么用的 ...

  9. 原生js实现在表格用鼠标框选并有反选功能

    今天应同学要求,需要写一个像Excel那样框选高亮,并且实现框选区域实现反选功能.要我用原生js写,由于没什么经验翻阅了很多资料,第一次写文章希望各位指出不足!! 上来先建表 <div clas ...

  10. 搭建Flutter开发环境需要注意的几个小Tips

    目录 下载SDK 安装 Android Stdio + SDK + tool SDK + 创建模拟器 + 插件(flutter和dart) Xcode + cocoapods VSCode + Flu ...