This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define mkp make_pair
#define MEM(x) memset(x,0,sizeof(x))
#define ALL(x) begin(x), end(x)
#define PH push
#define PB push_back
#define REP(i,N) for( int i = 0; i <(N); ++i )
#define FOR(i,a,b) for( int i = (a); i <= (b); ++i )
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
template<typename T>
using V = vector<T>;
void solve() {
int N; cin >> N;
map< int ,int > cnt;
V<pii> vc;
FOR(i,1,N) {
int a; cin >> a;
if( cnt[ a ] != 0 ) {
while( vc.back().F != a ) {
cnt[ vc.back().F ] --;
vc.pop_back();
}
}
else {
cnt[ a ]++;
vc.PB( mkp(a,i) );
}
}
int l = 0;
FOR(i,1,N) {
if( l+1<vc.size() && vc[l+1].S == i )
++l;
cout << vc[l].F << '\n';
}
}
int main () {
int T=1;
#ifdef LOCAL
freopen( "input.txt", "r", stdin );
freopen( "output.txt", "w", stdout );
cin >> T;
#else
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#endif
while(T--) solve();
}
Compilation message (stderr)
Main.cpp: In function 'void solve()':
Main.cpp:40:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int>, std::allocator<std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
40 | if( l+1<vc.size() && vc[l+1].S == i )
| ~~~^~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |