st表全wa求助

P1816 忠诚

```cpp #include<bits/stdc++.h> using namespace std; long long m,n,f[1000010][25]; inline int read() { int x=0,f=1;char ch=getchar(); while (ch<'0'||ch>'9'){if (ch=='-') f=-1;ch=getchar();} while (ch>='0'&&ch<='9'){x=x*10+ch-48;ch=getchar();} return x*f; } int qe(int l,int r) { int k=log2(r-l+1); return min(f[l][k],f[r-(1<<k)+1][k]); } void pre() { int t=log(n)/log(2)+1; for(int j=1;j<t;j++) { for(int i=1;i<=n-(1<<j)+1;i++) { f[i][j]=min(f[i][j-1],f[i+(1<<(j-1))][j-1]); } } } int main(){ n=read(); m=read(); for(int i=1;i<=n;i++) { f[i][0]=read(); } pre(); /*for(int i=1;i<=m;i++) { l[i]=read(); r[i]=read(); } for(int i=1;i<=m;i++) cout<<qe(l[i],r[i])<<endl;*/ while(m--){ int l=read(),r=read(); int j=log2(r-l+1); cout<<qe(l,r)<<' '; } return 0; } ```
by mouyulin @ 2024-01-30 16:03:57


@[rlgrlgrlg](/user/574931)
by mouyulin @ 2024-01-30 16:04:28


|