码风贼好看的st表
#include<bits/stdc++.h>
#define N 100005
using namespace std;
int n,m;
int st[N][18];
inline int Mx(int x,int y){return x>y?x:y;}
inline int query(int l,int r)
{
int lg=log(r-l+1)/log(2);
return Mx(st[l][lg],st[r-(1<<lg)+1][lg]);
}
int main()
{
ios::sync_with_stdio(false);
cin>>n>>m;
for(int i=1;i<=n;++i) cin>>st[i][0];
int lg=log(n)/log(2);
for(int l=1;l<=lg;++l)
for(int i=1;i<=n-(1<<l)+1;++i)
st[i][l]=Mx(st[i][l-1],st[i+(1<<(l-1))][l-1]);
int l,r;
while(m--)
{
cin>>l>>r;
printf("%d\n",query(l,r));
}
return 0;
}
#define N 100005
using namespace std;
int n,m;
int st[N][18];
inline int Mx(int x,int y){return x>y?x:y;}
inline int query(int l,int r)
{
int lg=log(r-l+1)/log(2);
return Mx(st[l][lg],st[r-(1<<lg)+1][lg]);
}
int main()
{
ios::sync_with_stdio(false);
cin>>n>>m;
for(int i=1;i<=n;++i) cin>>st[i][0];
int lg=log(n)/log(2);
for(int l=1;l<=lg;++l)
for(int i=1;i<=n-(1<<l)+1;++i)
st[i][l]=Mx(st[i][l-1],st[i+(1<<(l-1))][l-1]);
int l,r;
while(m--)
{
cin>>l>>r;
printf("%d\n",query(l,r));
}
return 0;
}
Last one:Young Turks - Rod Stewart
Next one:《假如你不够快乐》
声明:以上文章均为用户自行添加,仅供打字交流使用,不代表本站观点,本站不承担任何法律责任,特此声明!如果有侵犯到您的权利,请及时联系我们删除。
Hot degree:★☆☆☆☆
Difficulty:☆☆☆☆☆
quality:☆☆☆☆☆
Description: the system according to the heat, the difficulty, the quality of automatic certification, the certification of the article will be involved in typing!
This paper typing ranking TOP20
登录后可见
用户更多文章推荐
- abcdefghijklmnopqrstuvwxyz2018-10-15