제출 #1133582

#제출 시각아이디문제언어결과실행 시간메모리
1133582nuutsnoyntonStone Arranging 2 (JOI23_ho_t1)C++20
100 / 100
186 ms14280 KiB
#include<bits/stdc++.h> using namespace std; using ll = int; map < ll, ll > A; int main() { ll n, m, sum,r, x, y, ans,i,p, j, lo, hi, lo1,hi1,cnt1,cnt, t,s, mx, mn, k, o; cin >> n ; stack < pair < ll, ll > > S; for (i = 1; i <= n; i ++) { cin >> x; if ( A[x] == 0) { S.push({x, 1}); A[x] ++; } else { if ( S.empty()) { S.push({x, 1}); A[x] ++; continue; } sum = 0; while(!S.empty() && S.top().first != x) { A[S.top().first] -= (S.top().second); sum += (S.top().second); S.pop(); } A[S.top().first] --; sum += (S.top().second); S.pop(); A[x] =sum + 1; S.push({x, sum + 1}); } } vector <ll > v; while ( !S.empty()) { r = S.top().first; s = S.top().second; S.pop(); while ( s --) { v.push_back(r); } } reverse(v.begin(), v.end()); for (i = 0; i < v.size(); i ++) { cout << v[i] << " "; } cout << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...