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 ll long long
#define pb push_back
#define foru(i,a,b) for(int i = a; i <= b; ++i)
#define ford(i,a,b) for(int i = a; i >= b; --i)
#define vt vector
#define endl '\n'
const int N = 200005;
int n;
int x;
int col[N];
int a[N];
int s[N];
int e[N];
int cnt;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
memset(col,-1,sizeof col);
foru(i,0,n-1){
cin >> a[i];
}
ford(i,n-1,0){
if(col[a[i]] == -1){
col[a[i]] = i;
s[i] = i;
e[i] = i;
} else {
s[i] = i;
e[i] = col[a[i]];
col[a[i]] = i;
}
}
int p = 0;
bool ok = 0;
while(p < n){
cnt = e[p] - s[p] + 1;
if(!ok){
foru(i,1,cnt){
cout << a[p] << endl;
}
} else {
foru(i,1,cnt-1){
cout << a[p] << endl;
}
}
p += cnt;
if(cnt > 1){
p -= 1;
ok = 1;
} else {
ok = 0;
}
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |