zoukankan      html  css  js  c++  java
  • 【luogu P3865 ST表】 模板

    跟忠诚是一样滴,不过是把min改成max就AC了。模板题。

     1 #include <cstdio> 
     2 #include <algorithm>
     3 using namespace std;
     4 const int maxn = 1000000;
     5 int st[maxn][21], a[maxn], ans[maxn];
     6 int i, j, n, m, 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] = max(st[i][j-1] , st[i + (1<< (j-1) )][j-1]);
    19     
    20     for(i = 1; i <= m; i++)
    21     {
    22         scanf("%d%d", &left, &right);
    23         j = 0;
    24         while((1<<(j+1)) <= (right-left+1)) j++;
    25         ans[i] = max(st[left][j],st[right-(1<<j)+1][j]);
    26     }
    27     
    28     for(i = 1; i <= m; i++)
    29     printf("%d
    ",ans[i]);
    30     return 0;
    31 }

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

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

  • 相关阅读:
    工厂模式
    dubbo
    WebSocket WebService
    消息中间
    原型模式
    ApiPost Apifox
    Future 的使用与源码解析
    JUC 线程池的使用与源码解析
    ReentrantLock 源码解析
    CountDownLatch 的使用与源码解析
  • 原文地址:https://www.cnblogs.com/MisakaAzusa/p/8471467.html
Copyright © 2011-2022 走看看