// File: /workspace/github_cpp_makefile_star2_O3/sharmaeklavya2[P]ddos-on-anycast/src/segtree.cpp
// Function: main
int main(int argc, char* argv[]) {
    if(argc == 1) {
        fprintf(stderr, "usage: %s space_separated_list_of_numbers\n", argv[0]);
        return 2;
    }

    int n = argc - 1;
    vector<double> v(n);
    for(int i=1; i<argc; ++i) {
        v[i-1] = std::atof(argv[i]);
    }

    SegTree segtree(v);

    printf("commands: print, query i, update i x, cumsum_search x;  Ctrl+D to quit\n");

    char command[10];
    while(true) {
        printf(">> ");
        if(scanf("%s", command) == EOF) {
            printf("\r");
            break;
        }
        if(command[0] == 'p') {
            segtree.print(stdout);
        }
        else if(command[0] == 'u') {
            int i; double x;
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-result"
            scanf("%d%lf", &i, &x);
#pragma GCC diagnostic pop
            segtree.update(i, x);
        }
        else if(command[0] == 'q') {
            int i; double x;
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-result"
            scanf("%d", &i);
#pragma GCC diagnostic pop
            x = segtree.query(i);
            printf("%lf\n", x);
        }
        else if(command[0] == 'c') {
            int i; double x;
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-result"
            scanf("%lf", &x);
#pragma GCC diagnostic pop
            i = segtree.cumsum_search(x);
            printf("%d\n", i);
        }
        else {
            printf("Invalid command\n");
        }
    };
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rsi, %rbx
cmpl $0x1, %edi
je 0x17f1
movl %edi, %r14d
leal -0x1(%r14), %eax
movslq %eax, %rsi
leaq 0x40(%rsp), %rdi
leaq 0x20(%rsp), %rdx
callq 0x1834
cmpl $0x2, %r14d
jl 0x1637
movq 0x40(%rsp), %r15
movl %r14d, %r14d
decq %r14
xorl %r12d, %r12d
movq 0x8(%rbx,%r12,8), %rdi
callq 0x10c0
movsd %xmm0, (%r15,%r12,8)
incq %r12
cmpq %r12, %r14
jne 0x161f
leaq 0x20(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x18c2
leaq 0xa3a(%rip), %rdi       # 0x2087
callq 0x1100
leaq 0x9e9(%rip), %rdi       # 0x2042
xorl %eax, %eax
callq 0x1030
leaq 0x9df(%rip), %rdi       # 0x2046
leaq 0x16(%rsp), %rsi
xorl %eax, %eax
callq 0x10b0
cmpl $-0x1, %eax
je 0x17b8
leaq 0x8(%rsp), %r14
leaq 0x20(%rsp), %r15
leaq 0x9b5(%rip), %r13       # 0x2042
leaq 0x9b2(%rip), %rbp       # 0x2046
leaq 0x16(%rsp), %rbx
leaq 0x10(%rsp), %r12
movzbl 0x16(%rsp), %eax
cmpl $0x70, %eax
jg 0x16d8
cmpl $0x63, %eax
je 0x1727
cmpl $0x70, %eax
jne 0x1719
movq 0x2907(%rip), %rax      # 0x3fc0
movq (%rax), %rsi
movl 0x20(%rsp), %r8d
decl %r8d
movq %r15, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r9d, %r9d
callq 0x134c
jmp 0x1798
cmpl $0x71, %eax
je 0x1762
cmpl $0x75, %eax
jne 0x1719
leaq 0x95c(%rip), %rdi       # 0x2049
movq %r12, %rsi
movq %r14, %rdx
xorl %eax, %eax
callq 0x10b0
movl 0x10(%rsp), %r8d
movsd 0x8(%rsp), %xmm0
movl 0x20(%rsp), %ecx
decl %ecx
movq %r15, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x14b8
jmp 0x1798
leaq 0x9ae(%rip), %rdi       # 0x20ce
callq 0x1100
jmp 0x1798
leaq 0x91d(%rip), %rdi       # 0x204b
movq %r14, %rsi
xorl %eax, %eax
callq 0x10b0
movsd 0x8(%rsp), %xmm0
movl 0x20(%rsp), %ecx
decl %ecx
movq %r15, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x1576
leaq 0x8fb(%rip), %rdi       # 0x2052
movl %eax, %esi
xorl %eax, %eax
callq 0x1030
jmp 0x1798
leaq 0x8e6(%rip), %rdi       # 0x204f
movq %r14, %rsi
xorl %eax, %eax
callq 0x10b0
movl 0x8(%rsp), %r8d
movl 0x20(%rsp), %ecx
decl %ecx
movq %r15, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x1426
leaq 0x881(%rip), %rdi       # 0x2012
movb $0x1, %al
callq 0x1030
movq %r13, %rdi
xorl %eax, %eax
callq 0x1030
movq %rbp, %rdi
movq %rbx, %rsi
xorl %eax, %eax
callq 0x10b0
cmpl $-0x1, %eax
jne 0x169e
movl $0xd, %edi
callq 0x10d0
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x17d1
callq 0x1090
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x17e0
callq 0x1090
xorl %eax, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %rdi
callq 0x1140
movl $0x2, %eax
jmp 0x17e2
movq %rax, %rbx
jmp 0x181d
jmp 0x180b
jmp 0x180b
jmp 0x180b
movq %rax, %rbx
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x181d
callq 0x1090
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x182c
callq 0x1090
movq %rbx, %rdi
callq 0x1110