问题 - E - 代码强制 (codeforces.com)
#include <iostream>
#include <bits/stdc++.h>
#include <cstring>
#include <vector>
#include <unordered_map>
#include <queue>
#include <set>
#define int long long
#include <algorithm>
#define x first
#define y second
#define pb emplace_back
#define fu(i,a,b) for(int i=a;i<=b; ++ i)
#define fd(i,a,b) for(int i=a;i>=b; -- i)
#define endl '\n'
#define ms(x,y) memset(x,y,sizeof x)
#define ios ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<vector<LL>> VVL;
typedef vector<vector<int>> VVI;
typedef vector<LL> VL;
typedef vector<int> VI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef vector<PII> VPII;
typedef pair<PII,int> PIII;
typedef pair<double,double> PDD;
typedef pair<double,int> PDI;
typedef pair<char,int> PCI;
typedef pair<string,int> PSI;
typedef pair<int,string> PIS;
typedef pair<int,char> PIC;
typedef pair<LL,LL> PLL;
typedef __int128 i128;
typedef unsigned long long ULL;
const int N =3e5+ 10,M = N *25,base =400 ,INF = 0x3f3f3f3f,P = 131;
const double eps = 1e-8;
const int mod = 998244353;
const LL LNF=(LL) INF * INF;
int n;
inline void solve()
{
cin >> n;
VI a(n+5),b(n+5),mx(n+5),ds(n+5);
fu(i,1,n)cin >> a[i];
b[n + 1 ] = 0;
fd(i,n,1) // 预处理 每个点 能否跳到 n+1,-1不能跳到,否则为跳到n+1的步数
{
if(i + a[i] > n || b[i + a[i] + 1 ] == -1 ) b[i] = -1 ;
else b[i] = b[i + a[i] + 1 ] + 1 ;
}
mx[n + 1 ] = ds[n + 1 ] = 0;
fd(i,n,1)
mx[i] = max(mx[i+1],b[i]);
// 或者 当前点和后面一个点合并, a[i] = a[i+ 1] + 1
// 不修改的情况下 ,当前这个点后面最多可以分成几段
// mx 中间数组,不改变现有的 段数 的修改次数
fd(i,n,1)
if(b[i] >= 0) ds[i] = b[i]; // 能跳到终点 肯定是 不修改答案最小
// 当前点 不能到n+1
else ds[i] = mx[i+1] + 1; // 当前点i修改 为 1 ,当前段数 = 后面 一个的段数 + 1
fd(i,n,1)
if(i+a[i] <= n && b[i] == -1 ) // 跳一步合法,但是不能到n+1
ds[i] = max(ds[i],ds[i + a[i] + 1 ] + 1 );
// 使用一次修改 修改第 i + a[i] + 1 为后面数的个数
fu(i,1,n-1)
{
if(a[i] == b[i+1]) cout << "0 ";
else if(b[i + 1] >= 0 || ds[i + 1 ] >= a[i]) cout << "1 ";
// 后面一个点能 跳到 终点 ,后一个点 能分成的段数 多余 当前数,a[i] 可以改成1 或者ds[i+1]
else cout << "2 ";
// 修改 i 和 i+ 1 ,a[i]修改为1,a[i+1]修改 后面还剩多少个数,每个成为一段
}
cout << endl;
}
signed main()
{
// freopen("1.txt","r",stdin);
// #define int long long
// init(N-1);
ios
// cout << fixed<<setprecision(2);
int t=1;
cin>>t;
int now = 1;
while(t -- )
{
// cout<<"Case ";
// cout<<"Case #";
// cout<<"Scenario #";
// cout<< now ++ <<": ";
// cout<< now ++ <<": \n";
solve();
}
return 0;
}