Source Code
/*
+---------------------------------------------+
|                                             |
|  Copytright, MinaMagdy, 20/04/2022 (20:37)  |
|                                             |
+---------------------------------------------+
*/
/*
        .@@@@@@@@   @@@                                              @@       @@
    ,@@@@@@     @@ .@@@      @@    @@@        @@@%@@@@.   @@@        @@  @@  @@@@/      @@@
    /& @@@@    @@@ *@@@     @@@#  @@@&@@@    @@@@@@@#&@@ @@@%&,      @@ @@@@  @@@@    @@@&
        @@@  .@@@   /@%@     @@@  @@@@   @@& .@@@         @@&&&@      @@ @@@@  >@@@@ @@@@
        %@@@@@@&     /&&&     %@&  @&@     @& @&@&         &&@#%@%.   &@@ &@&#   %@@@@@@
        @@@@@        /@&%@%&@@@&@  @&&    ,@@ @@&&@@&@@@   &@@ /@@&/  @@, @@@/    %@@@@
        @@@.         *@@@@#,  @@@  @@@   ,@@  @@@.         @@@   @@@@@@@  %@@/   @@@@@@%
        @@@          *@@%     @@@   @@@@@@#    @@@@@@@@@@  @@@    ,@@@@    @@& .@@@  @@@@
        &@@,          @@%      @@                          @@@                 @@      @@@
                                                            &*
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

using namespace __gnu_cxx;
using namespace std;
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ceil(w, m) (((w) / (m)) + ((w) % (m) ? 1 : 0))
#define endl "\n"
#define NumOfDig(w) log10(w) + 1
#define MOD 1000000007
#define INF 2000000000
#define Time cerr << "Time Taken: " << (float)clock() / CLOCKS_PER_SEC << " Secs" << "\n";
#define EPS 1e-9
#define PI1 acos(-1)
#define PI2 3.141592653
#define all(s) s.begin(), s.end()
#define rall(s) s.rbegin(), s.rend()
#define sz(x) int(x.size())
#define init(x, c) memset(x, c, sizeof(x))
#define getlineCh(s, c) getline(cin >> ws, s, c)
// #define TC int testcases = 1; cin >> testcases; for (ll test = 1; test <= testcases; test++)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

/**
 * @author MiinaMagdy
 * @remark Time limit - memory limit (EFFICIENCY)
 * @remark (OVERFLOW) long long
 * @remark freopen() file
 * @remark (CORNER) test case
 * @remark division by (ZERO) || Out of array's (RANGE)
 * @remark use logarithm if you want to compare two products
 * @remark Brute Force means try all possible solutions remember (MAXPOINT - CodeChef)
 * @remark '/0' takes all input in getline string
 */

void phoenix()
{
    ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
    #endif
    Time
}

ll BS(vector<pair<ll, ll>>& vec, ll x) {
    ll l = 0, r = sz(vec) - 1, best = -1;
    while (l <= r) {
        ll mid = l + (r - l) / 2;
        (x <= vec[mid].first ? best = vec[mid].second, r = mid - 1 : l = mid + 1);
    }
    return best;
}

int main(void)
{
    phoenix();
    int testcase = 1;
    cin >> testcase;
    while (testcase--)
    {
        int n;
        cin >> n;
        ll arr[n];
        vector<pair<ll, ll>> vec(n);
        for (ll i = 0; i < n && cin >> arr[i]; i++) {
            vec[i] = {arr[i] + i, i};
        }
        sort(all(vec), [](pair<ll, ll> a, pair<ll, ll> b) {
            if (a.first == b.first) return a.second < b.second;
            return a.first < b.first;
        });
        for (ll i = n - 2; i >= 0; i--) {
            vec[i].second = min(vec[i].second, vec[i + 1].second);
        }
        for (ll i = 0; i < n; i++) {
            cout << BS(vec, i - arr[i]) + 1 << " ";
        }
        cout << endl;
    }
    return 0;
}
Copy
Easy challenge? MiinaMagdy
GNU G++17
39 ms
432 KB
Wrong Answer