题解

1 条题解

  • 0
    @ 2020-09-12 20:58:41
    #include<bits/stdc++.h>
    using namespace std;
    const int N = 1e6 + 5, INF = 1e9 + 5;
    int f[N], n, h[N], q, k, s[N], ops[N], l, r, minn;
    int main(){
        //freopen("t4.in","r",stdin);   freopen("t4.out","w",stdout);
        scanf("%d", &n);
        for(int i = 1; i <= n; i ++) scanf("%d", &h[i]);
        scanf("%d", &q);
        for(int t = 1; t <= q; t ++){
            scanf("%d", &k);
            l = r = 1;
            s[1] = 1; f[1] = 0;
            for(int i = 2; i <= n; i ++){
                while(l <= r && i - s[l] > k) l ++;
                if(h[i] < h[s[l]]) f[i] = f[s[l]];
                else f[i] = f[s[l]] + 1;
                while(l <= r && (f[i] < f[s[r]] || (f[i] == f[s[r]] && h[i] > h[s[r]]))) r --;
                s[++ r] = i;
            }   
    //      for(int i = 1; i <= n; i ++) cout<<f[i]<<" ";
    //      cout<<"\n";
            printf("%d\n", f[n]);    
        }
        fclose(stdin); fclose(stdout);
        return 0;
    }
    /*
    9
    4 6 3 6 3 7 2 6 5 
    2
    2
    5
    */
    
  • 1

信息

难度
8
分类
(无)
标签
递交数
12
已通过
5
通过率
42%
上传者