Source Code
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long long ll;
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	int t;
	cin >> t;
	while (t--)
	{
		ll n;
		cin >> n;
		vector<ll> a(n + 1);
		multiset<pair<ll, ll>> s;
		for (int i = 1; i <= n; i++)
		{
			cin >> a[i];
			s.insert({i - a[i], i});
		}

		map<ll, ll> ans;
		for (int i = 1; i <= n; i++)
		{
			ll x = a[i] + i;
			while (s.size())
			{
				pair<ll, ll> y = *s.begin();
				if (x >= y.F)
				{
					ans[y.S] = i;
					s.erase(s.begin());
				}
				else
					break;
			}
		}

		for (int i = 1; i <= n; i++)
		{
			if (!ans[i])
				cout << "-1 ";
			else
				cout << ans[i] << " ";
		}
		cout << "\n";
	}

	return 0;
}
Copy
Easy challenge? Yamanabdullah1
GNU G++17
617 ms
27.4 MB
Accepted