"Link" I am the link, point me:)
Test instructions
Exercises
For each I, a two-point method is used to find out where Y is located J.
You can ask for it.
Suppose now two points to the position of mid.
Then use a RMQ to find out mid. n the minimum value of this section, temp.
See if Temp meets <a[i]
If satisfied, then very good, we let l=mid+1, and then try to go to the right a little better.
Otherwise, the explanation is too right, then left a point r = mid-1
Initial value L = I,r = N.
Code
#include <bits/stdc++.h> #define REP1 (I,A,B) for (int i = a;i <= b;i++) #define REP2 (I,A,B) for (int i = A;i >= b;i--) #define LL long longusing namespace Std;const int N = 1e5;int n;int a[n+10];int mi[n+10][17+5];int get_mi (int l,int R) {int len = log2 (r-l+1); return min (mi[l][len],mi[r-(1<<len) +1][len]);} int main () {//freopen ("D:\\rush.txt", "R", stdin); scanf ("%d", &n); REP1 (i,1,n) scanf ("%d", &a[i]); REP1 (i,1,n) mi[i][0] = A[i]; REP1 (l,1,17) rep1 (i,1,n) {int J = i+ (1<<l)-1; if (j>n) break; Mi[i][l] = min (mi[i][l-1],mi[i+ (1<< (L-1))][l-1]); } rep1 (i,1,n) {int L = I,r = N,temp =-1; while (l<=r) {int mid = (l+r) >>1; if (Get_mi (mid,n) <a[i]) {temp = mid; L = mid + 1; }else r = mid-1; } if (temp==-1) {printf ("-1"); }else{printf ("%d", temp-I-1); } if (I==n) puts (""); else Putchar ("); } return 0;}
"Codeforces 91B" Queue