码迷,mamicode.com
首页 > 其他好文 > 详细

hiho1068(RMQ)

时间:2017-04-09 09:46:51      阅读:165      评论:0      收藏:0      [点我收藏+]

标签:nbsp   coder   str   style   std   mat   math   algorithm   can   

题目连接:https://hihocoder.com/problemset/problem/1068?sid=1069788

RMQ

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<cmath>
 4 #include<algorithm>
 5 using namespace std;
 6 const int maxn=1e6+10;
 7 const int inf=0x3f3f3f3f;
 8 
 9 int dp[maxn][21];
10 
11 int main()
12 {
13     int n;
14     scanf("%d",&n);
15     for(int i=1;i<=n;i++)
16         scanf("%d",&dp[i][0]);
17     for(int i=0;i<21;i++)
18         dp[0][i]=inf;
19         
20     int len=log2(n);
21     for(int j=1;j<=len;j++)
22         for(int i=1;(i+(1<<j)-1)<=n;i++)
23             dp[i][j]=min(dp[i][j-1],dp[i+(1<<j-1)][j-1]);
24     int m,s,e,ans;
25     scanf("%d",&m);
26     while(m--)
27     {
28         scanf("%d%d",&s,&e);
29         int k=log2(e-s+1);
30         ans=min(dp[s][k],dp[e-(1<<k)+1][k]);
31         printf("%d\n",ans);
32     }
33     return 0;
34 
35 }

 

hiho1068(RMQ)

标签:nbsp   coder   str   style   std   mat   math   algorithm   can   

原文地址:http://www.cnblogs.com/yijiull/p/6683564.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!