Source Code
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;

#define forr(_a, _b, _c) for(_a = (_b); _a <= (_c); ++_a)
#define ford(_a, _b, _c) for(_a = (_b) + 1; _a --> (_c);)
#define forf(_a, _b, _c) for(_a = (_b); _a < (_c); ++_a)
#define mp make_pair
#define fi first
#define se second
#define vi vector
#define sz(_v) _v.begin(), _v.end()
#define mask(_x) (1ll << (_x))
#define bit(_x,_y) (((_x) >> (_y)) & 1)

string yes[2] = {"NO\n","YES\n"};
const ld eps = ld(1e-7);
const ll inf = ll(1e16) + 1;
const ll mod = ll(1e9) + 7;

const int N = 2e5 + 5;
int n, i, a[N], f[N], l, r, m;
pair<int,int> b[N];

void solve() {
	cin >> n;
	forr(i,1,n) {
		cin >> a[i];
		b[i].fi = a[i] + i;
		b[i].se = i;
	}
	sort(b + 1,b + 1 + n);
	f[n + 1] = (mod << 1);
	ford(i,n,1) {
		f[i] = min(f[i + 1],b[i].se);
	}
	forr(i,1,n) {
		l = 1;
		r = n;
		while(l <= r) {
			m = (l + r) >> 1;
			if(i - a[i] <= b[m].fi) r = m - 1;
			else l = m + 1;
		}
		if(i - a[i] <= b[l].fi) cout << f[l] << " ";
		else cout << "-1 ";
	}
	cout << "\n";
}

void precalc() {
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	#ifdef umf
		freopen("test.inp","r",stdin);
		freopen("test.out","w",stdout);
	#endif

	int tc = 1;
	cin >> tc;
	precalc();
	while(tc --> 0) {
		solve();
	}

	return 0;
}
Copy
Easy challenge? thqdothabit
GNU G++17
21 ms
996 KB
Wrong Answer