Submission #961322

#TimeUsernameProblemLanguageResultExecution timeMemory
961322mannshah1211Stone Arranging 2 (JOI23_ho_t1)C++17
60 / 100
2049 ms16328 KiB
#pragma GCC target("avx2,bmi2") #pragma GCC optimize("O2") /** * author: hashman * created: **/ #include <bits/stdc++.h> using namespace std; string to_string(string s) { return '"' + s + '"'; } string to_string(const char* s) { return to_string((string) s); } string to_string(bool b) { return (b ? "true" : "false"); } template <typename A, typename B> string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } template <typename A> string to_string(A v) { bool first = true; string res = "{"; for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); } res += "}"; return res; } void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); } #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__); int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } map<int, pair<int, int>> who; for (int i = 0; i < n; i++) { who[a[i]] = make_pair(-1, -1); } for (int i = 0; i < n; i++) { if (who[a[i]] == make_pair(-1, -1)) { who[a[i]] = make_pair(i, i); } else { int old = who[a[i]].second; who[a[i]].second = i; for (int j = old + 1; j < who[a[i]].second; j++) { who[a[j]] = make_pair(-1, -1); a[j] = a[i]; } } } vector<int> ans(n); for (auto [_, p] : who) { if (p != make_pair(-1, -1)) { for (int i = p.first; i <= p.second; i++) { ans[i] = _; } } } for (int i = 0; i < n; i++) { cout << ans[i] << '\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...