首页 > 编程语言 > 详细

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

时间:2019-11-25 01:24:42      阅读:106      评论:0      收藏:0      [点我收藏+]
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);
}

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

原文:https://www.cnblogs.com/KisekiPurin2019/p/11925193.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!