Source Code
#include<bits/stdc++.h>
using namespace std;
#define all(v) v.begin(),v.end()
#define pb push_back
#define pp pop_back
#define f first
#define s second
typedef long long ll;
typedef long double ld;
ld pi=acos(-1);
ll mod=1e9+7;
void fast()
{
	cin.sync_with_stdio(0) ;
		cin.tie(0) ;
		cout.tie(0);
}
bool cmp(pair<int,int>a,pair<int,int>b)
{
	if(a.first==b.first)
		return b.second>a.second;
	return a.first<b.first;
}
long long gcd(long long a,long long b)
{
	if(a==0)
		return b;
	return gcd(b%a,a);
}
long long fp(ll b, ll p)
{
    ll ans = 1;
    while (p)
    {
        if (p % 2)
        {
            ans = (ans * b)%mod;
        }
        b = (b * b)%mod;
        p /= 2;
    }
    return ans%mod;

}
bool isp(long long n)
{
	if(n==1)
		return false;
	if(n==2||n==3)
		return true;
	if(n%2==0||n%3==0)
		return false;
	for(long long i=5;i*i<=n;i+=2)
		if(n%i==0)
			return false;
	return true;
}
long long fc(long long n)
{
	if(n==0)
		return 1;
	long long s=1;
	for(int i=1;i<=n;i++)
		s=s*i;
	return s;
}
ll lcm(ll a,ll b)
{
	ll m=gcd(a,b);
	m=a/m*b;
	return m;
}
#define MAX 10000001
ll primes[MAX] ;
bool sieve[MAX] ;
int l;
void genPrimes()
{
    primes[l++] = 2 ;
    long long i,j ;
    for(j=4;j<MAX;j+=2)               sieve[j] = true ;
    for(i=3;i<MAX;i+=2)
    {
        if(sieve[i]==false)
        {
            primes[l++] = i ;
            for(j=i*i;j<MAX;j+=i)   sieve[j] = true ;
        }
    }
}
void Nn(ll n)
{
	map<int,int>mp;
	int od=0,ev=0;
    ll tmp = sqrt(n),i ;
    ll j = 0 ;
    ll p[1000];
    memset(p,0,sizeof(p));
    for(i=0;primes[i]<=tmp;i++)
        if(n % primes[i] == 0)
        {
            int cnt =  0 ;
            while(n % primes[i] == 0)
            {
                cnt ++ ;
                //cout<<"    "<<primes[i]<<"\n";
                n /=primes[i] ;
            }
            if(cnt%2)
            	od++;
            else
            	ev++;
            p[j++]=primes[i] ;
            mp[primes[i]]=cnt;
            tmp = sqrt(n) ;
        }
    if(n>1) {
    	p[j++]=n;
    	od++;
    //	cout<<"    "<<n<<"\n";
    	mp[n]++;
    }
    sort(p,p+j);
    for(int i=0;i<j;i++)
    	cout<<p[i]<<'^'<<mp[p[i]]<<" ";
   // sort(p,p+j);

}
/*ll c=1e9+7;
ll modd(ll a,ll b)
{
	ll rs=0;
	a=a%c;
	while(b)
	{
		if(b%2)
			rs=(rs+a)%c;
		a=(2*a)%c;
		b/=2;
	}
	return rs;
}*/
int main() {
    fast();
	int tt=1;
	cin>>tt;
	for(int ts=1;ts<=tt;ts++)
	{
		int n;
		cin>>n;
		vector<ll>a,b;
		map<ll,int>mp;
		ll x,c;
		for(int i=0;i<n;i++)
		{
			cin>>x;
			a.pb(i+1-x);
			if(mp[i+1+x]==0)
				{
				mp[i+1+x]=i+1;
				}
			else
			{
				mp[i+1+x]=min(mp[i+1+x],i+1);
			}
			if(b.empty())
			{
				b.pb(i+1+x);
				c=i+1+x;
			}
			else
			{
				if(i+1+x>c)
				{
					b.pb(x+1+i);
					c=i+1+x;
				}
			}
		}
		for(int i=0;i<n;i++)
		{
			ll m=a[i];
			auto it=upper_bound(all(b),m);
			if(it==b.end())
				cout<<"-1";
			else
				cout<<mp[*it];
			if(i!=n-1)
				cout<<" ";
		}
		cout<<"\n";
	}
	return 0;
}
Copy
Easy challenge? sameh58
GNU G++17
136 ms
11.5 MB
Wrong Answer