Submission #774638

#TimeUsernameProblemLanguageResultExecution timeMemory
774638huutuanStone Arranging 2 (JOI23_ho_t1)C++14
60 / 100
2065 ms14724 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define sz(x) ((int)x.size()) #define sumof(x) accumulate(all(x), 0ll) const int N=2e5+1; int n, ans[N]; map<int, vector<pair<int, int>>> mp; void solve(int tc){ // cout << "Case #" << tc << ": "; cin >> n; for (int i=1; i<=n; ++i){ int x; cin >> x; if (mp.count(x) && mp[x].size()){ auto j=mp[x].back(); mp[x].pop_back(); for (auto it=mp.begin(); it!=mp.end();){ while (it->second.size() && it->second.back()>=j) it->second.pop_back(); if (it->second.empty()) it=mp.erase(it); else ++it; } mp[x].emplace_back(j.first, i); }else mp[x].emplace_back(i, i); } for (auto& i:mp) for (auto& j:i.second) for (int k=j.first; k<=j.second; ++k) ans[k]=i.first; for (int i=1; i<=n; ++i) cout << ans[i] << '\n'; } int32_t main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); int ntests=1; // cin >> ntests; for (int i=1; i<=ntests; ++i) solve(i); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...