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>
typedef long long ll;
using namespace std;
const int maxn=2000005;
int n;
int a[maxn];
bool used[maxn];
map<int,int>mp;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n;
for (int i=1; i<=n; i++)
{
cin >> a[i];
}
stack<pair<int,int>>s;
for (int i=1; i<=n; i++)
{
if(mp[a[i]]==0)
{
mp[a[i]]++;
pair<int,int>tmp;
tmp.first=a[i];
tmp.second=mp[a[i]];
s.push(tmp);
}
else
{
int cur=0;
while(!s.empty() && s.top().first!=a[i])
{
int x=s.top().first;
int y=s.top().second;
s.pop();
cur+=y;
mp[x]-=y;
}
cur+=s.top().second;
s.pop();
pair<int,int>tmp;
tmp.first=a[i];
tmp.second=cur+1;
mp[a[i]]=cur+1;
s.push(tmp);
}
}
vector<int>v;
while(!s.empty())
{
for (int i=0; i<s.top().second; i++)
{
v.push_back(s.top().first);
}
s.pop();
}
for (int i=v.size()-1; i>=0; i--)
{
cout << v[i] << endl;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |