// File: /workspace/github_cpp_makefile_star2_O2/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 0x177e
movl %edi, %r14d
leal -0x1(%r14), %eax
movslq %eax, %rsi
leaq 0x20(%rsp), %r15
leaq 0x38(%rsp), %rdx
movq %r15, %rdi
callq 0x17c8
movq (%r15), %r15
movslq %r14d, %r14
pushq $0x1
popq %r12
cmpq %r14, %r12
jge 0x1622
movq (%rbx,%r12,8), %rdi
callq 0x10b0
movsd %xmm0, -0x8(%r15,%r12,8)
incq %r12
jmp 0x1608
leaq 0x38(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x181a
leaq 0xa4f(%rip), %rdi       # 0x2087
callq 0x10f0
leaq 0x9fe(%rip), %rbx       # 0x2042
leaq 0x9fb(%rip), %r14       # 0x2046
leaq 0x16(%rsp), %r15
leaq 0x8(%rsp), %r13
leaq 0x38(%rsp), %rbp
leaq 0xa6d(%rip), %r12       # 0x20ce
movq %rbx, %rdi
xorl %eax, %eax
callq 0x1030
movq %r14, %rdi
movq %r15, %rsi
xorl %eax, %eax
callq 0x10a0
cmpl $-0x1, %eax
je 0x1751
movzbl 0x16(%rsp), %eax
cmpl $0x63, %eax
je 0x1710
cmpl $0x75, %eax
je 0x16b6
cmpl $0x71, %eax
je 0x16e0
cmpl $0x70, %eax
jne 0x1744
movq 0x2917(%rip), %rax      # 0x3fc0
movq (%rax), %rsi
movq %rbp, %rdi
callq 0x1876
jmp 0x1661
leaq 0x98c(%rip), %rdi       # 0x2049
leaq 0x10(%rsp), %rsi
movq %r13, %rdx
xorl %eax, %eax
callq 0x10a0
movl 0x10(%rsp), %esi
movsd 0x8(%rsp), %xmm0
movq %rbp, %rdi
callq 0x1888
jmp 0x1661
leaq 0x968(%rip), %rdi       # 0x204f
movq %r13, %rsi
xorl %eax, %eax
callq 0x10a0
movl 0x8(%rsp), %esi
movq %rbp, %rdi
callq 0x1898
leaq 0x90e(%rip), %rdi       # 0x2012
movb $0x1, %al
callq 0x1030
jmp 0x1661
leaq 0x934(%rip), %rdi       # 0x204b
movq %r13, %rsi
xorl %eax, %eax
callq 0x10a0
movsd 0x8(%rsp), %xmm0
movq %rbp, %rdi
callq 0x18a8
leaq 0x91c(%rip), %rdi       # 0x2052
movl %eax, %esi
xorl %eax, %eax
callq 0x1030
jmp 0x1661
movq %r12, %rdi
callq 0x10f0
jmp 0x1661
pushq $0xd
popq %rdi
callq 0x10c0
leaq 0x40(%rsp), %rdi
callq 0x18f2
leaq 0x20(%rsp), %rdi
callq 0x18f2
xorl %eax, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x2853(%rip), %rax      # 0x3fd8
movq (%rax), %rdi
movq (%rbx), %rdx
leaq 0x885(%rip), %rsi       # 0x2017
xorl %eax, %eax
callq 0x10d0
pushq $0x2
popq %rax
jmp 0x176f
movq %rax, %rbx
jmp 0x17b6
jmp 0x17a9
jmp 0x17a9
jmp 0x17a9
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0x18f2
leaq 0x20(%rsp), %rdi
callq 0x18f2
movq %rbx, %rdi
callq 0x1100