#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 /*<<< orphan*/ build(int, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, int);
int query(int, int, int, int /*<<< orphan*/, int);
int /*<<< orphan*/ scanf(char *, int *, int *, ...);
int /*<<< orphan*/ update(int, int, int, int /*<<< orphan*/, int);
int main(void) {
  int n, q;
  scanf("%d %d", &n, &q);
  build(1, 0, n - 1);
  while (q--) {
    int t, a, b;
    scanf("%d %d %d", &t, &a, &b);
    if (t == 0)
      update(a, b, 1, 0, n - 1);
    else
      printf("%d\n", query(a, b, 1, 0, n - 1));
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9d(%rip),%rdi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
mov    $0x0,%al
call   1070 <scanf@plt>
mov    -0x8(%rbp),%edx
sub    $0x1,%edx
mov    $0x1,%edi
xor    %esi,%esi
call   1040 <build@plt>
mov    -0xc(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0xc(%rbp)
cmp    $0x0,%eax
je     120b <main+0xbb>
lea    0xe5e(%rip),%rdi
lea    -0x10(%rbp),%rsi
lea    -0x14(%rbp),%rdx
lea    -0x18(%rbp),%rcx
mov    $0x0,%al
call   1070 <scanf@plt>
cmpl   $0x0,-0x10(%rbp)
jne    11de <main+0x8e>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    -0x8(%rbp),%r8d
sub    $0x1,%r8d
mov    $0x1,%edx
xor    %ecx,%ecx
call   1030 <update@plt>
jmp    1206 <main+0xb6>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    -0x8(%rbp),%r8d
sub    $0x1,%r8d
mov    $0x1,%edx
xor    %ecx,%ecx
call   1060 <query@plt>
mov    %eax,%esi
lea    0xe08(%rip),%rdi
call   1050 <printf@plt>
jmp    1187 <main+0x37>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x20,%rsp
lea    0xe9f(%rip),%rdi
lea    0x10(%rsp),%rsi
lea    0xc(%rsp),%rdx
xor    %eax,%eax
call   1070 <scanf@plt>
mov    0x10(%rsp),%edx
add    $0xffffffff,%edx
mov    $0x1,%edi
xor    %esi,%esi
call   1040 <build@plt>
subl   $0x1,0xc(%rsp)
jb     1206 <main+0xb6>
lea    0xe6a(%rip),%r14
lea    0x1c(%rsp),%r15
lea    0x18(%rsp),%r12
lea    0x14(%rsp),%rbx
lea    0xe5d(%rip),%r13
jmp    11c8 <main+0x78>
xchg   %ax,%ax
xor    %ecx,%ecx
call   1060 <query@plt>
mov    %r13,%rdi
mov    %eax,%esi
call   1050 <printf@plt>
subl   $0x1,0xc(%rsp)
jb     1206 <main+0xb6>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
mov    %rbx,%rcx
xor    %eax,%eax
call   1070 <scanf@plt>
mov    0x10(%rsp),%r8d
add    $0xffffffff,%r8d
cmpl   $0x0,0x1c(%rsp)
mov    0x18(%rsp),%edi
mov    0x14(%rsp),%esi
mov    $0x1,%edx
jne    11b0 <main+0x60>
xor    %ecx,%ecx
call   1030 <update@plt>
subl   $0x1,0xc(%rsp)
jae    11c8 <main+0x78>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%d %d\00"
@.str.1 = [9 x i8] c"%d %d %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 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
%7 = call i32 (i8*, i32*, i32*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* %2, i32* %3)
%8 = load i32, i32* %2
%9 = sub nsw i32 %8, 1
%10 = call i32 @build(i32 1, i32 0, i32 %9)
br label %11
11: ; preds = %32, %0
%12 = load i32, i32* %3
%13 = add nsw i32 %12, -1
store i32 %13, i32* %3
%14 = icmp ne i32 %12, 0
br i1 %14, label %15, label %33
15: ; preds = %11
%16 = call i32 (i8*, i32*, i32*, ...) @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32* %4, i32* %5, i32* %6)
%17 = load i32, i32* %4
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %25
19: ; preds = %15
%20 = load i32, i32* %5
%21 = load i32, i32* %6
%22 = load i32, i32* %2
%23 = sub nsw i32 %22, 1
%24 = call i32 @update(i32 %20, i32 %21, i32 1, i32 0, i32 %23)
br label %32
25: ; preds = %15
%26 = load i32, i32* %5
%27 = load i32, i32* %6
%28 = load i32, i32* %2
%29 = sub nsw i32 %28, 1
%30 = call i32 @query(i32 %26, i32 %27, i32 1, i32 0, i32 %29)
%31 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %30)
br label %32
32: ; preds = %25, %19
br label %11
33: ; preds = %11
ret i32 0
}

LLVM IR (-O2):
@.str = [6 x i8] c"%d %d\00"
@.str.1 = [9 x i8] c"%d %d %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 = alloca i32
%6 = bitcast i32* %1 to i8*
%7 = bitcast i32* %2 to i8*
%8 = call i32 (i8*, i32*, i32*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* %1, i32* %2)
%9 = load i32, i32* %1
%10 = add nsw i32 %9, -1
%11 = call i32 @build(i32 1, i32 0, i32 %10)
%12 = load i32, i32* %2
%13 = add nsw i32 %12, -1
store i32 %13, i32* %2
%14 = icmp eq i32 %12, 0
br i1 %14, label %36, label %15
15: ; preds = %0
%16 = bitcast i32* %3 to i8*
%17 = bitcast i32* %4 to i8*
%18 = bitcast i32* %5 to i8*
br label %19
19: ; preds = %15, %32
%20 = call i32 (i8*, i32*, i32*, ...) @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32* %3, i32* %4, i32* %5)
%21 = load i32, i32* %3
%22 = icmp eq i32 %21, 0
%23 = load i32, i32* %4
%24 = load i32, i32* %5
%25 = load i32, i32* %1
%26 = add nsw i32 %25, -1
br i1 %22, label %27, label %29
27: ; preds = %19
%28 = call i32 @update(i32 %23, i32 %24, i32 1, i32 0, i32 %26)
br label %32
29: ; preds = %19
%30 = call i32 @query(i32 %23, i32 %24, i32 1, i32 0, i32 %26)
%31 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %30)
br label %32
32: ; preds = %29, %27
%33 = load i32, i32* %2
%34 = add nsw i32 %33, -1
store i32 %34, i32* %2
%35 = icmp eq i32 %33, 0
br i1 %35, label %36, label %19
36: ; preds = %32, %0
ret i32 0
}