Loj the wrong side of the problem. Go to Bzoj and see QWQ.
Observed \ (\sqrt{|i-j|} \) is only a \ (\sqrt{n}\) level, and then it's obvious, RMQ.
#include <iostream>#include <cstdio>using namespaceStdintN, a[100005], st[100005][ +], mlg[100005];intGetmax (intLintR) {if(L>r)return -0x3f3f3f3f;intP=mlg[r-l+1];returnMax (St[l][p], st[r-(1<<P)+1][p]);}intMain () {cin>>n; for(intI=1; i<=n; i++) {scanf ("%d", &a[i]); st[i][0] = A[i]; } for(intI=2; i<=n; i++) Mlg[i] = mlg[i>>1] +1; for(intI=1; i<= -; i++) for(intj=1; J<=n && j+ (1<< (i-1)) <=n; J + +) St[j][i] = max (st[j][i-1], st[j+ (1<< (i-1))][i-1]); for(intI=1; i<=n; i++) {intP=a[i]; for(intx=1; ; X + +) {p = max (P, Getmax (Max (i-x*x,1), I-(x-1) * (x-1)-1) +x);if(i-x*x<=1) Break; } for(intx=1; ; X + +) {p = max (P, Getmax (i+ (x-1) * (x-1)+1, Min (i+x*x, N)) +x);if(i+x*x>=n) Break; } printf ("%d\n", P-a[i]); }return 0;}
loj2074"jsoi2016" Lighthouse