K.Doremy's IQ 2
1.1思路
很明显,最优的方案是先走负的再走正的,或者是先走正的再走负的,而且使用增加/减少智力的竞赛一定是不包含最终方案里的。利用双指针维护一段答案即可
#include<iostream>
#include<cstring>
#include<vector>
#include<map>
#include<cstdio>
#include<algorithm>
#include<string>
#include<string.h>
#include<queue>
#include<math.h>
#include<set>
#include<functional>
using namespace std;
inline int inc(int x,int v,int mod){x+=v;return x>=mod?x-mod:x;}//代替取模+
#define endl '\n'
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;
const int N = 7e6 + 10, M = 1e5 + 10;
inline int read()
{
int x=0,f=1;
char ch=getchar();
while(ch<'0'||ch>'9')
{
if(ch=='-')
f=-1;
ch=getchar();
}
while(ch>='0' && ch<='9')
x=x*10+ch-'0',ch=getchar();
return x*f;
}
int e[N],ne[N],h[M],w[N];
void solve()
{
int n;
cin >> n;
std::vector<int> arr(n + 1);
for(int i = 1; i <= n; i ++) cin >> arr[i];
int cnt = 1;
int ans = 0;
for(int i = 1; i <= n; i ++)
{
if(arr[i] < 0) continue;
if(arr[i] > n - i) break;
while(arr[cnt] < 0 && arr[i] - arr[cnt] > cnt - 1) cnt ++;
ans = max(ans,i - cnt + 1);
}
int idx = n;
for(int i = n; i >= 1; i --)
{
if(arr[i] > 0) continue;
if(arr[i] * -1 > i - 1) break;
while(arr[idx] > 0 && arr[idx] - arr[i] > n - idx) idx --;
ans = max(ans,idx - i + 1);
}
cout << ans << endl;
}
signed main()
{
//ios::sync_with_stdio(0);
//cin.tie(0);
int tt;
tt = read();
//tt = 1;
while(tt --)
{
solve();
}
}