QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#757647#9519. Build a ComputerDarwinA66AC ✓0ms3924kbC++205.8kb2024-11-17 11:48:142024-11-17 11:48:15

Judging History

This is the latest submission verdict.

  • [2024-11-17 11:48:15]
  • Judged
  • Verdict: AC
  • Time: 0ms
  • Memory: 3924kb
  • [2024-11-17 11:48:14]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
int L[25],R[25],R2[25],L2[25];
vector<pair<int,int>>G[150];
int main()
{
    int l,r,r2,l2;
    int l_maxbit=0;
    int r_maxbit=0;
    int l_minbit=25;
    int r_minbit=25;
    scanf("%d %d",&l,&r);
    r2=r+1;
    l2=1048576-l;
    for(int i=0;i<20;i++)
    {
        L[i]=l%2;
        L2[i]=l2%2;
        R[i]=r%2;
        R2[i]=r2%2;
        l/=2;
        l2/=2;
        r/=2;
        r2/=2;
        if(L[i]==1)l_maxbit=max(l_maxbit,i);
        if(R[i]==1)r_maxbit=max(r_maxbit,i);
    }
    for(int i=19;i>=0;i--)
    {
        if(R2[i]==1)r_minbit=min(r_minbit,i);
        if(L2[i]==1)l_minbit=min(l_minbit,i);
    }
    int total=1;
    int max_bit=max(l_maxbit,r_maxbit);
    int curr=max_bit;
    for(;(L[curr]==R[curr])&&curr>=0;curr--)
    {
        G[max_bit+1-curr].push_back({max_bit-curr+2,R[curr]});
        total++;
    }
    int div=total;
    int div_curr=curr;
    int div_max,div_mid,div_min;
    int end;
    div_max=total+1;
    if(curr<0)
    {
        printf("%d\n",total);
        for(int i=1;i<=total;i++)
        {
            printf("%d ",G[i].size());
            for(int j=0;j<G[i].size();j++)
            {
                printf("%d %d",G[i][j].first,G[i][j].second);
            }
            printf("\n");
        }
        return 0;
    }
    if(curr>=0)
    {
        G[max_bit+1-curr].push_back({max_bit-curr+2,R[curr]});
        total++;
    }
    //printf("!%d\n",curr);
    for(curr-=1;curr>=0;curr--)
    {
        if(R[curr]==1)break;
        else
        {
            G[max_bit+1-curr].push_back({max_bit-curr+2,R[curr]});
            total++;
        }
    }
    //printf("!%d\n",curr);
    if(r_minbit>curr&&curr>=0)
    {
        G[total].push_back({total+1,0});
        G[total].push_back({total+1,1});
        total++;
    }
    else if(curr>=0)
    {
        G[total].push_back({total+1,0});
        total++;
    }
    curr--;
    int back01=total-1;
    int back02=total;
    //printf("!%d\n",curr);
    for(;curr>=0;curr--)
    {
        if(curr>=r_minbit)
        {
            G[back01].push_back({total+1,R[curr+1]});
            total++;
            back01=total;
            if(R2[curr])G[total].push_back({total+1,0});
        }
        total++;
        G[back02].push_back({total,0});
        G[back02].push_back({total,1});
        back02=total;
    }
    end=total;
    div_min=total+1;
    curr=div_curr;
    int back;
    int so=0;
    if(l_maxbit<r_maxbit)
    {
        while(!L[curr])curr--;
        back=div;
        //printf("correct\n");
    }
    else if(curr>=0)
    {
        if(curr==0)
        {
            G[div].push_back({end,L[curr]});
        }
        else
        {
            G[div].push_back({div_min,L[curr]});
            total++;
            back=total;
        }
    }
    //printf("!!%d %d %d\n",back,curr,total);
    for(curr-=(l_maxbit==r_maxbit);curr>=0;curr--)
    {
        if(L[curr]==0)break;
        else
        {
            //printf("cc!\n");
            if(curr==0)
            {
                //printf("correct!\n");
                G[back].push_back({end,L[curr]});
            }
            else
            {
                G[back].push_back({total+1,L[curr]});
                total++;
                back=total;
            }
        }
    }
    //printf("!!%d\n",curr);
    //printf("!!!%d\n",total);
    int back1,back2;
    if((curr<l_minbit)&&curr>=0)
    {
        G[total].push_back({total+1,0});
        G[total].push_back({total+1,1});
        total++;
    }
    else if(curr>=0)
    {
        G[total].push_back({total+1,1});
        total++;
    }
    curr--;
    //printf("!!%d\n",curr);
    //printf("!!!%d\n",total);
    back1=total;
    back2=total-1;
    for(;curr>=0;curr--)
    {
        if(curr==0)
        {
            if(curr>=l_minbit)
            {
                G[back2].push_back({total+1,L[curr+1]});
                total++;
                if(L2[curr])G[total].push_back({end,1});
            }
            G[back1].push_back({end,0});
            G[back1].push_back({end,1});
        }
        else
        {
            if(curr>=l_minbit)
            {
                G[back2].push_back({total+1,L[curr+1]});
                total++;
                if(L2[curr])G[total].push_back({total+1,1});
                back2=total;
            }
            total++;
            G[back1].push_back({total,0});
            G[back1].push_back({total,1});
            back1=total;
        }
        //printf("damn %d %d %d %d\n",curr,back1,back2,total);
    }
    if(r_maxbit>l_maxbit+1)
    {
        int bf;
        for(int i=l_maxbit+1;i<=r_maxbit-1;i++)
        {
            G[div].push_back({total+1,1});
            total++;
            if(i<=l_maxbit+1)
            {
                bf=total;
            }
            else
            {
                G[total].push_back({total-1,0});
                G[total].push_back({total-1,1});
            }
        }
        for(int i=l_maxbit;i>=0;i--)
        {
            if(i==0)
            {
                G[bf].push_back({end,0});
                G[bf].push_back({end,1});
            }
            else
            {
                G[bf].push_back({total+1,0});
                G[bf].push_back({total+1,1});
                total++;
                bf=total;
            }
        }
    }
    printf("%d\n",total);
    for(int i=1;i<=total;i++)
    {
        printf("%d ",G[i].size());
        for(int j=0;j<G[i].size();j++)
        {
            printf("%d %d ",G[i][j].first,G[i][j].second);
        }
        printf("\n");
    }
    //printf("%d %d %d %d\n",div,div_min,div_max,end);
    //printf("%d %d %d %d\n",l_maxbit,l_minbit,r_maxbit,r_minbit);
    return 0;
}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

