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;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef pair<int,int> pi;
typedef vector<pi> pii;
#define REP(i,a,b) for(int i=a;i<b;i++)
#define F first
#define S second
#define PB push_back
#define MP make_pair
ll INF=1e18+10;
ll M=1e9+7;
int main() {
//ios::sync_with_stdio(0);
//cin.tie(0);
//freopen("test_input.txt", "r", stdin);
//freopen("test_output.txt", "w", stdout);
int n;cin>>n;
vi a(n);
REP(i,0,n)cin>>a[i];
map<int,queue<int>> b;
REP(i,0,n)b[a[i]].push(i);
int pos=0;
vi ans;
while(pos<n){
ans.PB(a[pos]);
int k=a[pos];
while(!b[k].empty()&&b[k].front()<=pos)b[k].pop();
if(b[k].empty()){
pos++;continue;
}
int x=b[k].front();
REP(i,pos,x-1)ans.PB(k);
pos=x;
}
for(auto u:ans)cout<<u<<"\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |