Submission #1317887

#TimeUsernameProblemLanguageResultExecution timeMemory
1317887nathako9nStone Arranging 2 (JOI23_ho_t1)C++17
100 / 100
232 ms27324 KiB
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
using namespace std;

const int N = 200005;

struct com {
   
    bool operator()(const pair<ll,ll>& a, const pair<ll,ll>& b) const {
        if(a.second == b.second) return a.first < b.first;
        return a.second < b.second;
    }
};

set<pair<ll,ll>, com> st;
map<ll, int> in; 

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n;
    cin>>n;

    for(int i = 1; i <= n; i++) {
        ll x; cin >> x;

       
        if(in.find(x) == in.end()) {
            st.insert({x, i});
            in[x] = i;
        } else {
          
            int target_idx = in[x];
            while(!st.empty() && st.rbegin()->second > target_idx) {
                in.erase(st.rbegin()->first);
                st.erase(prev(st.end()));
            }
        }
    }

    st.insert({-1, (ll)n + 1});
    int curr_print = 1;
    for(auto it = st.begin(); it != prev(st.end()); ++it) {
        while(curr_print < next(it)->second) {
            cout << it->first << " ";
            curr_print++;
        }
    }
    cout << endl;

    return 0;
}
/*

6
1
2
1
2
3
2

*/

#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...