hdu6098[RMQ+筛法] 2017多校6

/*hdu6098[RMQ+筛法] 2017多校6*/
#include <bits/stdc++.h>
using namespace std;
int T, n, st[100005][20], len[100005], a[100005];
void st_init() {
    len[0] = -1;
    for (int i = 1; i <= n; i++) {
        st[i][0] = a[i];
        len[i] = (i & (i - 1)) == 0 ? len[i - 1] + 1 : len[i - 1];
    }
    for (int j = 1; j <= len[n]; j++) {
        for (int i = 1; i + (1 << j) - 1 <= n; i++) {
            st[i][j] = max(st[i][j - 1], st[i + (1 << (j - 1))][j - 1]);
        }
    }
}
int query(int l, int r) {
    int k = len[r - l + 1];
    return max(st[l][k], st[r - (1 << k) + 1][k]);
}
int main() {
    scanf("%d", &T);
    while (T--) {
        scanf("%d", &n);
        for (int i = 1; i <= n; i++) {
            scanf("%d", &a[i]);
        }
        st_init();
        for (int i = 2; i <= n; i++) {
            int ans = 0;
            for (int j = 0; j < n; j += i) {
                //cout<<"["<<j+1<<", "<<min(n, j + i - 1)<<"]\n";
                ans = max(query(j + 1, min(n, j + i - 1)), ans);
            }
            if(i>2) printf(" ");
            printf("%d", ans);
        }
        puts("");
    }
    return 0;
}

 

posted @ 2017-08-13 12:54 UnderSilence 阅读(...) 评论(...) 编辑 收藏