Submission #1064203

#TimeUsernameProblemLanguageResultExecution timeMemory
1064203ducksaysquackStone Arranging 2 (JOI23_ho_t1)C++98
100 / 100
200 ms24916 KiB
#include <bits/stdc++.h> #define int long long #define f first #define s second using namespace std; signed main() { int n; cin >> n; map<int,int> m; stack<pair<int,int>> t; for(int i=0;i<n;i++) { int x; cin >> x; if(m[x]) { int c = 1; while(t.top().f != x) {c += t.top().s, m[t.top().f]--; t.pop();} int y = t.top().s; t.pop(); t.push({x,y+c}); } else {t.push({x,1}); m[x]++;} } vector<int> v(n); int k=n-1; stack<pair<int,int>> q = t; while(!t.empty()) { for(int i=0;i<t.top().s;i++) v[k-i] = t.top().f; k -= t.top().s; t.pop(); } for(auto i:v) cout << i << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...