Submission #774724

#TimeUsernameProblemLanguageResultExecution timeMemory
774724vjudge1Stone Arranging 2 (JOI23_ho_t1)C++14
60 / 100
2061 ms13892 KiB
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
#define ii pair<int,int>
const ll maxn=2e5+2;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n; cin>>n;
    int a[n];
    unordered_map <int,int> mp;
    stack<int> st;
    int x;
    for (int i=0;i<n;++i){
        cin>>x;
        if (!mp[x]){
            st.push(x);
        }else{
            int cnt=1;
            while (st.top()!=x){
                ++cnt;
                --mp[st.top()];
                st.pop();
            }   
            while (cnt--){
                st.push(x);
                ++mp[x];
            }
            --mp[x];
        }
        ++mp[x];
    }
    vector<int> v;
    while (!st.empty()){
        v.push_back(st.top());
        st.pop();
    }
    reverse(v.begin(),v.end());
    for (int i: v) cout<<i<<" ";
}

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:15:9: warning: unused variable 'a' [-Wunused-variable]
   15 |     int a[n];
      |         ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...