QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#125060#6669. Mapabashkort#0 1ms3832kbC++204.2kb2023-07-16 00:19:342024-07-04 00:43:04

Judging History

你现在查看的是最新测评结果

  • [2024-07-04 00:43:04]
  • 评测
  • 测评结果:0
  • 用时:1ms
  • 内存:3832kb
  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-16 00:19:34]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int need(int n) { // [0...n]
    return __lg(n) + 1;
}

string encode(vector<int> a, int b, int f) {
    if (size(a) == 0) {
        return {};
    }
    if (size(a) <= 1) {
        string s;
        while (f && b > 0) {
            s += '0' + bool(a[0] & b);
            b /= 2;
        }
        return s;
    }
    assert(b > 0);
    int mid = 0;
    while (mid < size(a) && !(a[mid] & b)) {
        mid += 1;
    }
    string ans;
    int h = need(size(a));
    for (int i = 0; i < h; ++i) {
        ans += '0' + (mid >> i & 1);
    }
    string l = encode(vector(a.begin(), a.begin() + mid), b / 2, f);
    string r = encode(vector(a.begin() + mid, a.end()), b / 2, f);
    return ans + l + r;
}

void decode(vector<int> &ans, int &p, int n, const string &s, int b, int up, int f) {
    if (n == 0) {
        return;
    }
    if (n == 1) {
        while (f && b > 0) {
            up += (s[p++] - '0') * b;
            b /= 2;
        }
        return ans.push_back(up);
    }
    int h = need(n);
    int mid = 0;
    for (int i = 0; i < h; ++i) {
        if (s[p++] == '1') {
            mid += 1 << i;
        }
    }
    decode(ans, p, mid, s, b / 2, up, f);
    decode(ans, p, n - mid, s, b / 2, up + b, f);
}

string encodePerm(const vector<int> &p) {
    int n = size(p);
    string s;
    vector<bool> used(n);
    for (int i = 0; i < n - 1; ++i) {
        int f = find(p.begin(), p.end(), i) - p.begin();
        int pos = count(used.begin(), used.begin() + f, false);
        used[f] = true;
        int h = need(n - i - 1);
        for (int k = 0; k < h; ++k) {
            s += '0' + (pos >> k & 1);
        }
    }
    return s;
}

vector<int> decodePerm(int n, const string &s) {
    vector<int> p(n, -1);
    int pnt = 0;
    for (int i = 0; i < n - 1; ++i) {
        int h = need(n - i - 1);
        int pos = 0;
        for (int k = 0; k < h; ++k) {
            pos += (s[pnt++] - '0') << k;
        }
        for (int j = 0; j < n; ++j) {
            if (p[j] == -1 && pos-- == 0) {
                p[j] = i;
                break;
            }
        }
    }
    p[find(p.begin(), p.end(), -1) - p.begin()] = n - 1;
    return p;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    constexpr int A = 1e9 + 1;

    int type;
    cin >> type;

    mt19937 rnd(1337);

    if (type == 1) {
        int n;
        cin >> n;

        map<int, int> mp;
        vector<int> x(n), y(n);

        for (int i = 0; i < n; ++i) {
            int a, b;
            cin >> a >> b;
            int xr = rnd() % A;
            a ^= (0 * xr), b ^= xr;
            mp[a] = b;
            x[i] = a, y[i] = b;
        }

        sort(x.begin(), x.end());
        sort(y.begin(), y.end());

        assert(unique(x.begin(), x.end()) == x.end());
        assert(unique(y.begin(), y.end()) == y.end());

        string ex = encode(x, 1 << 29, 0);
        string ey = encode(y, 1 << 29, 1);
        vector<int> p(n);
        for (int i = 0; i < n; ++i) {
            p[i] = lower_bound(y.begin(), y.end(), mp[x[i]]) - y.begin();
        }
        string ep = encodePerm(p);

//        for (int t = 0; t < 3; ++t) {
//            for (int i = 0; i < 12; ++i) {
//                cout << (size(t == 0 ? ex : t == 1 ? ey : ep) >> i & 1);
//            }
//        }
        cout << size(ex + ey + ep) << '\n';
        cout << ex << ey << ep << '\n';
    } else {
        int n, q, k;
        cin >> n >> q >> k;

        vector<int> xr(n);

        for (int i = 0; i < n; ++i) {
            xr[i] = rnd() % A;
        }

        string s;
        cin >> s;

        vector<int> x, y, p;
        int i = 0;

        decode(x, i, n, s, 1 << 29, 0, 0);
        decode(y, i, n, s, 1 << 29, 0, 1);
        p = decodePerm(n, s.substr(i));

        for (int qwq = 0; qwq < q; ++qwq) {
            int a;
            cin >> a;
            pair<int, int> best{2e9, 0};
            for (int j = 0; j < n; ++j) {
                best = min(best, {a ^ x[j], j});
            }
            int j = best.second;
            cout << (y[p[j]] ^ xr[j]) << '\n';
        }
    }

    return 0;
}

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 1ms = 1ms + 0ms
memory: 3832kb,3648kb

input:

1
100
495528311 963488152
269613430 443544124
700489871 792354118
151890319 506569919
180452297 13229948
684464994 543841485
978085128 903812192
238355172 441140842
28061035 783291471
530823766 718942732
936853023 439421263
201361623 226633955
304644844 778868118
864860135 461524170
88300500 6959354...

output:

3502
1111110110110000010001010100101010101101000110011010010100101010011010001011000011011011011001010100100101011010011010001100101001001100001100101010001010101011100110101001001101001100101010001011011010101001001001100001100100110001001100010101010000010110011011010110001101100001000011010100010...

input:

2
100 79 3502
1111110110110000010001010100101010101101000110011010010100101010011010001011000011011011011001010100100101011010011010001100101001001100001100101010001010101011100110101001001101001100101010001011011010101001001001100001100100110001001100010101010000010110011011010110001101100001000011...

output:

619669451
979000392
649676399
977430843
178716358
281435071
270578560
308202449
1012221554
876009823
219591668
934376857
540932921
495965657
1005226773
154449436
416832375
546627139
450989570
589867273
511096104
459834078
242454157
103224518
156144818
774445799
249600214
866314305
960861258
2368130
...

result:

wrong answer wrong answer on query #1: read 619669451 but expected 310305144