Submission #1336138

#TimeUsernameProblemLanguageResultExecution timeMemory
1336138blackscreen1Stone Arranging 2 (JOI23_ho_t1)C++20
100 / 100
70 ms23012 KiB
#include <bits//stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<long long, null_type, less<long long>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_set;
typedef tree<long long, null_type, less_equal<long long>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_multiset;
#define ll long long
#define iloop(m, h) for (auto i = m; i != h; i += (m < h ? 1 : -1))
#define jloop(m, h) for (auto j = m; j != h; j += (m < h ? 1 : -1))
#define kloop(m, h) for (auto k = m; k != h; k += (m < h ? 1 : -1))
#define lloop(m, h) for (auto l = m; l != h; l += (m < h ? 1 : -1))
#define pll pair<ll, ll>
#define INF 1000000000000000
#define MOD1 1000000007
#define MOD2 998244353
#define MOD3 1000000009
ll n, a, dis = 0;
gp_hash_table<ll, ll> mp;
vector<pll> st;
pll tmp;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n;
	st.push_back({-1, -1});
	iloop(0, n) {
		cin >> a;
		if (mp[a] == 0) {
			st.push_back({i, a});
			mp[a]++;
			dis++;
		}
		else {
			while (st.back().second != a) {
				tmp = st.back();
				st.pop_back();
				mp[tmp.second] -= tmp.first - st.back().first;
				if (mp[tmp.second] == 0) dis--;
			}
			mp[a] += i - st.back().first;
			st.back().first = i;
		}
	}
	vector<ll> res;
	while (st.size() > 1) {
		tmp = st.back();
		st.pop_back();
		iloop(0, tmp.first - st.back().first) res.push_back(tmp.second);
	}
	while (res.size()) {cout << res.back() << "\n"; res.pop_back();}
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...