QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#689388#9519. Build a ComputernonanalyzerAC ✓1ms3732kbC++172.8kb2024-10-30 16:45:442024-10-30 16:45:48

Judging History

This is the latest submission verdict.

  • [2024-10-30 16:45:48]
  • Judged
  • Verdict: AC
  • Time: 1ms
  • Memory: 3732kb
  • [2024-10-30 16:45:44]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
const int maxn=1005;

int get(int x)
{
    int p=1,q=1;
    while(p<=x) p<<=1,q++;
    return q-1;
}

struct edge
{
    int u,v,w;
    edge(int u=0,int v=0,int w=0) : u(u),v(v),w(w) {}
};

vector<edge> ed;
vector<pair<int,int> > G[maxn];
int cnt=0;
int maxlen = 0, mr = 0;
void dfs(int pos,int L,int R,int las, int odd)
{
    L&=((1<<pos)-1);
    R&=((1<<pos)-1);
    if(pos == 1){
        if(L == R) ed.emplace_back(las, 2, L);
        else ed.emplace_back(las, 2, 0), ed.emplace_back(las, 2, 1);
        return;
    }
    if(L==0&&R==((1<<pos)-1))
    {
        if(pos <= maxlen){
            ed.emplace_back(las, mr - pos + 2, 0);
            ed.emplace_back(las, mr - pos + 2, 1);
            return;
        }
        for(int i=1;i<=pos-1;++i)
        {
            int u=++cnt;
            ed.emplace_back(las,u,0);
            ed.emplace_back(las,u,1);
            las=u;
        }
        ed.emplace_back(las,2,0);
        ed.emplace_back(las,2,1);
        maxlen = pos - 1, mr = cnt;
        return;
    }
    int u=++cnt;
    if((L>>pos-1)==(R>>pos-1))
    {
        ed.emplace_back(las,u,(L>>pos-1));
        dfs(pos-1,L,R,u, odd^1);
    }
    else
    {
        int v=++cnt;
        if(odd){
            ed.emplace_back(las,u,0);
            dfs(pos-1,L,R|((1<<pos)-1),u, odd^1);
            ed.emplace_back(las,v,1);
            dfs(pos-1,0,R,v, odd^1);
        }
        else{
            ed.emplace_back(las,v,1);
            dfs(pos-1,0,R,v, odd^1);
            ed.emplace_back(las,u,0);
            dfs(pos-1,L,R|((1<<pos)-1),u, odd^1);
        }
    }
}

int main()
{
    #ifdef local
    freopen("data.in", "r", stdin);
    #endif
    int L,R,x,y,S=1,T=2;
    cnt=2;
    cin>>L>>R;
    x=get(L);
    y=get(R);
    if(x==y){
        dfs(x,L,R,1, 0);
    }
    else{
        if(x <= y-2){
            for(int i=1;i<=y-2;++i)
            {
                int u=++cnt;
                if(i==1)
                {
                    ed.emplace_back(S,u,1);
                }
                else
                {
                    ed.emplace_back(u-1,u,0);
                    ed.emplace_back(u-1,u,1);
                }
                if(i==y-2)
                {
                    ed.emplace_back(u,T,0);
                    ed.emplace_back(u,T,1);
                }
            }
            maxlen = y - 2, mr = cnt;
        }
        for(int i = x+1; i <= y-2; ++i) dfs(i-1, 0, 0xffffff, 3, 0);
        dfs(y,1<<(y-1),R,S, 0);
        dfs(x,L,(1<<x)-1,S, 0);
    }
    cout<<cnt<<endl;
    for(auto [u,v,w]:ed)
	{
		G[u].emplace_back(v,w); 
	}
    for(int i=1;i<=cnt;++i)
    {
        cout<<G[i].size()<<' ';
        for(auto [v,w]:G[i])
            cout<<v<<' '<<w<<' ';
        cout<<endl;
    }
    return 0;
}

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

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3660kb

input:

5 7

output:

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

result:

ok ok

Test #2:

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

input:

10 27

output:

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

result:

ok ok

Test #3:

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

input:

5 13

output:

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

result:

ok ok

Test #4:

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

input:

1 1000000

output:

45
3 3 1 21 1 2 1 
0 
36 4 0 4 1 2 0 2 1 20 0 20 1 19 0 19 1 18 0 18 1 17 0 17 1 16 0 16 1 15 0 15 1 14 0 14 1 13 0 13 1 12 0 12 1 11 0 11 1 10 0 10 1 9 0 9 1 8 0 8 1 7 0 7 1 6 0 6 1 5 0 5 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...

result:

ok ok

Test #5:

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

input:

1 1

output:

2
1 2 1 
0 

result:

ok ok

Test #6:

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

input:

7 9

output:

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

result:

ok ok

Test #7:

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

input:

3 7

output:

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

result:

ok ok

Test #8:

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

input:

1 5

output:

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

result:

ok ok

Test #9:

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

input:

1 4

output:

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

result:

ok ok

Test #10:

score: 0
Accepted
time: 1ms
memory: 3664kb

input:

8 9

output:

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

result:

ok ok

Test #11:

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

input:

7 51

output:

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

result:

ok ok

Test #12:

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

input:

51 79

output:

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

result:

ok ok

Test #13:

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

input:

92 99

