QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#714937#9519. Build a ComputerlvliangAC ✓0ms4044kbC++143.5kb2024-11-06 09:18:412024-11-06 09:18:41

Judging History

This is the latest submission verdict.

  • [2024-11-06 09:18:41]
  • Judged
  • Verdict: AC
  • Time: 0ms
  • Memory: 4044kb
  • [2024-11-06 09:18:41]
  • Submitted

answer

#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <stack>
#include <cmath>
using namespace std;
typedef pair<int, int> PII;
const int N = 100;
PII pa[N];
vector<PII> ans[N];
int idx;

int max_lg(int num) {
    return (int)log2((pa[num].second ^ pa[num].first) + 1);
}

PII seperate_section(int l, int r) {
    int num1 = 1, num2 = 0;
    pa[1] = { l, l };
    int max_suf = 0;
    for (int i = 2; ; i++, num1++) {
        int x = pa[i - 1].second + 1;
        int y = x | pa[i - 1].second;
        if (y > r) break;
        //cout << x << ' ' << y << endl;
        pa[i] = { x, y };
    }
    max_suf = max(max_suf, max_lg(num1));
    if (pa[num1].second ^ r) {
        pa[++num1] = { r, r };
        num2 = num1;
        for (int i = num1 + 1; ; i++, num1++) {
            int x = pa[i - 1].first - 1;
            int y = x & pa[i - 1].first;
            if (y < l) break;
            //cout << y << ' ' << x << endl;
            pa[i] = { y, x };
        }
        max_suf = max(max_suf, max_lg(num1));
    }
    max_suf++;
    for (int i = 2; i <= max_suf; i++) {
        ans[i].push_back({ i - 1, 0 });
        ans[i].push_back({ i - 1, 1 });
    }
    idx = max_suf;
    return { num1, num2 };
}

stack<int> dec_bin(int x) {
    stack<int> ans;
    while (x) {
        ans.push(x % 2);
        x /= 2;
    }
    return ans;
}

void make_graph(PII num) {
    int x = num.first, y = num.second;
    int start = ++idx;
    if (y) {
        int tmp = pa[y].first;
        stack<int> stk = dec_bin(tmp);
        ans[start].push_back({ ++idx, 1 });
        stk.pop();
        vector<PII> vec;
        while (!stk.empty()) {
            int tp_val = stk.top();
            if (tp_val) {
                vec.push_back({ idx, stk.size() });
            }
            ans[idx].push_back({ stk.size() == 1 ? 1 : ++idx, tp_val });
            stk.pop();
        }
        int tmp1 = x;
        for (int i = vec.size() - 1; tmp1 > y; i--, tmp1--) {
            ans[vec[i].first].push_back({ vec[i].second, 0 });
        }
    }

    y = y ? y : x + 1;
    int tmp = pa[1].first;
    stack<int> stk = dec_bin(tmp);
    int stk_si = stk.size() + 1;
    vector<PII> vec;
    while (!stk.empty()) {
        int tp_val = stk.top();
        if (!tp_val) vec.push_back({ idx, stk.size() });
        if (stk.size() == stk_si - 1) {
            ans[start].push_back({ stk.size() == 1 ? 1 : ++idx, tp_val });
        } else {
            ans[idx].push_back({ stk.size() == 1 ? 1 : ++idx, tp_val });
        }
        
        stk.pop();
    }
    y--;
    if (vec.size() >= y) {
        y--;
        for (int i = vec.size() - 1; y > 0; i--, y--) {
            ans[vec[i].first].push_back({ vec[i].second, 1 });
        }
    } else {
        for (int i = 0; i < vec.size(); i++) {
            ans[vec[i].first].push_back({ vec[i].second, 1 });
        }
        for (int i = vec.size() + 1; i < y; i++) {
            ans[start].push_back({ stk_si++, 1 });
        }
    }
}

void out_ans() {
    printf("%d\n", idx);
    for (int i = 1; i <= idx; i++) {
        printf("%d", ans[i].size());
        for (auto x : ans[i]) {
            printf(" %d %d", x.first, x.second);
        }
        puts("");
    }
}

void solve() {
    int l, r;
    scanf("%d%d", &l, &r);
    auto num = seperate_section(l, r);

    make_graph(num);

    out_ans();
}

