#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*/ add(int, unsigned short *, int);
void *malloc(int);
int /*<<< orphan*/ printRes(unsigned int *, int);
unsigned int query(int, unsigned short *, int);
int /*<<< orphan*/ scanf(char *, ...);
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  unsigned short *nums = malloc(sizeof(unsigned short) * n);
  unsigned int *res = malloc(sizeof(unsigned int) * 200000);
  int i, k;
  for (i = 0; i < n; i++)
    scanf("%d", &nums[i]);
  char op;
  int arg;
  int j;
  int qCount = 0;
  for (j = 0; j < m; j++) {
    scanf(" %c %d", &op, &arg);
    if (op == 'Q') {
      res[qCount++] = query(arg, nums, n);
    } else if (op == 'C') {
      add(arg, nums, n);
    }
  }
  printRes(res, qCount);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
mov    $0x0,%al
call   1060 <scanf@plt>
movslq -0x8(%rbp),%rax
shl    $0x1,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    $0xc3500,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11d4 <main+0x84>
mov    -0x18(%rbp),%rsi
movslq -0x24(%rbp),%rax
shl    $0x1,%rax
add    %rax,%rsi
lea    0xe4b(%rip),%rdi
mov    $0x0,%al
call   1060 <scanf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    119d <main+0x4d>
movl   $0x0,-0x38(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1270 <main+0x120>
lea    0xe11(%rip),%rdi
lea    -0x29(%rbp),%rsi
lea    -0x30(%rbp),%rdx
mov    $0x0,%al
call   1060 <scanf@plt>
movsbl -0x29(%rbp),%eax
cmp    $0x51,%eax
jne    123c <main+0xec>
mov    -0x30(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x8(%rbp),%edx
call   1040 <query@plt>
mov    %eax,%edx
mov    -0x20(%rbp),%rax
mov    -0x38(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x38(%rbp)
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
jmp    125d <main+0x10d>
movsbl -0x29(%rbp),%eax
cmp    $0x43,%eax
jne    1258 <main+0x108>
mov    -0x30(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x8(%rbp),%edx
call   1030 <add@plt>
jmp    125d <main+0x10d>
jmp    1262 <main+0x112>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11e2 <main+0x92>
mov    -0x20(%rbp),%rdi
mov    -0x38(%rbp),%esi
call   1070 <printRes@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xe9b(%rip),%rdi
xor    %r15d,%r15d
lea    0x4(%rsp),%rsi
lea    0xc(%rsp),%rdx
xor    %eax,%eax
call   1060 <scanf@plt>
mov    0x4(%rsp),%ebx
lea    (%rbx,%rbx,1),%edi
call   1050 <malloc@plt>
mov    %rax,%r14
mov    $0xc3500,%edi
call   1050 <malloc@plt>
mov    %rax,0x10(%rsp)
test   %ebx,%ebx
jle    11cf <main+0x7f>
lea    0xe68(%rip),%r12
mov    %r14,%rbx
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
add    $0x1,%rbp
movslq 0x4(%rsp),%rax
add    $0x2,%rbx
cmp    %rax,%rbp
jl     11b0 <main+0x60>
cmpl   $0x0,0xc(%rsp)
jle    1247 <main+0xf7>
lea    0xe29(%rip),%r12
lea    0x3(%rsp),%r13
lea    0x8(%rsp),%rbp
xor    %r15d,%r15d
xor    %ebx,%ebx
jmp    1209 <main+0xb9>
xchg   %ax,%ax
mov    0x8(%rsp),%edi
mov    0x4(%rsp),%edx
mov    %r14,%rsi
call   1030 <add@plt>
add    $0x1,%ebx
cmp    0xc(%rsp),%ebx
jge    1247 <main+0xf7>
mov    %r12,%rdi
mov    %r13,%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   1060 <scanf@plt>
movzbl 0x3(%rsp),%eax
cmp    $0x43,%al
je     11f0 <main+0xa0>
cmp    $0x51,%al
jne    1200 <main+0xb0>
mov    0x8(%rsp),%edi
mov    0x4(%rsp),%edx
mov    %r14,%rsi
call   1040 <query@plt>
movslq %r15d,%rcx
add    $0x1,%r15d
mov    0x10(%rsp),%rdx
mov    %eax,(%rdx,%rcx,4)
jmp    1200 <main+0xb0>
mov    0x10(%rsp),%rdi
mov    %r15d,%esi
call   1070 <printRes@plt>
xor    %eax,%eax
add    $0x18,%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 = [7 x i8] c" %c %d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i16*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %1
%12 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* %2, i32* %3)
%13 = load i32, i32* %2
%14 = sext i32 %13 to i64
%15 = mul i64 2, %14
%16 = trunc i64 %15 to i32
%17 = call i8* @malloc(i32 %16)
%18 = bitcast i8* %17 to i16*
store i16* %18, i16** %4
%19 = call i8* @malloc(i32 800000)
%20 = bitcast i8* %19 to i32*
store i32* %20, i32** %5
store i32 0, i32* %6
br label %21
21: ; preds = %31, %0
%22 = load i32, i32* %6
%23 = load i32, i32* %2
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %34
25: ; preds = %21
%26 = load i16*, i16** %4
%27 = load i32, i32* %6
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i16, i16* %26, i64 %28
%30 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i16* %29)
br label %31
31: ; preds = %25
%32 = load i32, i32* %6
%33 = add nsw i32 %32, 1
store i32 %33, i32* %6
br label %21
34: ; preds = %21
store i32 0, i32* %11
store i32 0, i32* %10
br label %35
35: ; preds = %65, %34
%36 = load i32, i32* %10
%37 = load i32, i32* %3
%38 = icmp slt i32 %36, %37
br i1 %38, label %39, label %68
39: ; preds = %35
%40 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %8, i32* %9)
%41 = load i8, i8* %8
%42 = sext i8 %41 to i32
%43 = icmp eq i32 %42, 81
br i1 %43, label %44, label %54
44: ; preds = %39
%45 = load i32, i32* %9
%46 = load i16*, i16** %4
%47 = load i32, i32* %2
%48 = call i32 @query(i32 %45, i16* %46, i32 %47)
%49 = load i32*, i32** %5
%50 = load i32, i32* %11
%51 = add nsw i32 %50, 1
store i32 %51, i32* %11
%52 = sext i32 %50 to i64
%53 = getelementptr inbounds i32, i32* %49, i64 %52
store i32 %48, i32* %53
br label %64
54: ; preds = %39
%55 = load i8, i8* %8
%56 = sext i8 %55 to i32
%57 = icmp eq i32 %56, 67
br i1 %57, label %58, label %63
58: ; preds = %54
%59 = load i32, i32* %9
%60 = load i16*, i16** %4
%61 = load i32, i32* %2
%62 = call i32 @add(i32 %59, i16* %60, i32 %61)
br label %63
63: ; preds = %58, %54
br label %64
64: ; preds = %63, %44
br label %65
65: ; preds = %64
%66 = load i32, i32* %10
%67 = add nsw i32 %66, 1
store i32 %67, i32* %10
br label %35
68: ; preds = %35
%69 = load i32*, i32** %5
%70 = load i32, i32* %11
%71 = call i32 @printRes(i32* %69, i32 %70)
ret i32 0
}

