首页 > 代码库 > [vijos1514]天才的记忆

[vijos1514]天才的记忆

ST表模板题目

#include <cstdio>#include <cmath>#include <algorithm>using namespace std;int n,m,Maxsum[200005][20];int main(){    scanf("%d",&n);    for(int i=1;i<=n;i++){        scanf("%d",&Maxsum[i][0]);    }    int fuck = log(n) / log(2);    for(int j=1;j<=fuck;j++)        for(int i=1;i<=n;i++)            if(i+(1<<j)-1 <= n){                Maxsum[i][j] = max(Maxsum[i][j-1],Maxsum[i+(1<<(j-1))][j-1]);            }    scanf("%d",&m);    while(m--){        int x,y;        scanf("%d%d",&x,&y);        fuck = log(y-x+1) / log(2);        printf("%d\n",max(Maxsum[x][fuck],Maxsum[y-(1<<fuck)+1][fuck]));    }    return 0;}

 

[vijos1514]天才的记忆