提交记录 47926


用户 题目 状态 得分 用时 内存 语言 代码长度
jiegec noip17f. 【NOIP2017】列队 Accepted 100 149.892 ms 41136 KB C++17 3.38 KB
提交时间 评测时间
2026-09-13 10:59:58 2026-09-13 11:00:05
// This code is AI-generated. (AI 生成的代码)
// NOIP2017 列队: offline.  For each row and for the last column, replay only the
// queries that touch it through a Fenwick "select k-th present / remove", which
// maps each request to either an original position or an appended slot.  Then
// replay all queries, resolving appended slots with per-row / last-column vectors.
#include <sys/auxv.h>
#include <stdint.h>
#include <vector>
struct DuckInfo {
    unsigned long abi; const char *in; unsigned long in_size;
    char *out; unsigned long out_limit, out_size;
    char *err; unsigned long err_limit, err_size;
    const char *IB; unsigned long IB_limit; char *OB; unsigned long OB_limit; unsigned long tsc;
} __attribute__((packed));
static const char *ip; static char *op;
static inline int rd() {
    const char *p = ip;
    while ((unsigned)(*p - '0') > 9u) p++;
    int x = 0;
    do { x = x * 10 + (*p++ - '0'); } while ((unsigned)(*p - '0') <= 9u);
    ip = p; return x;
}
static inline void wr(long long v) {
    if (v < 0) { *op++ = '-'; v = -v; }
    char t[24]; int k = 0;
    if (!v) t[k++] = '0';
    while (v) { t[k++] = (char)('0' + v % 10); v /= 10; }
    while (k) *op++ = t[--k];
    *op++ = '\n';
}
using namespace std;
typedef long long ll;
enum { MAXN = 300005 };
struct Req { int qid, x; };
static vector<Req> rowReq[MAXN];
static vector<Req> colReq;
static int ind[2 * MAXN];
static int qx[MAXN], qy[MAXN];
static int fw[1 << 21];
static int FW;
static inline int lowbit(int x) { return x & -x; }
static void rebuild(int size) {
    FW = 1; while (FW < size) FW <<= 1;
    for (int i = 1; i <= FW; i++) fw[i] = lowbit(i);
}
static int rmv(int k) {
    int pos = 0, rem = k;
    for (int pw = FW >> 1; pw; pw >>= 1)
        if (pos + pw <= FW && fw[pos + pw] < rem) { pos += pw; rem -= fw[pos]; }
    int p = pos + 1;
    for (int i = p; i <= FW; i += lowbit(i)) fw[i]--;
    return p;
}
static void addp(int p) { for (int i = p; i <= FW; i += lowbit(i)) fw[i]++; }
int main() {
    int n, m, q;
    struct DuckInfo *d = (struct DuckInfo *)getauxval(0x6b637564UL);
    ip = d->in; op = d->out;
    n = rd(); m = rd(); q = rd();
    int qc = 0;
    for (int i = 1; i <= q; i++) {
        qx[i] = rd(); qy[i] = rd();
        if (qy[i] == m) colReq.push_back(Req{++qc, qx[i]});
        else {
            rowReq[qx[i]].push_back(Req{++qc, qy[i]});
            colReq.push_back(Req{++qc, qx[i]});
        }
    }
    rebuild(m + q + 2);
    for (int i = 1; i <= n; i++) {
        for (size_t j = 0; j < rowReq[i].size(); j++) ind[rowReq[i][j].qid] = rmv(rowReq[i][j].x);
        for (size_t j = 0; j < rowReq[i].size(); j++) addp(ind[rowReq[i][j].qid]);
    }
    rebuild(n + q + 2);
    for (size_t j = 0; j < colReq.size(); j++) ind[colReq[j].qid] = rmv(colReq[j].x);
    static vector<ll> rr[MAXN];
    static vector<ll> rc;
    qc = 0;
    for (int i = 1; i <= q; i++) {
        if (qy[i] == m) {
            ++qc; ll v;
            if (ind[qc] <= n) v = (ll)ind[qc] * m; else v = rc[ind[qc] - n - 1];
            rc.push_back(v); wr(v);
        } else {
            ++qc; ll v;
            if (ind[qc] < m) v = (ll)ind[qc] + (ll)(qx[i] - 1) * m;
            else v = rr[qx[i]][ind[qc] - m];
            wr(v); rc.push_back(v);
            ++qc;
            if (ind[qc] <= n) v = (ll)ind[qc] * m; else v = rc[ind[qc] - n - 1];
            rr[qx[i]].push_back(v);
        }
    }
    d->out_size = (unsigned long)(op - d->out);
    return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #12.592 ms13 MB + 832 KBAcceptedScore: 5

Testcase #22.534 ms13 MB + 832 KBAcceptedScore: 5

Testcase #32.537 ms13 MB + 832 KBAcceptedScore: 5

Testcase #42.55 ms13 MB + 836 KBAcceptedScore: 5

Testcase #52.547 ms13 MB + 832 KBAcceptedScore: 5

Testcase #62.602 ms13 MB + 836 KBAcceptedScore: 5

Testcase #72.736 ms14 MB + 60 KBAcceptedScore: 5

Testcase #82.733 ms14 MB + 64 KBAcceptedScore: 5

Testcase #92.744 ms14 MB + 64 KBAcceptedScore: 5

Testcase #102.744 ms14 MB + 64 KBAcceptedScore: 5

Testcase #1129.275 ms20 MB + 1004 KBAcceptedScore: 5

Testcase #1229.096 ms20 MB + 552 KBAcceptedScore: 5

Testcase #13107.109 ms40 MB + 176 KBAcceptedScore: 5

Testcase #14101.403 ms39 MB + 460 KBAcceptedScore: 5

Testcase #15104.579 ms37 MB + 8 KBAcceptedScore: 5

Testcase #16109.394 ms37 MB + 636 KBAcceptedScore: 5

Testcase #1739.678 ms22 MB + 28 KBAcceptedScore: 5

Testcase #1838.743 ms21 MB + 816 KBAcceptedScore: 5

Testcase #19149.892 ms39 MB + 608 KBAcceptedScore: 5

Testcase #20148.572 ms39 MB + 904 KBAcceptedScore: 5


Judge Duck Online | 评测鸭在线
Server Time: 2026-09-14 15:46:48 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