• 【luogu P2251 质量检测】 题解


    也是一道ST表的板子题,很裸的RMQ问题,只需要在查询区间时处理一下下就好啦~

     1 #include <cstdio>
     2 #include <algorithm>
     3 using namespace std;
     4 const int maxn = 1000000 + 10;
     5 int st[maxn][21], a[maxn], ans[maxn];
     6 int n, m, i, j, left, right;
     7 int main()
     8 {
     9     scanf("%d%d", &n, &m);
    10     for(i = 1; i <= n; i++)
    11     {
    12         scanf("%d", &a[i]);
    13         st[i][0] = a[i];
    14     }
    15     
    16     for(j = 1; (1<<j) <= n; j++)
    17         for(i = 1; i <= n-(1<<j)+1; i++)
    18         st[i][j] = min(st[i][j-1],st[i+(1<<(j-1))][j-1]);
    19     
    20     right = m;
    21     for(i = 1; i <= n-m+1; i++)
    22     {
    23         j = 0;
    24         left = i;
    25         while((1<<(j+1)) <= (right-left+1)) j++;
    26         ans[i] = min(st[left][j],st[right-(1<<j)+1][j]);
    27         right++;
    28     }
    29     
    30     for(i = 1; i <= n-m+1; i++)
    31     printf("%d
    ",ans[i]);
    32     return 0;
    33 }

    隐约雷鸣,阴霾天空,但盼风雨来,能留你在此。

    隐约雷鸣,阴霾天空,即使天无雨,我亦留此地。

  • 相关阅读:
    [BZOJ3202][SDOI2013]项链
    Educational Codeforces Round 50
    [agc23E]Inversions
    [CF1016G]Appropriate Team
    [CF765F]Souvenirs
    [Luogu3733][HAOI2017]八纵八横
    [Luogu4609][FJOI2016]建筑师
    [BZOJ2159]Crash 的文明世界
    【学习笔记】Nim积
    PKUWC2020游记
  • 原文地址:https://www.cnblogs.com/MisakaAzusa/p/8471530.html
Copyright © 2020-2023  润新知