#include <bits/stdc++.h>
#define fori(i,a,b) for(int i = a;i <= b;i ++)
#define fore(i,a,b) for(int i = a;i >= b;i --)
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define bit(n,i) ((n >> i) & 1)
using namespace std;
typedef long long ll;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l,int r)
{
return l + rng() % (r - l + 1);
}
int const N = 2e5 + 10;
int a[N],dp[N];
void speed()
{
ios_base::sync_with_stdio(NULL);
cin.tie(NULL);
cout.tie(NULL);
}
int t,n;
void solve()
{
cin >> n;
fori(i,1,n)
{
cin >> a[i];
dp[i] = 0;
}
ll res(0);
fori(i,1,n)
{
ll c = a[i] - dp[i] - 1;
res += max(0ll,c);
for(int j = i + 2;j <= min(n,a[i] + i);j ++)
dp[j] += 1;
if(i < n and c < 0) dp[i + 1] -= c;
}
cout << res;
}
int main()
{
if(fopen("task.inp","r"))
{
freopen("task.inp","r",stdin);
freopen("task.out","w",stdout);
}
cin >> t;
while(t--)
{
solve();
cout << "\n";
}
return 0;
}
450. Delete Node in a BST | 445. Add Two Numbers II |
442. Find All Duplicates in an Array | 437. Path Sum III |
436. Find Right Interval | 435. Non-overlapping Intervals |
406. Queue Reconstruction by Height | 380. Insert Delete GetRandom O(1) |
332. Reconstruct Itinerary | 368. Largest Divisible Subset |
377. Combination Sum IV | 322. Coin Change |
307. Range Sum Query - Mutable | 287. Find the Duplicate Number |
279. Perfect Squares | 275. H-Index II |
274. H-Index | 260. Single Number III |
240. Search a 2D Matrix II | 238. Product of Array Except Self |
229. Majority Element II | 222. Count Complete Tree Nodes |
215. Kth Largest Element in an Array | 198. House Robber |
153. Find Minimum in Rotated Sorted Array | 150. Evaluate Reverse Polish Notation |
144. Binary Tree Preorder Traversal | 137. Single Number II |
130. Surrounded Regions | 129. Sum Root to Leaf Numbers |