Submission #774666

#TimeUsernameProblemLanguageResultExecution timeMemory
774666vjudge1Stone Arranging 2 (JOI23_ho_t1)C++17
100 / 100
59 ms12920 KiB
#include<bits/stdc++.h> using namespace std; int a[200001], noi[200001]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; cin>>n; for(int i = 1; i <= n; i++) cin>>a[i]; unordered_map<int, int> f; stack<int> num; for(int i = 1; i <= n; i++){ int &val = f[a[i]]; if(val > 0){ while(num.size() > 0 && a[num.top()] != a[i]){ f[a[num.top()]]--; num.pop(); } noi[i] = num.top(); } num.push(i); val++; } for(int i = n; i >= 1; i--) if(noi[i] > 0){ int x = noi[i], cur = a[i]; while(i > x+1){ i--; a[i] = cur; } } for(int i = 1; i <= n; i++) cout<<a[i]<<'\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...