output:

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

result:

ok ok

Test #14:

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

input:

27 36

output:

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

result:

ok ok

Test #15:

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

input:

55 84

output:

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

result:

ok ok

Test #16:

score: 0
Accepted
time: 1ms
memory: 3656kb

input:

297208 929600

output:

70
2 3 1 47 1 
0 
2 4 0 5 1 
2 6 0 6 1 
2 24 1 23 0 
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 19 0 19 1 
2 20 0 20 1 
2 21 0 21 1 
2 22 0 22 1 
2 2 0 2 1 
2 7 0 7 1 
1 25 0 
1 26 0 
1 27 0 ...

result:

ok ok

Test #17:

score: 0
Accepted
time: 1ms
memory: 3588kb

input:

45728 589156

output:

65
3 3 1 21 1 50 1 
0 
6 4 0 4 1 6 0 6 1 5 0 5 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 19 0 19 1 
2 20 0 20 1 
2 2 0 2 1 
1 22 0 
1 23 0 
1 24 0 
2 26 1 25 0 
2 7 ...

result:

ok ok

Test #18:

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

input:

129152 138000

output:

48
2 3 1 36 1 
0 
1 4 0 
1 5 0 
1 6 0 
1 7 0 
2 8 0 9 1 
2 10 0 10 1 
2 22 1 21 0 
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 19 0 19 1 
2 20 0 20 1 
2 2 0 2 1 
2 11 0 11 1 
1 23 0 
2 25 1 24 0 
2 13 0 13 1 
2 26 0 27 1 
2 14 0 14 1 
1 2...

result:

ok ok

Test #19:

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

input:

245280 654141

output:

68
3 3 1 21 1 52 1 
0 
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 19 0 19 1 
2 20 0 20 1 
2 2 0 2 1 
1 22 0 
1 23 0 
2 24 0 25 1 
2 6 0 6 1 
2 27 1 26 0 
2 7 ...

result:

ok ok

Test #20:

score: 0
Accepted
time: 1ms
memory: 3724kb

input:

202985 296000

output:

77
2 3 1 38 1 
0 
1 4 0 
1 5 0 
2 6 0 7 1 
2 8 0 8 1 
1 22 0 
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 19 0 19 1 
2 20 0 20 1 
2 21 0 21 1 
2 2 0 2 1 
1 23 0 
1 24 0 
1 25 0 
2 27 1 26 0 
2 13 0 13 1 
1 28 0 
1 ...

result:

ok ok

Test #21:

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

input:

438671 951305

output:

69
2 3 1 44 1 
0 
2 4 0 5 1 
2 6 0 6 1 
2 24 1 23 0 
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 19 0 19 1 
2 20 0 20 1 
2 21 0 21 1 
2 22 0 22 1 
2 2 0 2 1 
2 7 0 7 1 
1 25 0 
2 27 1 26 0 
2 ...

result:

ok ok

Test #22:

score: 0
Accepted
time: 1ms
memory: 3612kb

input:

425249 739633

output:

86
2 3 1 60 1 
0 
1 4 0 
2 6 1 5 0 
2 44 0 44 1 
2 7 0 8 1 
2 9 0 9 1 
1 24 0 
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 19 0 19 1 
2 20 0 20 1 
2 21 0 21 1 
2 22 0 22 1 
2 23 0 23 1 
2 2 0 2 1 
2 25 0 26 1 
2 11 0 11 1 
1 ...

result:

ok ok

Test #23:

score: 0
Accepted
time: 1ms
memory: 3732kb

input:

551207 961718

output:

91
1 3 1 
0 
2 4 0 5 1 
2 7 1 6 0 
2 50 1 49 0 
2 24 0 25 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 19 0 19 1 
2 20 0 20 1 
2 21 0 21 1 
2 22 0 22 1 
2 23 0 23 1 
2 2 0 2 1 
2 27 1 26 0 
2 9 0 9 1 
...

result:

ok ok

Test #24:

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

input:

114691 598186

output:

73
3 3 1 21 1 46 1 
0 
4 4 0 4 1 5 0 5 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 19 0 19 1 
2 20 0 20 1 
2 2 0 2 1 
1 22 0 
1 23 0 
2 24 0 25 1 
2 6 0 6 1 
1 26 0 
1...

result:

ok ok

Test #25:

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

input:

234654 253129

output:

57
1 3 1 
0 
1 4 1 
1 5 1 
2 6 0 7 1 
2 9 1 8 0 
1 39 0 
1 22 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 19 0 19 1 
2 20 0 20 1 
2 21 0 21 1 
2 2 0 2 1 
2 24 1 23 0 
1 25 1 
2 12 0 12 1 
2 27 1 26 0 
2 28 0 29 1 
2 14 0 1...

result:

ok ok

Test #26:

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

input:

554090 608599

output:

61
1 3 1 
0 
1 4 0 
1 5 0 
2 6 0 7 1 
2 9 1 8 0 
1 44 0 
1 24 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 19 0 19 1 
2 20 0 20 1 
2 21 0 21 1 
2 22 0 22 1 
2 23 0 23 1 
2 2 0 2 1 
1 25 1 
1 26 1 
2 28 1 27 0 
1 29 1 
2 14 ...

result:

ok ok

Extra Test:

score: 0
Extra Test Passed