提交记录 6957


用户 题目 状态 得分 用时 内存 语言 代码长度
EntropyIncreaser noip17f. 【NOIP2017】列队 Accepted 100 220.982 ms 45232 KB C++ 2.17 KB
提交时间 评测时间
2018-11-23 20:49:18 2020-08-01 00:55:11
#include <cstdio>

#include <vector>

using namespace std;

typedef long long ll;

struct Modify {
    int qid, x;

    Modify() {}

    Modify(int qid, int x) : qid(qid), x(x) {}
};

const int N = 300010, FW = 1 << 21;

int n, m, q;
int qCnt;
int qx[N], qy[N];
int ind[N * 2];
int fw[FW];
vector<Modify> mr[N], mc;
vector<ll> rr[N], rc;

int rmv(int k);
void change(int k);
int lowBit(int k);

int main() {
    for (int i = 1; i < FW; ++i)
        fw[i] = lowBit(i);
    scanf("%d%d%d", &n, &m, &q);
    for (int i = 1; i <= q; ++i) {
        scanf("%d%d", &qx[i], &qy[i]);
        if (qy[i] == m)
            mc.push_back(Modify(++qCnt, qx[i]));
        else {
            mr[qx[i]].push_back(Modify(++qCnt, qy[i]));
            mc.push_back(Modify(++qCnt, qx[i]));
        }
    }
    for (int i = 1; i <= n; ++i) {
        for (int j = 0; j < mr[i].size(); ++j) {
            ind[mr[i][j].qid] = rmv(mr[i][j].x);
        }
        for (int j = 0; j < mr[i].size(); ++j)
            change(ind[mr[i][j].qid]);
    }
    for (int j = 0; j < mc.size(); ++j)
        ind[mc[j].qid] = rmv(mc[j].x);
    qCnt = 0;
    for (int i = 1; i <= q; ++i) {
        ll v;
        if (qy[i] == m) {
            ++qCnt;
            if (ind[qCnt] <= n)
                v = ind[qCnt] * (ll)m;
            else
                v = rc[ind[qCnt] - n - 1];
            rc.push_back(v);
            printf("%lld\n", v);
        } else {
            ++qCnt;
            if (ind[qCnt] < m)
                v = ind[qCnt] + (qx[i] - 1) * (ll)m;
            else
                v = rr[qx[i]][ind[qCnt] - m];
            printf("%lld\n", v);
            rc.push_back(v);
            ++qCnt;
            if (ind[qCnt] <= n)
                v = ind[qCnt] * (ll)m;
            else
                v = rc[ind[qCnt] - n - 1];
            rr[qx[i]].push_back(v);
        }
    }
    return 0;
}

int lowBit(int k) {
    return k & -k;
}

void change(int k) {
    for (; k < FW; k += lowBit(k))
        ++fw[k];
}

int rmv(int k) {
    int ret = 0;
    --k;
    for (int l = 20; l >= 0; --l)
        if (fw[ret | (1 << l)] <= k)
            k -= fw[ret |= (1 << l)];
    ++ret;
    for (k = ret; k < FW; k += lowBit(k))
        --fw[k];
    return ret;
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #14.189 ms21 MB + 824 KBAcceptedScore: 5

Testcase #24.132 ms21 MB + 824 KBAcceptedScore: 5

Testcase #34.188 ms21 MB + 824 KBAcceptedScore: 5

Testcase #44.17 ms21 MB + 828 KBAcceptedScore: 5

Testcase #54.198 ms21 MB + 824 KBAcceptedScore: 5

Testcase #64.212 ms21 MB + 828 KBAcceptedScore: 5

Testcase #74.266 ms21 MB + 828 KBAcceptedScore: 5

Testcase #84.338 ms21 MB + 832 KBAcceptedScore: 5

Testcase #94.337 ms21 MB + 832 KBAcceptedScore: 5

Testcase #104.313 ms21 MB + 832 KBAcceptedScore: 5

Testcase #1155.865 ms27 MB + 1004 KBAcceptedScore: 5

Testcase #1255.33 ms27 MB + 552 KBAcceptedScore: 5

Testcase #13175.818 ms44 MB + 176 KBAcceptedScore: 5

Testcase #14166.145 ms43 MB + 460 KBAcceptedScore: 5

Testcase #15168.571 ms41 MB + 8 KBAcceptedScore: 5

Testcase #16176.177 ms41 MB + 636 KBAcceptedScore: 5

Testcase #1767.736 ms29 MB + 28 KBAcceptedScore: 5

Testcase #1865.604 ms28 MB + 816 KBAcceptedScore: 5

Testcase #19220.982 ms43 MB + 608 KBAcceptedScore: 5

Testcase #20219.965 ms43 MB + 908 KBAcceptedScore: 5


Judge Duck Online | 评测鸭在线
Server Time: 2024-12-05 10:21:51 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