LLVM IR (-O2):
@.str = [6 x i8] c"%d %d\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [7 x i8] c" %c %d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8
%4 = alloca i32
%5 = bitcast i32* %1 to i8*
%6 = bitcast i32* %2 to i8*
%7 = call i32 (i8*, ...) @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 = shl i32 %8, 1
%10 = call i8* @malloc(i32 %9)
%11 = bitcast i8* %10 to i16*
%12 = call dereferenceable_or_null(800000) i8* @malloc(i32 800000)
%13 = bitcast i8* %12 to i32*
%14 = icmp sgt i32 %8, 0
br i1 %14, label %15, label %23
15: ; preds = %0, %15
%16 = phi i64 [ %19, %15 ], [ 0, %0 ]
%17 = getelementptr inbounds i16, i16* %11, i64 %16
%18 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i16* %17)
%19 = add nuw nsw i64 %16, 1
%20 = load i32, i32* %1
%21 = sext i32 %20 to i64
%22 = icmp slt i64 %19, %21
br i1 %22, label %15, label %23
23: ; preds = %15, %0
%24 = bitcast i32* %4 to i8*
%25 = load i32, i32* %2
%26 = icmp sgt i32 %25, 0
br i1 %26, label %27, label %48
27: ; preds = %23, %43
%28 = phi i32 [ %44, %43 ], [ 0, %23 ]
%29 = phi i32 [ %45, %43 ], [ 0, %23 ]
%30 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %3, i32* %4)
%31 = load i8, i8* %3
switch i8 %31, label %43 [
i8 81, label %32
i8 67, label %39
]
32: ; preds = %27
%33 = load i32, i32* %4
%34 = load i32, i32* %1
%35 = call i32 @query(i32 %33, i16* %11, i32 %34)
%36 = add nsw i32 %28, 1
%37 = sext i32 %28 to i64
%38 = getelementptr inbounds i32, i32* %13, i64 %37
store i32 %35, i32* %38
br label %43
39: ; preds = %27
%40 = load i32, i32* %4
%41 = load i32, i32* %1
%42 = call i32 @add(i32 %40, i16* %11, i32 %41)
br label %43
43: ; preds = %27, %32, %39
%44 = phi i32 [ %36, %32 ], [ %28, %39 ], [ %28, %27 ]
%45 = add nuw nsw i32 %29, 1
%46 = load i32, i32* %2
%47 = icmp slt i32 %45, %46
br i1 %47, label %27, label %48
48: ; preds = %43, %23
%49 = phi i32 [ 0, %23 ], [ %44, %43 ]
%50 = call i32 @printRes(i32* %13, i32 %49)
ret i32 0
}