forked from srikanthmalipatel/Spoj-Problems
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathARRAYSUB-6739475-src.cpp
More file actions
97 lines (87 loc) · 1.52 KB
/
ARRAYSUB-6739475-src.cpp
File metadata and controls
97 lines (87 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iterator>
#include <utility>
using namespace std;
#define FOR(I,A,B) for(int I= (A); I<(B); ++I)
#define REP(I,N) FOR(I,0,N)
#define ALL(A) (A).begin(), (A).end()
#define DEBUG 0
typedef long long int LL;
struct P {
int N;
int O;
P( int n, int o ) : N(n), O(o) {}
};
bool operator <( P const& A, P const& B )
{
return ( A.N > B.N ) ? true : false;
}
int L( set<P> &S )
{
set<P>::iterator it = S.begin();
return it->N;
}
void addToSet( set<P> &K, int X )
{
pair<set<P>::iterator,bool> result;
result = K.insert( P( X, 1 ) );
if( result.second == false )
{
int o = result.first->O;
K.erase( result.first );
K.insert( P( X, o+1 ) );
}
}
void eraseFromSet( set<P> &K, int X )
{
pair<set<P>::iterator,bool> result;
result = K.insert( P( X, 1 ) );
if( result.second == false )
{
int o = result.first->O;
K.erase( result.first );
if( o > 1 )
K.insert( P( X, o-1 ) );
}
}
void printSet( set<P> &S )
{
cout << "S: {" << endl;
set<P>::iterator it = S.begin(), itEnd = S.end();
for( ; it!=itEnd; ++it )
cout << "(" << it->N << "," << it->O << ")" << endl;
cout << "}" << endl;
}
int main ()
{
int n;
cin >> n;
vector<int> A( n );
REP( i, n )
cin >> A[i];
int k;
cin >> k;
set<P> K;
REP( i, k )
{
addToSet( K, A[i] );
}
//printSet( K );
cout << L( K );
for( int i=k; i<n; ++i )
{
addToSet( K, A[i] );
eraseFromSet( K, A[i-k] );
//printSet( K );
cout << " " << L( K );
}
cout << endl;
}