QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#511362#5451. 树据结构Franuch#0 0ms34996kbC++172.4kb2024-08-09 19:43:202024-08-09 19:43:20

Judging History

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

  • [2024-08-09 19:43:20]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:34996kb
  • [2024-08-09 19:43:20]
  • 提交

answer

#include "ds.h"
#include <bits/stdc++.h>

using namespace std;
typedef int ll;
#define st first
#define nd second

struct Pair {
    ll v, mx;
};

vector<pair<ll, ll>> s;

vector<ll> rec(vector<Pair> a, ll l, ll max) {
    if (a.size() == 1)
        return {a[0].v};

    exchange(l, max);
    s.emplace_back(l, max);
    for (auto &[v, mx] : a) {
        mx = query(v + 1);
    }
    sort(a.begin(), a.end(), [](auto &v, auto &w) {
        return v.mx < w.mx;
    });

    vector<ll> ret;
    ret.push_back(a[0].v);
    vector<vector<Pair>> b = {{a[1]}};
    for (ll i = 2; i < a.size(); i++) {
        if (b.back()[0].mx == a[i].mx)
            b.back().push_back(a[i]);
        else {
            b.emplace_back();
            b.back().push_back(a[i]);
        }
    }

    l++;
    for (auto & part : b) {
        vector<ll> tmp = rec(part, l, part[0].mx);
        for (ll v: tmp)
            ret.push_back(v);
        l += (ll) part.size();
    }

    return ret;
}

void dlasciezki(ll n) {
    vector<Pair> a(n);
    for (ll v = 1; v < n; v++) {
        a[v].v = v;
        a[v].mx = query(v + 1);
    }
    sort(a.begin(), a.end(), [](auto &v, auto &w) {
        return v.mx < w.mx;
    });

    vector<ll> ret = {0};
    vector<vector<Pair>> b = {{a[1]}};
    for (ll i = 2; i < a.size(); i++) {
        if (b.back()[0].mx == a[i].mx)
            b.back().push_back(a[i]);
        else {
            b.emplace_back();
            b.back().push_back(a[i]);
        }
    }

    ll l = 1;
    for (auto & part : b) {
        vector<ll> tmp = rec(part, l, part[0].mx);
        for (ll v: tmp)
            ret.push_back(v);
        l += (ll) part.size();
    }

    vector<ll> ord(n - 1);
    std::iota(ord.begin(), ord.end(), 1);
    vector<ll> pos(n);
    std::iota(pos.begin(), pos.end(), -1);
    while (not s.empty()) {
        auto p = s.back();
        swap(pos[p.st], pos[p.nd]);
        swap(ord[pos[p.st]], ord[pos[p.nd]]);
        s.pop_back();
    }

    vector<ll> vord(n);
    for (ll i = 0; i < n; i++)
        vord[ret[i]] = i;

    vector<ll> parent(n - 1), val(n - 1);
    for (ll i = 1; i < n; i++) {
        parent[i - 1] = ret[vord[i] - 1] + 1;
        val[i - 1] = ord[vord[i] - 1];
    }

    answer(parent, val);
}

void solve(ll n, ll lim1, ll lim2) {
    ll subtask = lim1 % 10;
    if (subtask == 1 or subtask == 3 or subtask == 6) {
        dlasciezki(n);
    }
}

详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 34612kb

input:

sfdjklasl2335n1j;llksaet35GTwejtklwrklakrjlt
50 1000001 1000001
2351tgsaldjkgakldfjtkjl;3136sajdflkjasdf135bbbwq
28 2 18 36 14 34 37 5 44 1 21 29 46 16 43 31 33 30 23 50 17 8 26 41 3 24 40 11 35 10 27 45 39 13 42 19 4 47 7 49 32 48 15 6 20 22 12 38 25
3 36 9 26 32 4 43 29 47 31 14 11 27 39 49 5 8 42...

output:


result:

wrong answer 1st lines differ - expected: '6640196347516987400', found: ''

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #1:

0%

Subtask #4:

score: 0
Wrong Answer

Test #16:

score: 0
Wrong Answer
time: 0ms
memory: 34996kb

input:

sfdjklasl2335n1j;llksaet35GTwejtklwrklakrjlt
20000 3000004 3000004
2351tgsaldjkgakldfjtkjl;3136sajdflkjasdf135bbbwq
4879 6169 1969 17706 4213 18093 4963 18252 19119 2557 12571 19437 17865 6637 7288 13247 12644 15689 13894 5948 4474 12271 18580 6962 20000 8024 17921 15238 125 4044 14282 297 2126 1468...

output:


result:

wrong answer 1st lines differ - expected: '11411519532273973792', found: ''

Subtask #5:

score: 0
Skipped

Dependency #1:

0%

Subtask #6:

score: 0
Skipped

Dependency #1:

0%

Subtask #7:

score: 0
Skipped

Dependency #1:

0%