模板 - 算法基础 - 离线询问

struct Query {
    int id, pos, ans;
} q[200005];

bool cmp1(const Query &q1, const Query &q2) {
    return q1.pos < q2.pos;
}

bool cmp2(const Query &q1, const Query &q2) {
    return q1.id < q2.id;
}

void InputQuery(int n) {
    for(int i = 1; i <= n; ++i) {
        scanf("%d", &q[i].pos);
        q[i].id = i;
    }
    sort(q + 1, q + 1 + n, cmp1);
}

void OutputQuery(int n) {
    sort(q + 1, q + 1 + n, cmp2);
//    for(int i = 1; i <= n; ++i)
//        printf("%d%c", q[i].ans, " \n"[i == n]);
    for(int i = 1; i <= n; ++i)
        printf("%d\n", q[i].ans);
}
posted @ 2019-11-24 23:35  KisekiPurin2019  阅读(149)  评论(0编辑  收藏  举报