# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
941394 | Reverberate | Stone Arranging 2 (JOI23_ho_t1) | C++14 | 208 ms | 19908 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define INF 1e18
#define DEBUG 0
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin>>n;
stack<pair<int,int>>stk;
int t;
map<int,int>mp;
for(int i=0;i<n;i++){
cin>>t;
if(mp[t]==0){
stk.push({1,t});
mp[t]++;
continue;
}
int sum=1;
while(!stk.empty()&&stk.top().second!=t){
auto [sz,val] = stk.top();
stk.pop();
mp[val]-=sz;
sum+=sz;
}
auto [sz,val] = stk.top();
stk.pop();
mp[val]-=sz;
sum+=sz;
mp[t]+=sum;
stk.push({sum,t});
}
vector<int>ans;
while(!stk.empty()){
auto [sz,val] = stk.top();
stk.pop();
while(sz--){
ans.push_back(val);
}
}
reverse(ans.begin(),ans.end());
for(auto it:ans){
cout<<it<<'\n';
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |