模板汇总——ST(暂)

int Log[N];
struct ST {
    int dp[N][20], a[N];
    void init(int n) {
        for(int i = -(Log[0]=-1); i < N; i++)
            Log[i] = Log[i - 1] + ((i & (i - 1)) == 0);
        for(int i = 1; i <= n; ++i) dp[i][0] = a[i];
        for(int j = 1; j <= Log[n]; j++)
            for(int i = 1; i+(1<<j)-1 <= n; i++)
                dp[i][j] = __gcd(dp[i][j-1], dp[i+(1<<(j-1))][j-1]);
    }
    int Query(int l, int r) {
        int k = Log[r - l + 1];
        return __gcd(dp[l][k], dp[r-(1<<k)+1][k]);
    }
}st;
View Code

 

posted @ 2019-05-08 22:01  Schenker  阅读(108)  评论(0编辑  收藏  举报