#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int RMQ(int *, int, int, int);
int *constructST(int *, int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ scanf(char *, int *, ...);
int main() {
  int n;
  int t;
  scanf("%d %d", &n, &t);
  int width[n];
  for (int width_i = 0; width_i < n; width_i++) {
    scanf("%d", &width[width_i]);
  }
  int *rmqArr = constructST(width, n);
  for (int a0 = 0; a0 < t; a0++) {
    int i;
    int j;
    scanf("%d %d", &i, &j);
    printf("%d\n", RMQ(rmqArr, n, i, j));
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
xor    %eax,%eax
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
call   1060 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11ca <main+0x8a>
mov    -0x48(%rbp),%rsi
movslq -0x24(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe4e(%rip),%rdi
mov    $0x0,%al
call   1060 <scanf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1193 <main+0x53>
mov    -0x48(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1040 <constructST@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1231 <main+0xf1>
lea    0xe0c(%rip),%rdi
lea    -0x38(%rbp),%rsi
lea    -0x3c(%rbp),%rdx
mov    $0x0,%al
call   1060 <scanf@plt>
mov    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%esi
mov    -0x38(%rbp),%edx
mov    -0x3c(%rbp),%ecx
call   1050 <RMQ@plt>
mov    %eax,%esi
lea    0xde8(%rip),%rdi
call   1030 <printf@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11e1 <main+0xa1>
movl   $0x0,-0x4(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xea8(%rip),%rdi
lea    -0x2c(%rbp),%rsi
lea    -0x30(%rbp),%rdx
xor    %eax,%eax
call   1060 <scanf@plt>
mov    %rsp,-0x40(%rbp)
mov    -0x2c(%rbp),%eax
mov    %rsp,%r14
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
mov    -0x2c(%rbp),%esi
test   %esi,%esi
jle    11be <main+0x7e>
lea    0xe72(%rip),%r15
mov    %r14,%r12
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
add    $0x1,%rbx
movslq -0x2c(%rbp),%rsi
add    $0x4,%r12
cmp    %rsi,%rbx
jl     11a0 <main+0x60>
mov    %r14,%rdi
call   1040 <constructST@plt>
cmpl   $0x0,-0x30(%rbp)
jle    1229 <main+0xe9>
mov    %rax,%rbx
lea    -0x38(%rbp),%r15
lea    -0x34(%rbp),%r12
lea    0xe28(%rip),%r13
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    0xe09(%rip),%rdi
mov    %r15,%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1060 <scanf@plt>
mov    -0x2c(%rbp),%esi
mov    -0x38(%rbp),%edx
mov    -0x34(%rbp),%ecx
mov    %rbx,%rdi
call   1050 <RMQ@plt>
mov    %r13,%rdi
mov    %eax,%esi
call   1030 <printf@plt>
add    $0x1,%r14d
cmp    -0x30(%rbp),%r14d
jl     11f0 <main+0xb0>
mov    -0x40(%rbp),%rsp
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%d %d\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %1
%11 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* %2, i32* %3)
%12 = load i32, i32* %2
%13 = zext i32 %12 to i64
%14 = call i8* @llvm.stacksave()
store i8* %14, i8** %4
%15 = alloca i32, i64 %13
store i64 %13, i64* %5
store i32 0, i32* %6
br label %16
16: ; preds = %25, %0
%17 = load i32, i32* %6
%18 = load i32, i32* %2
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %28
20: ; preds = %16
%21 = load i32, i32* %6
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i32, i32* %15, i64 %22
%24 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %23)
br label %25
25: ; preds = %20
%26 = load i32, i32* %6
%27 = add nsw i32 %26, 1
store i32 %27, i32* %6
br label %16
28: ; preds = %16
%29 = load i32, i32* %2
%30 = call i32* @constructST(i32* %15, i32 %29)
store i32* %30, i32** %7
store i32 0, i32* %8
br label %31
31: ; preds = %43, %28
%32 = load i32, i32* %8
%33 = load i32, i32* %3
%34 = icmp slt i32 %32, %33
br i1 %34, label %35, label %46
35: ; preds = %31
%36 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* %9, i32* %10)
%37 = load i32*, i32** %7
%38 = load i32, i32* %2
%39 = load i32, i32* %9
%40 = load i32, i32* %10
%41 = call i32 @RMQ(i32* %37, i32 %38, i32 %39, i32 %40)
%42 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %41)
br label %43
43: ; preds = %35
%44 = load i32, i32* %8
%45 = add nsw i32 %44, 1
store i32 %45, i32* %8
br label %31
46: ; preds = %31
store i32 0, i32* %1
%47 = load i8*, i8** %4
%48 = load i32, i32* %1
ret i32 %48
}

LLVM IR (-O2):
@.str = [6 x i8] c"%d %d\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %1 to i8*
%6 = bitcast i32* %2 to i8*
%7 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* %1, i32* %2)
%8 = load i32, i32* %1
%9 = zext i32 %8 to i64
%10 = call i8* @llvm.stacksave()
%11 = alloca i32, i64 %9
%12 = load i32, i32* %1
%13 = icmp sgt i32 %12, 0
br i1 %13, label %22, label %14
14: ; preds = %22, %0
%15 = phi i32 [ %12, %0 ], [ %27, %22 ]
%16 = call i32* @constructST(i32* %11, i32 %15)
%17 = load i32, i32* %2
%18 = icmp sgt i32 %17, 0
br i1 %18, label %19, label %30
19: ; preds = %14
%20 = bitcast i32* %3 to i8*
%21 = bitcast i32* %4 to i8*
br label %31
22: ; preds = %0, %22
%23 = phi i64 [ %26, %22 ], [ 0, %0 ]
%24 = getelementptr inbounds i32, i32* %11, i64 %23
%25 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %24)
%26 = add nuw nsw i64 %23, 1
%27 = load i32, i32* %1
%28 = sext i32 %27 to i64
%29 = icmp slt i64 %26, %28
br i1 %29, label %22, label %14
30: ; preds = %31, %14
ret i32 0
31: ; preds = %19, %31
%32 = phi i32 [ 0, %19 ], [ %39, %31 ]
%33 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* %3, i32* %4)
%34 = load i32, i32* %1
%35 = load i32, i32* %3
%36 = load i32, i32* %4
%37 = call i32 @RMQ(i32* %16, i32 %34, i32 %35, i32 %36)
%38 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %37)
%39 = add nuw nsw i32 %32, 1
%40 = load i32, i32* %2
%41 = icmp slt i32 %39, %40
br i1 %41, label %31, label %30
}