int main() {
    solve();
    return 0;
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3748kb

input:

5 7

output:

5
0
2 1 0 1 1
1 4 1
2 5 0 2 1
1 1 1

result:

ok ok

Test #2:

score: 0
Accepted
time: 0ms
memory: 3852kb

input:

10 27

output:

12
0
2 1 0 1 1
2 2 0 2 1
2 3 0 3 1
2 6 1 10 1
2 7 1 4 0
1 8 0
2 9 1 2 0
2 1 1 1 0
2 11 0 3 1
1 12 1
2 1 0 1 1

result:

ok ok

Test #3:

score: 0
Accepted
time: 0ms
memory: 3860kb

input:

5 13

output:

9
0
2 1 0 1 1
2 2 0 2 1
2 5 1 8 1
2 6 1 3 0
1 7 0
2 1 1 1 0
2 9 0 2 1
1 1 1

result:

ok ok

Test #4:

score: 0
Accepted
time: 0ms
memory: 3912kb

input:

1 1000000

output:

39
0
2 1 0 1 1
2 2 0 2 1
2 3 0 3 1
2 4 0 4 1
2 5 0 5 1
2 6 0 6 1
2 7 0 7 1
2 8 0 8 1
2 9 0 9 1
2 10 0 10 1
2 11 0 11 1
2 12 0 12 1
2 13 0 13 1
2 14 0 14 1
2 15 0 15 1
2 16 0 16 1
2 17 0 17 1
2 18 0 18 1
20 21 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 1 10 1 11 1 12 1 13 1 14 1 15 1 16 1 17 1 18 1 19 1
2 2...

result:

ok ok

Test #5:

score: 0
Accepted
time: 0ms
memory: 3848kb

input:

1 1

output:

2
0
1 1 1

result:

ok ok

Test #6:

score: 0
Accepted
time: 0ms
memory: 3788kb

input:

7 9

output:

7
0
2 3 1 6 1
1 4 0
1 5 0
2 1 1 1 0
1 7 1
1 1 1

result:

ok ok

Test #7:

score: 0
Accepted
time: 0ms
memory: 3744kb

input:

3 7

output:

5
0
2 1 0 1 1
2 2 0 2 1
2 5 1 3 1
1 1 1

result:

ok ok

Test #8:

score: 0
Accepted
time: 0ms
memory: 3912kb

input:

1 5

output:

5
0
2 1 0 1 1
3 4 1 1 1 2 1
1 5 0
2 1 1 1 0

result:

ok ok

Test #9:

score: 0
Accepted
time: 0ms
memory: 3968kb

input:

1 4

output:

5
0
2 1 0 1 1
3 4 1 1 1 2 1
1 5 0
1 1 0

result:

ok ok

Test #10:

score: 0
Accepted
time: 0ms
memory: 4044kb

input:

8 9

output:

5
0
1 3 1
1 4 0
1 5 0
2 1 0 1 1

result:

ok ok

Test #11:

score: 0
Accepted
time: 0ms
memory: 3848kb

input:

7 51

output:

13
0
2 1 0 1 1
2 2 0 2 1
2 3 0 3 1
2 4 0 4 1
4 7 1 12 1 4 1 5 1
2 8 1 5 0
1 9 0
1 10 0
2 11 1 2 0
2 1 1 1 0
1 13 1
1 1 1

result:

ok ok

Test #12:

score: 0
Accepted
time: 0ms
memory: 4044kb

input:

51 79

output:

16
0
2 1 0 1 1
2 2 0 2 1
2 3 0 3 1
2 6 1 12 1
1 7 0
1 8 0
2 9 1 4 0
2 10 1 3 0
2 11 1 2 0
2 1 1 1 0
1 13 1
2 14 0 4 1
2 15 0 3 1
1 16 1
1 1 1

result:

ok ok

Test #13:

score: 0
Accepted
time: 0ms
memory: 3972kb

input:

92 99

output:

15
0
2 1 0 1 1
2 4 1 10 1
1 5 1
1 6 0
1 7 0
1 8 0
2 9 1 2 0
2 1 1 1 0
1 11 0
1 12 1
1 13 1
1 14 1
2 15 0 2 1
2 1 0 1 1

result:

ok ok

Test #14:

score: 0
Accepted
time: 0ms
memory: 3912kb

input:

27 36

output:

13
0
2 1 0 1 1
2 2 0 2 1
2 5 1 10 1
1 6 0
1 7 0
2 8 1 3 0
1 9 0
1 1 0
1 11 1
2 12 0 3 1
1 13 1
1 1 1

result:

ok ok

Test #15:

score: 0
Accepted
time: 0ms
memory: 3852kb

input:

55 84

output:

17
0
2 1 0 1 1
2 2 0 2 1
2 3 0 3 1
2 4 0 4 1
2 7 1 13 1
1 8 0
2 9 1 5 0
1 10 0
2 11 1 3 0
1 12 0
1 1 0
1 14 1
2 15 0 4 1
1 16 1
1 17 1
1 1 1

result:

ok ok

Test #16:

score: 0
Accepted
time: 0ms
memory: 4040kb

input:

297208 929600

output:

57
0
2 1 0 1 1
2 2 0 2 1
2 3 0 3 1
2 4 0 4 1
2 5 0 5 1
2 6 0 6 1
2 7 0 7 1
2 8 0 8 1
2 9 0 9 1
2 10 0 10 1
2 11 0 11 1
2 12 0 12 1
2 13 0 13 1
2 14 0 14 1
2 15 0 15 1
2 16 0 16 1
2 17 0 17 1
2 18 0 18 1
2 21 1 40 1
2 22 1 19 0
2 23 1 18 0
1 24 0
1 25 0
1 26 0
2 27 1 14 0
1 28 0
2 29 1 12 0
2 30 1 11...

result:

ok ok

Test #17:

score: 0
Accepted
time: 0ms
memory: 3852kb

input:

45728 589156

output:

54
0
2 1 0 1 1
2 2 0 2 1
2 3 0 3 1
2 4 0 4 1
2 5 0 5 1
2 6 0 6 1
2 7 0 7 1
2 8 0 8 1
2 9 0 9 1
2 10 0 10 1
2 11 0 11 1
2 12 0 12 1
2 13 0 13 1
2 14 0 14 1
2 15 0 15 1
2 16 0 16 1
2 17 0 17 1
2 18 0 18 1
5 21 1 40 1 17 1 18 1 19 1
1 22 0
1 23 0
1 24 0
2 25 1 16 0
2 26 1 15 0
2 27 1 14 0
2 28 1 13 0
2...

result:

ok ok

Test #18:

score: 0
Accepted
time: 0ms
memory: 3916kb

input:

129152 138000

output:

47
0
2 1 0 1 1
2 2 0 2 1
2 3 0 3 1
2 4 0 4 1
2 5 0 5 1
2 6 0 6 1
2 7 0 7 1
2 8 0 8 1
2 9 0 9 1
2 10 0 10 1
2 11 0 11 1
2 12 0 12 1
2 15 1 32 1
1 16 0
1 17 0
1 18 0
1 19 0
2 20 1 13 0
2 21 1 12 0
1 22 0
2 23 1 10 0
2 24 1 9 0
1 25 0
1 26 0
1 27 0
2 28 1 5 0
1 29 0
1 30 0
1 31 0
1 1 0
1 33 1
1 34 1
1 ...

result:

ok ok

Test #19:

score: 0
Accepted
time: 0ms
memory: 3912kb

input:

245280 654141

output:

56
0
2 1 0 1 1
2 2 0 2 1
2 3 0 3 1
2 4 0 4 1
2 5 0 5 1
2 6 0 6 1
2 7 0 7 1
2 8 0 8 1
2 9 0 9 1
2 10 0 10 1
2 11 0 11 1
2 12 0 12 1
2 13 0 13 1
2 14 0 14 1
2 15 0 15 1
2 16 0 16 1
2 17 0 17 1
2 18 0 18 1
3 21 1 40 1 19 1
1 22 0
1 23 0
2 24 1 17 0
2 25 1 16 0
2 26 1 15 0
2 27 1 14 0
2 28 1 13 0
2 29 1...

result:

ok ok

Test #20:

score: 0
Accepted
time: 0ms
memory: 3928kb

input:

202985 296000

output:

52
0
2 1 0 1 1
2 2 0 2 1
2 3 0 3 1
2 4 0 4 1
2 5 0 5 1
2 6 0 6 1
2 7 0 7 1
2 8 0 8 1
2 9 0 9 1
2 10 0 10 1
2 11 0 11 1
2 12 0 12 1
2 13 0 13 1
2 14 0 14 1
2 15 0 15 1
2 18 1 36 1
1 19 0
1 20 0
2 21 1 16 0
1 22 0
1 23 0
1 24 0
1 25 0
2 26 1 11 0
1 27 0
1 28 0
1 29 0
2 30 1 7 0
1 31 0
1 32 0
1 33 0
1 ...

result:

ok ok

Test #21:

score: 0
Accepted
time: 0ms
memory: 3972kb

input:

438671 951305

output:

57
0
2 1 0 1 1
2 2 0 2 1
2 3 0 3 1
2 4 0 4 1
2 5 0 5 1
2 6 0 6 1
2 7 0 7 1
2 8 0 8 1
2 9 0 9 1
2 10 0 10 1
2 11 0 11 1
2 12 0 12 1
2 13 0 13 1
2 14 0 14 1
2 15 0 15 1
2 16 0 16 1
2 17 0 17 1
2 18 0 18 1
2 21 1 40 1
2 22 1 19 0
2 23 1 18 0
1 24 0
2 25 1 16 0
1 26 0
1 27 0
1 28 0
1 29 0
2 30 1 11 0
1 ...

result:

ok ok

Test #22:

score: 0
Accepted
time: 0ms
memory: 4044kb

input:

425249 739633

output:

56
0
2 1 0 1 1
2 2 0 2 1
2 3 0 3 1
2 4 0 4 1
2 5 0 5 1
2 6 0 6 1
2 7 0 7 1
2 8 0 8 1
2 9 0 9 1
2 10 0 10 1
2 11 0 11 1
2 12 0 12 1
2 13 0 13 1
2 14 0 14 1
2 15 0 15 1
2 16 0 16 1
2 17 0 17 1
2 20 1 39 1
1 21 0
2 22 1 18 0
2 23 1 17 0
1 24 0
2 25 1 15 0
1 26 0
1 27 0
2 28 1 12 0
1 29 0
1 30 0
2 31 1 ...

result:

ok ok

Test #23:

score: 0
Accepted
time: 0ms
memory: 3968kb

input:

551207 961718

output:

57
0
2 1 0 1 1
2 2 0 2 1
2 3 0 3 1
2 4 0 4 1
2 5 0 5 1
2 6 0 6 1
2 7 0 7 1
2 8 0 8 1
2 9 0 9 1
2 10 0 10 1
2 11 0 11 1
2 12 0 12 1
2 13 0 13 1
2 14 0 14 1
2 15 0 15 1
2 16 0 16 1
2 17 0 17 1
2 20 1 39 1
1 21 1
2 22 1 18 0
1 23 0
2 24 1 16 0
1 25 0
2 26 1 14 0
1 27 0
2 28 1 12 0
2 29 1 11 0
1 30 0
1 ...

result:

ok ok

Test #24:

score: 0
Accepted
time: 0ms
memory: 3912kb

input:

114691 598186

output:

55
0
2 1 0 1 1
2 2 0 2 1
2 3 0 3 1
2 4 0 4 1
2 5 0 5 1
2 6 0 6 1
2 7 0 7 1
2 8 0 8 1
2 9 0 9 1
2 10 0 10 1
2 11 0 11 1
2 12 0 12 1
2 13 0 13 1
2 14 0 14 1
2 15 0 15 1
2 16 0 16 1
2 17 0 17 1
2 18 0 18 1
4 21 1 40 1 18 1 19 1
1 22 0
1 23 0
2 24 1 17 0
1 25 0
1 26 0
2 27 1 14 0
1 28 0
1 29 0
1 30 0
1 ...

result:

ok ok

Test #25:

score: 0
Accepted
time: 0ms
memory: 3968kb

input:

234654 253129

output:

49
0
2 1 0 1 1
2 2 0 2 1
2 3 0 3 1
2 4 0 4 1
2 5 0 5 1
2 6 0 6 1
2 7 0 7 1
2 8 0 8 1
2 9 0 9 1
2 10 0 10 1
2 11 0 11 1
2 12 0 12 1
2 13 0 13 1
2 16 1 33 1
1 17 1
1 18 1
1 19 1
1 20 0
2 21 1 13 0
2 22 1 12 0
2 23 1 11 0
1 24 0
1 25 0
2 26 1 8 0
2 27 1 7 0
1 28 0
1 29 0
2 30 1 4 0
1 31 0
1 32 0
2 1 1 ...

result:

ok ok

Test #26:

score: 0
Accepted
time: 0ms
memory: 3748kb

input:

554090 608599

output:

55
0
2 1 0 1 1
2 2 0 2 1
2 3 0 3 1
2 4 0 4 1
2 5 0 5 1
2 6 0 6 1
2 7 0 7 1
2 8 0 8 1
2 9 0 9 1
2 10 0 10 1
2 11 0 11 1
2 12 0 12 1
2 13 0 13 1
2 14 0 14 1
2 15 0 15 1
2 18 1 37 1
1 19 0
1 20 0
1 21 1
1 22 0
2 23 1 15 0
1 24 0
1 25 0
2 26 1 12 0
1 27 0
1 28 0
2 29 1 9 0
1 30 0
2 31 1 7 0
1 32 0
2 33 ...

result:

ok ok

Extra Test:

score: 0
Extra Test Passed