Source Code
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
#define sz(s) (int)(s.size())
#define all(v) v.begin(),v.end()
#define clr(d,v) memset(d,v,sizeof(d))
#define ll long long
#define ld long double
#define ull unsigned long long
int dx[] = { -1, 0, 1, 0, 1, -1, 1, -1 };
int dy[] = { 0, 1, 0, -1, -1, 1, 1, -1 };
ll gcd(ll x, ll y) { return(!y) ? x : gcd(y, x % y); }
ll lcm(ll x, ll y) { return((x / gcd(x, y)) * y); }
void file()
{
    std::ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
}

int main()
{
    file();
    int t;
    cin >> t;
    while (t--)
    {
        priority_queue<pair<int, int>>pq;
        int n;
        cin >> n;
        vector<int>v(n), ans(n,-1);
        for (int i = 0; i< n; i++)
        {
            cin >> v[i];
            pq.push({ v[i] - i,i });
            

        }
        for (int i = 0; i < n; i++)
        {
            while (!pq.empty() && pq.top().first >= -(v[i] + i))
            {
                ans[pq.top().second] = i + 1;
                pq.pop();
            }

        }
        for (auto it : ans)cout << it << " ";
        cout << "\n";
    }
}
Copy
Easy challenge? Abo_Samrah
GNU G++17
114 ms
4.9 MB
Accepted