What a strange, inexplicable wa ...
Two things like a monotone queue maintenance on it.
Dig a hole first.
1 /**************************************************************2 problem:20963 User:rausen4 language:c++5 Result:wrong_answer6 ****************************************************************/7 8#include <cstdio>9#include <algorithm>Ten One using namespacestd; A Const intN =3000005; - Const intMaxLen = A* N + the; - the intN, k, ans =1; - intA[n], q[2][n], l[2], r[2]; - CharBuf[maxlen], *c =buf; - intLen; + -InlineintRead () { + intx =0, SGN =1; A while(*c <'0'||'9'< *c) { at if(*c = ='-') SGN =-1; -++C; - } - while('0'<= *c && *c <='9') -x = x *Ten+ *c-'0', ++C; - returnSGN *x; in } - toInlinevoidPop_tail_max (inti) { + while(l[0] <= r[0] && a[q[0][r[0]] <=A[i]) ---r[0]; theq[0][++r[0]] =i; * } $ Panax NotoginsengInlinevoidPop_tail_min (inti) { - while(l[1] <= r[1] && a[q[1][r[1]] >=A[i]) the--r[1]; +q[1][++r[1]] =i; A } the + intMain () { - inti, TMP; $Len = Fread (c,1, MaxLen, stdin); $Buf[len] =' /'; -K = read (), n =read (); - for(i =1; I <= N; ++i) theA[i] =read (); -l[0] = l[1] =1;Wuyi for(i =1; I <= N; ++i) { the pop_tail_min (i); - Pop_tail_max (i); Wu while(a[q[0][l[0]]-a[q[1][l[1]] >k) - if(q[0][l[0]] < q[1][l[1]]) TMP = q[0][l[0]++] +1; About ElseTMP = q[1][l[1]++] +1; $ans = max (ans, i-tmp +1); - } -printf"%d\n", ans); - return 0; A}View Code
BZOJ2096 [Poi2010]pilots