-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10868.cpp
More file actions
37 lines (28 loc) · 704 Bytes
/
10868.cpp
File metadata and controls
37 lines (28 loc) · 704 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
#define MAXN 100050
int N,M,D[MAXN][20],lg[MAXN];
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
cin >> N >> M;
for(int i=1 ; i<=N ; i++){
cin >> D[i][0];
}
for(int k=1 ; k<20 ; k++){
for(int i=1 ; i + (1<<k) -1 <= N ; i++){
D[i][k] = min(D[i][k-1], D[i+(1<<k-1)][k-1]);
}
}
lg[1]=0;
for(int i=2 ; i<=N ; i++) lg[i] = lg[i/2] + 1;
for(int i=0 ; i<M ; i++){
int l,r; cin >> l >> r;
int k = lg[r-l+1];
int ans = min(D[l][k], D[r-(1<<k)+1][k]);
cout << ans << '\n';
}
}