编号 题目 状态 分数 总时间 内存 代码 / 答案文件 提交者 提交时间
#49263 #1018. 1-01E. JM的俄罗斯套娃 Runtime Error 0 22 ms 416 K C++ 17 / 1.8 K afhi 2021-06-14 17:39:48
显示原始代码
#include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()

typedef long long ll;

struct node {
    bool is_num;
    int val;
    node* par;
    vector<node*> child;
    node(int n, node* p) {
        par = p;
        is_num = true;
        val = n;
    }
    node(node* p) {
        par = p;
        is_num = false;
    }
};

void insertPV(node* cur, int p, int val) {
    node* np;
    if (val == 0)
        np = new node(cur);
    else
        np = new node(val, cur);
    cur->child.push_back(np);
    int pos = cur->child.size() - 1;
    while (pos != p) {
        swap(cur->child[pos], cur->child[pos - 1]);
        pos--;
    }
}

void deleteP(node* cur, int p) {
    vector<node*> vs;
    for (int i = 0; i < cur->child.size(); i++) {
        if (i + 1 != p)
            vs.push_back(cur->child[i]);
    }
    cur->child = vs;
}

int main() {
    cin.tie(0)->sync_with_stdio(false);
    cin.exceptions(cin.failbit);
    int q, op, p, v;
    cin >> q;
    node root = node(nullptr);
    node* curA = &root;
    while (q) {
        cin >> op;
        if (op == 1) {
            cin >> p >> v;
            insertPV(curA, p, v);
        } else if (op == 2) {
            cin >> p;
            deleteP(curA, p);
        } else if (op == 3) {
            cin >> p;
            if (p == 0) {
                if (curA != &root)
                    curA = curA->par;
            } else {
                if (p - 1 < curA->child.size() && !curA->child[p - 1]->is_num)
                    curA = curA->child[p - 1];
            }
        } else {
            cout << "{";
            vector<node*>& vs = curA->child;
            for (int i = 0; i < vs.size(); i++) {
                if (vs[i]->is_num)
                    cout << vs[i]->val;
                else
                    cout << "[]";
                if (i != vs.size() - 1)
                    cout << " ";
            }
            cout << "}" << endl;
        }
    }
    return 0;
}
子任务 #1
Runtime Error
得分:0
测试点 #1
Runtime Error
得分:0
用时:4 ms
内存:416 KiB

