Submission #941394

#TimeUsernameProblemLanguageResultExecution timeMemory
941394ReverberateStone Arranging 2 (JOI23_ho_t1)C++14
100 / 100
208 ms19908 KiB
#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)

Main.cpp: In function 'int main()':
Main.cpp:27:9: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   27 |    auto [sz,val] = stk.top();
      |         ^
Main.cpp:32:8: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   32 |   auto [sz,val] = stk.top();
      |        ^
Main.cpp:41:8: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   41 |   auto [sz,val] = stk.top();
      |        ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...