Source Code
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
#define x           first
#define y           second
#define all(v)      v.begin(),v.end()
#define clr(v,d)    memset(v,d,sizeof(v));

const int N = 2e5 + 10;

const ll mod = 1e9 + 7;

int n , a[N] , b[N];

int main()
{
    cin.tie(0);
    cin.sync_with_stdio(0);

    int t = 1 ;
    cin >> t ;
    while(t--)
    {
        cin >> n ;
        for (int i = 0; i < n; ++i) {
            cin >> a[i] ;
            b[i] =  1 + i + a[i] ;
            if(i) b[i] = max(b[i] , b [i-1]) ;
        }

        for (int i = 0; i < n; ++i) {
            int l = 0 , r = n-1 , an = -2 , md ;

            while(l <= r)
            {
                md = (l + r) / 2;
                if(b[md] >= i+1-a[i]) an = md , r = md-1;
                else l= md+1;
            }

            cout << ++an << " " ;
        }
        cout << "\n" ;
    }

    return 0;
}
Copy
Easy challenge? MuhammadHassan
GNU G++17
68 ms
3.1 MB
Accepted