zoukankan      html  css  js  c++  java
  • Luogu1816 忠诚 (ST表)

    继续复习模板,加深理解ing...

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <cmath>
    #define R(a,b,c) for(register int  a = (b); a <= (c); ++ a)
    #define nR(a,b,c) for(register int  a = (b); a >= (c); -- a)
    #define Max(a,b) ((a) > (b) ? (a) : (b))
    #define Min(a,b) ((a) < (b) ? (a) : (b))
    #define Fill(a,b) memset(a, b, sizeof(a))
    #define Swap(a,b) a^=b^=a^=b
    #define ll long long
    #define ON_DEBUG
    
    #ifdef ON_DEBUG
    
    #define D_e_Line printf("
    
    ----------
    
    ")
    #define D_e(x)  cout << #x << " = " << x << endl
    #define Pause() system("pause")
    
    #else
    
    #define D_e_Line ;
    
    #endif
    
    struct ios{
        template<typename ATP>ios& operator >> (ATP &x){
            x = 0; int f = 1; char c;
            for(c = getchar(); c < '0' || c > '9'; c = getchar()) if(c == '-')  f = -1;
            while(c >= '0' && c <= '9') x = x * 10 + (c ^ '0'), c = getchar();
            x*= f;
            return *this;
        }
    }io;
    using namespace std;
    
    const int N = 100007;
    
    int n;
    
    int f[N][21];
    
    inline void ST_Init(){
    	R(j,1,20){
    		R(i,1,n + 1 - (1 << j)){
    			f[i][j] = Min(f[i][j - 1], f[i + (1 << (j - 1))][j - 1]);
    		}
    	}
    }
    int lg[N];
    inline int Query(int l, int r){
    	int k = lg[r - l + 1] - 1;
    	return Min(f[l][k], f[r - (1 << k) + 1][k]);
    }
    
    int main(){
    	int Que;
    	io >> n >> Que;
    	R(i,1,n){
    		io >> f[i][0];
    		// log(n) + 1
    		lg[i] = lg[i - 1] + ((1 << lg[i - 1]) == i);
    	}
    	
    	ST_Init();
    	
    	while(Que--){
    		int l, r;
    		io >> l >> r;
    		printf("%d ", Query(l, r));
    	}
    	
    	return 0;
    }
    

  • 相关阅读:
    面试题
    网络编程
    python_控制台输出带颜色的文字方法
    httpie 101
    JSON Web Signature 规范解析
    Kong 系列 -- Kong 101
    关于过渡机制的一点理解
    XAML概览 1(译自JeremyBytes.com)
    awk与sed简明教程
    Connection failed: NT_STATUS_ACCOUNT_RESTRICTION
  • 原文地址:https://www.cnblogs.com/bingoyes/p/11218739.html
Copyright © 2011-2022 走看看