标签:void turn names 问题 char ons include getc ace
可以求RMQ问题
#include<iostream> #include<cstdio> using namespace std; const int MAXN=100000+5; int n,m,log[MAXN],a[MAXN],st[MAXN][21]; inline int query(int l,int r); inline int read(); void ST(); int main() { register int l,r,t; n=read(); m=read(); log[0]=-1; for(register int i=1;i<=n;i++) { st[i][0]=read(); log[i]=log[i>>1]+1; } ST(); for(register int i=1;i<=m;i++) { l=read(); r=read(); printf("%d\n",query(l,r)); } return 0; } inline int read() { int re=0,f=1; char ch=getchar(); while(ch<‘0‘||ch>‘9‘) { if(ch==‘-‘) f=-1; ch=getchar(); } while(ch>=‘0‘&&ch<=‘9‘) { re=(re<<1)+(re<<3)+(ch^48); ch=getchar(); } return re*f; } void ST() { for(register int j=1;j<=20;j++) for(register int i=1;i+(1<<j)-1<=n;i++) st[i][j]=max(st[i][j-1],st[i+(1<<(j-1))][j-1]); } inline int query(int l,int r) { int t=log[r-l+1]; return max(st[l][t],st[r-(1<<t)+1][t]); }
标签:void turn names 问题 char ons include getc ace
原文地址:https://www.cnblogs.com/nenT/p/11622209.html