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.
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).
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 - 1that occur in this subarray exactly 1 time. If there are no such numbers in this subarray, print "Nothing".
5 3
1
2
2
3
3
1
3
2
6 4
3
3
3
4
4
2
4
Nothing
3
Question is intended: to a length of n digital output i from 1 to nk-1, i to i + k-1 within this interval if there is only occurrence interval maximum value of the output value, or output Nothing
Ideas: the number of those who once put the number of sorting and pre-k appears only to find out, you can ask to answer first,
and then start from k + 1, each adding a number to be deleted on a first interval the number, the number of the number and see the deletion of
whether 1, if it is a feasible set to join, or to see whether it is feasible to set (deleted because just once, if it is then it's feasible set it is the number 0, and take it to be deleted)
if the cut from it. Look at the number of the number of new add to the mix is 1, if it is to join the feasible set, otherwise it to see if it (if it is feasible set, then it is now the number 1, and now added to the feasible set once it, it becomes larger than a number, it does not meet the conditions), if the put it to delete the
feasible set the maximum number that each output
. 1 #include <bits / STDC ++ H.> 2 the using namespace STD; . 3 const int AMN = 1E5 + . 5 ; . 4 int A [AMN]; . 5 Map < int , int > MP; /// number of statistics, a [i] The maximum is 1e9, so with statistical map . 6 sET < int > S; /// feasible set . 7 int main () { . 8 int n-, K; . 9 iOS :: sync_with_stdio ( 0 ); 10 CIN >> >> n- K; 11 for ( int i=1;i<=n;i++){ 12 cin>>a[i]; 13 if(i<=k){ 14 mp[a[i]]++; 15 if(mp[a[i]]==1){ 16 s.insert(a[i]); 17 } 18 else{ 19 if(s.find(a[i])!=s.end()){ 20 s.erase(a[i]); 21 } 22 } 23 if(i==k){ 24 if(s.empty())printf(" Nothing \ n- " ); 25 the else { 26 is the printf ( " % D \ n- " , * (- s.end ())); /// SET ascending order, the output of the last 27 } 28 } 29 } 30 the else { 31 is MP [A [I]] ++ ; 32 MP [A [IK]] - ; 33 is IF (MP [A [IK]] == . 1 ) s.insert (A [IK ]); 34 is the else { /// may be 0, and if the number in the set will be over it possible to delete 35 if(s.find(a[i-k])!=s.end()){ 36 s.erase(a[i-k]); 37 } 38 } 39 if(mp[a[i]]==1)s.insert(a[i]); 40 else{ 41 if(s.find(a[i])!=s.end()){ 42 s.erase(a[i]); 43 } 44 } 45 if(s.empty())printf("Nothing\n"); 46 else{ 47 printf("D% \ n- " , * (- s.end ())); 48 } 49 } 50 } 51 is } 52 is / * ** 53 is first ordered and the number of the first k number of those find appear only once, it can be the first to answer to the inquiry, 54 then start from k + 1, a number is added to each of the first number on deletion of a section, and to see that the number of the omitted number of 55 is 1, if is a feasible set to join, or to see whether it is feasible to set (deleted because just once, if it is feasible to set it on the number 0, and take it to be deleted) 56 if delete the the number of the number of it. look at the new add to the mix is 1, if it is to join the feasible set, otherwise see whether it is feasible to set (if it is feasible set, then it is now the number 1, now add the time it, it would be greater than the number 1, does not meet the conditions), if the put it to delete 57 each output feasible set in the maximum number of 58 ** * /