#include <bits/stdc++.h>
using namespace std;
#include <bits/extc++.h>
using namespace __gnu_pbds;
typedef tree<vector<int>,null_type,less<vector<int>>,rb_tree_tag,tree_order_statistics_node_update>
ost;
map<int,bool> mapa;
int main()
{
int n;
cin>>n;
ost tree;
for(int i=0;i<n;i++)
{
int x;
cin>>x;
if(mapa[x]==false)
{
tree.insert({i,x,1});
}
else
{
int cnt=1;
for(;;)
{
vector<int> vec=*tree.find_by_order(tree.size()-1);
tree.erase(vec);
cnt+=vec[2];
mapa[vec[1]]=false;
if(vec[1]==x)
break;
}
tree.insert({i,x,cnt});
}
mapa[x]=true;
}
while(tree.size()>0)
{
vector<int> vec=*tree.find_by_order(0);
for(int i=0;i<vec[2];i++)
{
cout<<vec[1]<<endl;
}
tree.erase(vec);
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |