Submission #774636

#TimeUsernameProblemLanguageResultExecution timeMemory
774636tpd2kStone Arranging 2 (JOI23_ho_t1)C++14
100 / 100
420 ms33624 KiB
// teddybear's code
// the one who loves NBP
// noe the second
// goal: 0 / 8
// get medal in APIO (like TKN)
//#pragma GCC optimize("O3,unroll-loops")
//#pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")

// prob: 
#include <bits/stdc++.h>
using namespace std;

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")

#define FOR(i,n) for (int i = 0; i<n; i++)
using ll = long long;
using ull = unsigned long long;
ll n,m,t;
ll cnt = 0;
const int maxn = 1e5;
const ll mod = 1e9 + 7;
#define Y "YES"
#define N "NO"
ll a[2 * maxn + 5];
bool visited[1005][1005];
int dist[1005][1005];
int w,h;
int fx[4] = {-1, 1, 0, 0};
int fy[4] = {0, 0, -1, 1};
queue <pair<int,int>> q;

ll b[2 * maxn + 5];

void solve()
{
	map <int,int> mp;
	map <int,int> fir, las;
	cin >> n;
	for (int i = 1; i<=n; i++)
	{
		cin >> a[i];
		mp[a[i]]++;
		fir[a[i]] = 1e9;
		fir[a[i]] = min(i, fir[a[i]]);
		las[a[i]] = max(i, las[a[i]]);
	}	
	/*for (int i = 1; i<=n; i++)
	{
		cout << b[i] << '\n';
	}*/
	
	int tmp = 1;
	while (tmp <= n)
	{
		if (mp[a[tmp]] == 1)
		{
			b[tmp] = a[tmp];
			mp[a[tmp]]--;
			tmp++;
			continue;
		}
		else
		{
			ll en = las[a[tmp]];
			ll z = a[tmp];
			b[tmp] = a[tmp];
			mp[a[tmp]]--;
			tmp++;
			while (tmp <= en)
			{
				mp[a[tmp]]--;
				b[tmp] = z;
				tmp++;
			}
		}
	}
	
	for (int i = 1; i<=n; i++)
	{
		cout << b[i] << '\n';
	}
	
}

void init()
{
 	int te = 1; //cin >> te;
 	while (te--)
 	{
 	 	  solve();
 	}
}

void preprocess()
{

}


int main()
{
 	ios_base::sync_with_stdio(false);
 	cin.tie(NULL);
    //cin.tie(0); cout.tie(0);
    //freopen(".inp", "r", stdin);
    //freopen(".out", "w", stdout);
 	init();
 	preprocess();
 	//solve();
 	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...