5 7

output:

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

result:

ok ok

Test #2:

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

input:

10 27

output:

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

result:

ok ok

Test #3:

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

input:

5 13

output:

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

result:

ok ok

Test #4:

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

input:

1 1000000

output:

57
20 2 1 39 1 40 1 41 1 42 1 43 1 44 1 45 1 46 1 47 1 48 1 49 1 50 1 51 1 52 1 53 1 54 1 55 1 56 1 57 1 
2 3 0 4 1 
2 5 0 5 1 
2 5 0 6 1 
2 7 0 7 1 
2 7 0 8 1 
2 9 0 9 1 
1 10 0 
2 11 0 11 1 
2 11 0 12 1 
2 13 0 13 1 
1 14 0 
2 15 0 15 1 
1 16 0 
2 17 0 17 1 
1 18 0 
2 19 0 19 1 
1 20 0 
2 21 0 21 ...

result:

ok ok

Test #5:

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

input:

1 1

output:

2
1 2 1
0 

result:

ok ok

Test #6:

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

input:

7 9

output:

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

result:

ok ok

Test #7:

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

input:

3 7

output:

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

result:

ok ok

Test #8:

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

input:

1 5

output:

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

result:

ok ok

Test #9:

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

input:

1 4

output:

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

result:

ok ok

Test #10:

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

input:

8 9

output:

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

result:

ok ok

Test #11:

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

input:

7 51

output:

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

result:

ok ok

Test #12:

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

input:

51 79

output:

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

result:

ok ok

Test #13:

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

input:

92 99

output:

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

result:

ok ok

Test #14:

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

input:

27 36

output:

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

result:

ok ok

Test #15:

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

input:

55 84

output:

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

result:

ok ok

Test #16:

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

input:

297208 929600

output:

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

result:

ok ok

Test #17:

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

input:

45728 589156

output:

78
5 2 1 37 1 61 1 62 1 63 1 
1 3 0 
1 4 0 
1 5 0 
2 6 0 7 1 
2 8 0 8 1 
2 8 0 9 1 
2 10 0 10 1 
2 10 0 11 1 
2 12 0 12 1 
2 12 0 13 1 
2 14 0 14 1 
2 14 0 15 1 
2 16 0 16 1 
2 16 0 17 1 
2 18 0 18 1 
1 19 0 
2 20 0 20 1 
2 20 0 21 1 
2 22 0 22 1 
1 23 0 
2 24 0 24 1 
2 24 0 25 1 
2 26 0 26 1 
2 26 ...

result:

ok ok

Test #18:

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

input:

129152 138000

output:

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

result:

ok ok

Test #19:

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

input:

245280 654141

output:

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

result:

ok ok

Test #20:

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

input:

202985 296000

output:

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

result:

ok ok

Test #21:

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

input:

438671 951305

output:

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

result:

ok ok

Test #22:

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

input:

425249 739633

output:

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

result:

ok ok

Test #23:

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

input:

551207 961718

output:

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

result:

ok ok

Test #24:

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

input:

114691 598186

output:

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

result:

ok ok

Test #25:

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

input:

234654 253129

output:

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

result:

ok ok

Test #26:

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

input:

554090 608599

output:

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

result:

ok ok

Extra Test:

score: 0
Extra Test Passed