Submission #1121211

#TimeUsernameProblemLanguageResultExecution timeMemory
1121211Neco_arcStone Arranging 2 (JOI23_ho_t1)C++17
100 / 100
83 ms15388 KiB
#include <bits/stdc++.h>

#define ll long long
#define name "Stone Arranging 2"
#define fi(i, a, b)  for(int i = a; i <= b; ++i)
#define fid(i, a, b) for(int i = a; i <= b; --i)
#define maxn (int) (2e5 + 7)

using namespace std;

int n;
unordered_map<int, int> d;
vector<pair<int, int>> P;

void solve() {

    cin >> n;
    fi(i, 1, n) {
        int x; cin >> x;
        if(!d[x]) P.push_back({i, x}), d[x] = 1;
        else {
            while(P.back().second != x) d[P.back().second] = 0, P.pop_back();
            P.back().first = i;
        }
    }

    reverse(P.begin(), P.end());

    fi(i, 1, n) {
        while(i > P.back().first) P.pop_back();
        cout << P.back().second << '\n';
    }

}

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    if(fopen(name".inp", "r")) {
        freopen(name".inp", "r", stdin);
        freopen(name".out", "w", stdout);
    }

    solve();
}

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:42:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |         freopen(name".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:43:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |         freopen(name".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...