反向遍历
C++ 代码
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
#include<bits/stdc++.h>
const int N = 2e5;
int a[N],b[N];
int main()
{
int t;
cin >> t;
while(t--)
{
int n;
cin >> n;
for (int i = 0; i < n; i ++ )
cin >> a[i];
int cnt=0;
for (int i = n-1; i>=0; i -- )
{
cnt=max(cnt,a[i]);
if(cnt>0)
b[i]=1;
else
b[i]=0;
cnt--;
}
for (int i = 0; i < n; i ++ )
cout << b[i]<<' ';
cout << endl;
}
}