Submission #802929

#TimeUsernameProblemLanguageResultExecution timeMemory
802929aymanrsStone Arranging 2 (JOI23_ho_t1)C++14
100 / 100
158 ms16796 KiB
#include<bits/stdc++.h> const int MOD = 1e9+7; using namespace std; struct ball { int c, l, r; }; void solve(){ int n; cin >> n; int a[n]; for(int i = 0;i < n;i++) cin >> a[i]; map<int, int> c; stack<ball> s; for(int i = 0;i < n;i++){ ball g = {a[i], i, i}; if(!c[a[i]]){ c[a[i]]++; s.push(g); continue; } while(s.top().c != a[i]){ g.l = s.top().l; c[s.top().c] -= s.top().r-s.top().l+1; s.pop(); } c[a[i]] += g.r-g.l+1; g.l = s.top().l; s.pop(); s.push(g); } while(!s.empty()){ for(int i = s.top().l;i <= s.top().r;i++) a[i] = s.top().c; s.pop(); } for(int i = 0;i < n;i++) cout << a[i] << '\n'; } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...