输入文件(1.in

12
1 0 1
1 0 2
1 1 0
4
2 3
4
3 2
4
1 0 6
4
3 0
4

答案文件(1.out

{2 [] 1}
{2 []}
{}
{6}
{2 []}

用户输出

{2 [] 1}
{2 []}
{}
{6}
{2 []}

标准错误流

terminate called after throwing an instance of 'std::__ios_failure'
  what():  basic_ios::clear: iostream error

系统信息

Killed: Segmentation fault
测试点 #2
Runtime Error
得分:0
用时:2 ms
内存:376 KiB

输入文件(2.in

10
1 0 1
1 0 2
1 1 3
1 1 4
1 3 5
1 5 6
4
2 2
2 4
4

答案文件(2.out

{2 4 3 5 1 6}
{2 3 5 6}

用户输出

{2 4 3 5 1 6}
{2 3 5 6}

标准错误流

terminate called after throwing an instance of 'std::__ios_failure'
  what():  basic_ios::clear: iostream error

系统信息

Killed: Segmentation fault
测试点 #3
Runtime Error
得分:0
用时:2 ms
内存:376 KiB

输入文件(3.in

28
1 0 12
1 1 4
1 1 7
1 2 0
1 0 0
2 2
4
3 1
1 0 89
1 1 0
1 0 0
1 3 0
4
3 0
4
3 3
4
<50 bytes omitted>

答案文件(3.out

{[] 7 [] 4}
{[] 89 [] []}
{[] 7 [] 4}
{}
{1}
{}
{[] 7 [] 4}
{[] [] 4}

用户输出

{[] 7 [] 4}
{[] 89 [] []}
{[] 7 [] 4}
{}
{1}
{}
{[] 7 [] 4}
{[] [] 4}

标准错误流

terminate called after throwing an instance of 'std::__ios_failure'
  what():  basic_ios::clear: iostream error

系统信息

Killed: Segmentation fault
测试点 #4
Runtime Error
得分:0
用时:2 ms
内存:376 KiB

输入文件(4.in

20
1 0 0
1 1 1
1 0 0
1 3 2
4
3 1
1 0 17
1 1 12
1 2 19
2 1
1 0 23
1 3 0
4
3 0
3 1
3 0
<16 bytes omitted>

答案文件(4.out

{[] [] 1 2}
{23 12 19 []}
{[] 1 2}
{}

用户输出

{[] [] 1 2}
{23 12 19 []}
{[] 1 2}
{}

标准错误流

terminate called after throwing an instance of 'std::__ios_failure'
  what():  basic_ios::clear: iostream error

系统信息

Killed: Segmentation fault
测试点 #5
Runtime Error
得分:0
用时:2 ms
内存:348 KiB

输入文件(5.in

45
1 0 11
1 1 0
2 1
1 0 32
4
3 2
1 0 0
1 1 0
1 2 40
1 3 0
4
3 3
4
3 2
1 0 0
3 1
1 0
<129 bytes omitted>

答案文件(5.out

{32 []}
{[] [] 40 []}
{[] [] 40 []}
{12}
{[]}
{12}
{[] [] 40 []}
{32 []}
{32 []}
{[] [] 40 
<26 bytes omitted>

用户输出

{32 []}
{[] [] 40 []}
{[] [] 40 []}
{12}
{[]}
{12}
{[] [] 40 []}
{32 []}
{32 []}
{[] [] 40 []}
{[] 40 []}
{32 []}

标准错误流

terminate called after throwing an instance of 'std::__ios_failure'
  what():  basic_ios::clear: iostream error

系统信息

Killed: Segmentation fault
测试点 #6
Runtime Error
得分:0
用时:2 ms
内存:376 KiB

输入文件(6.in

50
1 0 12
1 0 8
1 0 19
1 3 6
4
1 4 34
1 5 7
1 5 8
4
1 7 91
1 1 1
1 7 2
1 0 12
4
1 0 8
<251 bytes omitted>

答案文件(6.out

{19 8 12 6}
{19 8 12 6 34 8 7}
{12 19 1 8 12 6 34 8 2 7 91}
{19 8 12 6 34 7 19 1 8 12 6 34 8 2 7 
<259 bytes omitted>

用户输出

{19 8 12 6}
{19 8 12 6 34 8 7}
{12 19 1 8 12 6 34 8 2 7 91}
{19 8 12 6 34 7 19 1 8 12 6 34 8 2 7 91}
{19 8 12 6 34 8 7 19 1 8 12
<224 bytes omitted>

标准错误流

terminate called after throwing an instance of 'std::__ios_failure'
  what():  basic_ios::clear: iostream error

系统信息

Killed: Segmentation fault
测试点 #7
Runtime Error
得分:0
用时:2 ms
内存:376 KiB

输入文件(7.in

50
1 0 0
1 0 8
2 2
1 1 6
4
1 2 34
1 3 0
1 3 8
4
1 4 0
2 1
1 4 2
1 0 12
4
1 0 8
1 0 1
<234 bytes omitted>

答案文件(7.out

{8 6}
{8 6 34 8 []}
{12 6 34 8 [] 2 []}
{19 8 12 6 34 7 6 34 8 [] 2 []}
{12 19 [] 6 74 83 [] 8 1
<186 bytes omitted>

用户输出

{8 6}
{8 6 34 8 []}
{12 6 34 8 [] 2 []}
{19 8 12 6 34 7 6 34 8 [] 2 []}
{12 19 [] 6 74 83 [] 8 12 6 34 8 2 7 6 95 34 8 [] 2 []}

<151 bytes omitted>

标准错误流

terminate called after throwing an instance of 'std::__ios_failure'
  what():  basic_ios::clear: iostream error

系统信息

Killed: Segmentation fault
测试点 #8
Runtime Error
得分:0
用时:2 ms
内存:348 KiB

输入文件(8.in

50
1 0 0
1 1 0
1 0 29
1 3 0
1 0 8
1 5 0
1 1 88
1 2 0
2 8
4
3 5
1 0 63
1 0 52
1 2 19
1
<187 bytes omitted>

答案文件(8.out

{8 88 [] 29 [] [] []}
{63 7}
{8 88 [] 29 [] [] []}
{18 71 33}
{18}
{5 15 45}
{9 15 45}
{9 15 
<16 bytes omitted>

用户输出

{8 88 [] 29 [] [] []}
{63 7}
{8 88 [] 29 [] [] []}
{18 71 33}
{18}
{5 15 45}
{9 15 45}
{9 15 45}
{9 15 45}

标准错误流

terminate called after throwing an instance of 'std::__ios_failure'
  what():  basic_ios::clear: iostream error

系统信息

Killed: Segmentation fault
测试点 #9
Runtime Error
得分:0
用时:2 ms
内存:376 KiB

输入文件(9.in

12
3 0
1 0 0
3 1
1 0 9
3 1
4
3 0
4
2 1
1 0 0
3 1
4

答案文件(9.out

{9}
{[]}
{}

用户输出

{9}
{[]}
{}

标准错误流

terminate called after throwing an instance of 'std::__ios_failure'
  what():  basic_ios::clear: iostream error

系统信息

Killed: Segmentation fault
测试点 #10
Runtime Error
得分:0
用时:2 ms
内存:376 KiB

输入文件(10.in

32
1 0 46
3 1
1 1 0
4
2 1
3 1
4
1 0 0
3 1
4
1 0 0
3 1
1 0 0
3 1
1 0 12
1 0 14
1 2 2
<73 bytes omitted>

答案文件(10.out

{46 []}
{}
{}
{14 24}
{94}
{[]}
{7}

用户输出

{46 []}
{}
{}
{14 24}
{94}
{[]}
{7}

标准错误流

terminate called after throwing an instance of 'std::__ios_failure'
  what():  basic_ios::clear: iostream error

系统信息

Killed: Segmentation fault