Submission #1164905

#TimeUsernameProblemLanguageResultExecution timeMemory
1164905pinbuStone Arranging 2 (JOI23_ho_t1)C++20
100 / 100
102 ms13408 KiB
#include <bits/stdc++.h> using namespace std; const int N = 200005; const long long oo = 1e18; const int MOD = 1e9 + 7; int n, a[N]; int nxt[N]; map<int, int> p; int ans[N]; void solve(void) { cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; } for (int i = n; i; i--) { if (!p.count(a[i])) nxt[i] = i; else nxt[i] = p[a[i]] - 1; p[a[i]] = i; } int t = 0, col = -1; for (int i = 1; i <= n; i++) { if (i > t) { col = a[i]; t = nxt[i]; } cout << col << '\n'; } } signed main(void) { ios::sync_with_stdio(false); cin.tie(nullptr); // int TEST; cin >> TEST; while (TEST--) solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...