Example #1
0
int main(void) {
    scanf("%d", &T);
    int a, b;       // interval to get min value

    for (int t = 1; t <= T; t++) {
        scanf("%d %d", &n, &q);

        for (int i = 1; i <= n; i++) {
            scanf("%d", v+i);         
        }

        gen_st(1, 1, n);

        printf("Scenario #%d:\n", t);

        for (int i = 0; i < q; i++) {
            scanf("%d %d", &qa, &qb);

            printf("%d\n", query(1));
        }

    }

    return 0;
}
Example #2
0
void gen_st(int i, int a, int b) {
    st[i].a = a;
    st[i].b = b;

    if (a == b) {

       st[i].v = v[a];

    } else if (a < b) {
        int m = (a+b)/2;

        gen_st(2*i, a, m);
        gen_st(2*i+1, m+1, b);
        
        st[i].v = std::min(st[2*i].v, st[2*i+1].v);
        
    } else {
        printf("deu ruim aqui, b > a\n");
    }
}
Example #3
0
void Compiler::handle_ik_ls(const JInst& jinst) {
    switch(jinst.opcode) {
    case OPCODE_ICONST_M1:  gen_push((int)-1); break;
    case OPCODE_ICONST_0:   gen_push((int)0);   break;
    case OPCODE_ICONST_1:   gen_push((int)1);   break;
    case OPCODE_ICONST_2:   gen_push((int)2);   break;
    case OPCODE_ICONST_3:   gen_push((int)3);   break;
    case OPCODE_ICONST_4:   gen_push((int)4);   break;
    case OPCODE_ICONST_5:   gen_push((int)5);   break;

    case OPCODE_LCONST_0:   gen_push((jlong)0); break;
    case OPCODE_LCONST_1:   gen_push((jlong)1); break;

    case OPCODE_FCONST_0:   gen_push(flt32, &g_fconst_0); break;
    case OPCODE_FCONST_1:   gen_push(flt32, &g_fconst_1); break;
    case OPCODE_FCONST_2:   gen_push(flt32, &g_fconst_2); break;

    case OPCODE_DCONST_0:   gen_push(dbl64, &g_dconst_0); break;
    case OPCODE_DCONST_1:   gen_push(dbl64, &g_dconst_1); break;

    case OPCODE_LDC:
    case OPCODE_LDC_W:
    case OPCODE_LDC2_W:
        gen_ldc();
        break;
    case OPCODE_SIPUSH:
        gen_push((int)(short)(unsigned short)jinst.op0);
        break;
    case OPCODE_BIPUSH:
        gen_push((int)(char)(unsigned char)jinst.op0);
        break;

    case OPCODE_ASTORE:
        assert(m_jframe->top() == jobj || m_jframe->top() == jretAddr);
        gen_st(m_jframe->top(), jinst.op0);
        break;
    case OPCODE_ISTORE:     gen_st(i32, jinst.op0); break;
    case OPCODE_LSTORE:     gen_st(i64, jinst.op0); break;

    case OPCODE_FSTORE:     gen_st(flt32, jinst.op0); break;

    case OPCODE_DSTORE:     gen_st(dbl64, jinst.op0); break;

    case OPCODE_ISTORE_0:
    case OPCODE_ISTORE_1:
    case OPCODE_ISTORE_2:
    case OPCODE_ISTORE_3:
        gen_st(i32, jinst.opcode-OPCODE_ISTORE_0);
        break;
    case OPCODE_LSTORE_0:
    case OPCODE_LSTORE_1:
    case OPCODE_LSTORE_2:
    case OPCODE_LSTORE_3:
        gen_st(i64, jinst.opcode-OPCODE_LSTORE_0);
        break;
    case OPCODE_FSTORE_0:
    case OPCODE_FSTORE_1:
    case OPCODE_FSTORE_2:
    case OPCODE_FSTORE_3:
        gen_st(flt32, jinst.opcode-OPCODE_FSTORE_0);
        break;
    case OPCODE_DSTORE_0:
    case OPCODE_DSTORE_1:
    case OPCODE_DSTORE_2:
    case OPCODE_DSTORE_3:
        gen_st(dbl64, jinst.opcode-OPCODE_DSTORE_0);
        break;
    case OPCODE_ASTORE_0:
    case OPCODE_ASTORE_1:
    case OPCODE_ASTORE_2:
    case OPCODE_ASTORE_3:
        assert(m_jframe->top() == jobj || m_jframe->top() == jretAddr);
        gen_st(m_jframe->top(), jinst.opcode-OPCODE_ASTORE_0);
        break;

    case OPCODE_ILOAD:      gen_ld(i32, jinst.op0);   break;
    case OPCODE_LLOAD:      gen_ld(i64, jinst.op0);   break;

    case OPCODE_FLOAD:      gen_ld(flt32, jinst.op0); break;

    case OPCODE_DLOAD:      gen_ld(dbl64, jinst.op0); break;
    case OPCODE_ALOAD:      gen_ld(jobj, jinst.op0);  break;

    case OPCODE_ILOAD_0:
    case OPCODE_ILOAD_1:
    case OPCODE_ILOAD_2:
    case OPCODE_ILOAD_3:
        gen_ld(i32, jinst.opcode-OPCODE_ILOAD_0);
        break;
    case OPCODE_LLOAD_0:
    case OPCODE_LLOAD_1:
    case OPCODE_LLOAD_2:
    case OPCODE_LLOAD_3:
        gen_ld(i64, jinst.opcode-OPCODE_LLOAD_0);
        break;
    case OPCODE_FLOAD_0:
    case OPCODE_FLOAD_1:
    case OPCODE_FLOAD_2:
    case OPCODE_FLOAD_3:
        gen_ld(flt32, jinst.opcode-OPCODE_FLOAD_0);
        break;
    case OPCODE_DLOAD_0:
    case OPCODE_DLOAD_1:
    case OPCODE_DLOAD_2:
    case OPCODE_DLOAD_3:
        gen_ld(dbl64, jinst.opcode-OPCODE_DLOAD_0);
        break;
    case OPCODE_ALOAD_0:
    case OPCODE_ALOAD_1:
    case OPCODE_ALOAD_2:
    case OPCODE_ALOAD_3:
        gen_ld(jobj, jinst.opcode-OPCODE_ALOAD_0);
        break;
    case OPCODE_ACONST_NULL:
        gen_push(jobj, NULL_REF);
        break;
    default:    assert(false); break;
    }
}