想来也是个裸体 关键是我WA了一次 脑残了下 特地将WA的代码注释进去 以警示自己
POP完了过后队列的开始是 q1.front()+1 或者 q2.front()+1
其实相当水 进来最舒服的一道题
#include<cstdio>
#include<cstring>
#include<deque>
#include<queue>
#include<algorithm>
#define MAXN 100000
int A[MAXN+10];
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
deque <int> q1, q2; // q1 递增 q2 递减
int main()
{
int n, l, r;
while(~scanf("%d%d%d", &n, &l, &r))
{
q1.clear(); q2.clear();
int ans = 0, F = 0;
for(int i = 1; i <= n; i++) scanf("%d", &A[i]);
for(int i = 1; i <= n; i++)
{
while(!q1.empty() && A[q1.back()] < A[i]) q1.pop_back();
while(!q2.empty() && A[q2.back()] > A[i]) q2.pop_back();
q1.push_back(i); q2.push_back(i);
while(!q1.empty() && !q2.empty() && A[q1.front()] - A[q2.front()] > r )
if(q1.front() < q2.front()) {
F = q1.front();
q1.pop_front();
}
else {
F = q2.front();
q2.pop_front();
}
if(!q1.empty() && !q2.empty() && A[q1.front()] - A[q2.front()] >= l)
ans = max(i - F, ans);
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
while(!q1.empty() && !q2.empty() && A[q1.front()] - A[q2.front()] > r )
if(q1.front() < q2.front()) q1.pop_front();
else q2.pop_front();
if(!q1.empty() && !q2.empty() && A[q1.front()] - A[q2.front()] >= l)
ans = max(i - min(q1.front(), q2.front())+1, ans);
*/
}
printf("%d\n", ans);
}
}