"Codeforces 91B" Queue

Source: Internet
Author: User

"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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.