QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#678096#9519. Build a Computerucup-team5052#AC ✓0ms3720kbC++141.4kb2024-10-26 14:01:372024-10-26 14:01:39

Judging History

This is the latest submission verdict.

  • [2024-10-26 14:01:39]
  • Judged
  • Verdict: AC
  • Time: 0ms
  • Memory: 3720kb
  • [2024-10-26 14:01:37]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
vector<pair<int,int>> G[200];
int a[30];
void add(int u,int v,int w)
{
	G[u].emplace_back(v,w);
}
int main() {
	std::ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int L,R,s=1,t=2,tot=2,d=0;
	cin>>L>>R;
	bool all0=1;
	int k=__lg((L-1)^(R+1)),tp=__lg(R+1);
	for(int i=tp;i>k;i--)
	{
		int s2=++tot;
		add(s,s2,((R+1)>>i)&1);
		s=s2;
	}
	int p1=s;
	if(((L-1)&((1<<k)-1))!=(1<<k)-1)
	{
		if(tp!=k)
		{
			all0=0;
			p1=++tot;
			add(s,p1,0);
		}
		for(int i=k-1;i>=0;i--)
			if(!(((L-1)>>i)&1))
			{
				add(p1,-i,1);
				d=max(d,i);
				if(((L-1)&((1<<i)-1))==(1<<i)-1) break;
				if(!all0)
				{
					int p2=++tot;
					add(p1,p2,0);
					p1=p2;
				}
			}
			else
			{
				int p2=++tot;
				add(p1,p2,1);
				p1=p2;all0=0;
			}
	}
	if(((R+1)&((1<<k)-1))!=0)
	{
		p1=++tot;
		add(s,p1,1);
		for(int i=k-1;i>=0;i--)
			if(((R+1)>>i)&1)
			{
				add(p1,-i,0);
				d=max(d,i);
				if(((R+1)&((1<<i)-1))==0) break;
				int p2=++tot;
				add(p1,p2,1);
				p1=p2;
			}
			else
			{
				int p2=++tot;
				add(p1,p2,0);
				p1=p2;
			}
	}
	a[0]=t;
	for(int i=1;i<=d;i++) a[i]=++tot,add(a[i],a[i-1],0),add(a[i],a[i-1],1);
	for(int u=1;u<=tot;u++)
		for(auto &[v,w]:G[u])
			if(v<=0) v=a[-v];
	cout<<tot<<endl;
	for(int u=1;u<=tot;u++)
	{
		cout<<G[u].size()<<" ";
		for(auto [v,w]:G[u]) cout<<v<<" "<<w<<" ";
		cout<<"\n";
	}
	return 0;
}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

5 7

output:

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

result:

ok ok

Test #2:

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

input:

10 27

output:

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

result:

ok ok

Test #3:

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

input:

5 13

output:

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

result:

ok ok

Test #4:

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

input:

1 1000000

output:

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

result:

ok ok

Test #5:

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

input:

1 1

output:

2
1 2 1 
0 

result:

ok ok

Test #6:

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

input:

7 9

output:

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

result:

ok ok

Test #7:

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

input:

3 7

output:

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

result:

ok ok

Test #8:

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

input:

1 5

output:

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

result:

ok ok

Test #9:

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

input:

1 4

output:

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

result:

ok ok

Test #10:

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

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: 3560kb

input:

7 51

output:

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

result:

ok ok

Test #12:

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

input:

51 79

output:

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

result:

ok ok

Test #13:

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

input:

92 99

output:

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

result:

ok ok

Test #14:

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

input:

27 36

output:

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

result:

ok ok

Test #15:

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

input:

55 84

output:

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

result:

ok ok

Test #16:

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

input:

297208 929600

output:

54
2 3 1 18 1 
0 
2 53 1 4 0 
2 52 1 5 0 
1 6 1 
2 50 1 7 0 
2 49 1 8 0 
2 48 1 9 0 
1 10 1 
2 46 1 11 0 
2 45 1 12 0 
2 44 1 13 0 
1 14 1 
1 15 1 
1 16 1 
1 17 1 
1 39 1 
2 54 0 19 1 
2 53 0 20 1 
1 21 0 
1 22 0 
1 23 0 
2 49 0 24 1 
1 25 0 
2 47 0 26 1 
2 46 0 27 1 
2 45 0 28 1 
2 44 0 29 1 
1 30 ...

result:

ok ok

Test #17:

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

input:

45728 589156

output:

49
5 49 1 48 1 47 1 3 1 13 1 
0 
2 45 1 4 0 
1 5 1 
1 6 1 
2 42 1 7 0 
2 41 1 8 0 
1 9 1 
2 39 1 10 0 
1 11 1 
2 37 1 12 0 
1 36 1 
1 14 0 
1 15 0 
1 16 0 
2 46 0 17 1 
2 45 0 18 1 
2 44 0 19 1 
2 43 0 20 1 
2 42 0 21 1 
2 41 0 22 1 
1 23 0 
2 39 0 24 1 
1 25 0 
2 37 0 26 1 
2 36 0 27 1 
1 28 0 
1 2...

result:

ok ok

Test #18:

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

input:

129152 138000

output:

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

result:

ok ok

Test #19:

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

input:

245280 654141

output:

50
3 50 1 3 1 15 1 
0 
1 4 1 
1 5 1 
2 46 1 6 0 
1 7 1 
1 8 1 
1 9 1 
1 10 1 
1 11 1 
2 40 1 12 0 
2 39 1 13 0 
2 38 1 14 0 
1 37 1 
1 16 0 
1 17 0 
2 48 0 18 1 
2 47 0 19 1 
2 46 0 20 1 
2 45 0 21 1 
2 44 0 22 1 
2 43 0 23 1 
1 24 0 
2 41 0 25 1 
2 40 0 26 1 
1 27 0 
1 28 0 
2 37 0 29 1 
2 36 0 30 ...

result:

ok ok

Test #20:

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

input:

202985 296000

output:

52
2 3 1 20 1 
0 
1 4 1 
2 52 1 5 0 
2 51 1 6 0 
2 50 1 7 0 
1 8 1 
1 9 1 
2 47 1 10 0 
2 46 1 11 0 
2 45 1 12 0 
1 13 1 
1 14 1 
1 15 1 
2 41 1 16 0 
1 17 1 
2 39 1 18 0 
2 38 1 19 0 
1 2 1 
1 21 0 
1 22 0 
2 52 0 23 1 
1 24 0 
1 25 0 
1 26 0 
1 27 0 
2 47 0 28 1 
1 29 0 
1 30 0 
1 31 0 
2 43 0 32 ...

result:

ok ok

Test #21:

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

input:

438671 951305

output:

56
2 3 1 21 1 
0 
1 4 1 
2 54 1 5 0 
1 6 1 
2 52 1 7 0 
1 8 1 
1 9 1 
2 49 1 10 0 
2 48 1 11 0 
2 47 1 12 0 
1 13 1 
1 14 1 
2 44 1 15 0 
2 43 1 16 0 
2 42 1 17 0 
1 18 1 
1 19 1 
1 20 1 
1 2 1 
2 56 0 22 1 
2 55 0 23 1 
1 24 0 
2 53 0 25 1 
1 26 0 
1 27 0 
1 28 0 
1 29 0 
2 48 0 30 1 
1 31 0 
1 32 ...

result:

ok ok

Test #22:

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

input:

425249 739633

output:

55
2 3 1 21 1 
0 
1 4 1 
2 54 1 5 0 
2 53 1 6 0 
1 7 1 
1 8 1 
1 9 1 
1 10 1 
1 11 1 
2 47 1 12 0 
1 13 1 
2 45 1 14 0 
2 44 1 15 0 
1 16 1 
2 42 1 17 0 
2 41 1 18 0 
2 40 1 19 0 
2 39 1 20 0 
1 2 1 
1 22 0 
2 55 0 23 1 
2 54 0 24 1 
1 25 0 
2 52 0 26 1 
1 27 0 
1 28 0 
2 49 0 29 1 
1 30 0 
1 31 0 
...

result:

ok ok

Test #23:

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

input:

551207 961718

output:

56
1 3 1 
0 
2 4 0 22 1 
2 56 1 5 0 
2 55 1 6 0 
2 54 1 7 0 
1 8 1 
1 9 1 
2 51 1 10 0 
1 11 1 
2 49 1 12 0 
2 48 1 13 0 
1 14 1 
2 46 1 15 0 
2 45 1 16 0 
1 17 1 
2 43 1 18 0 
2 42 1 19 0 
1 20 1 
1 21 1 
1 2 1 
2 56 0 23 1 
1 24 0 
2 54 0 25 1 
1 26 0 
2 52 0 27 1 
1 28 0 
2 50 0 29 1 
2 49 0 30 1...

result:

ok ok

Test #24:

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

input:

114691 598186

output:

55
4 55 1 54 1 3 1 19 1 
0 
1 4 1 
1 5 1 
2 50 1 6 0 
2 49 1 7 0 
2 48 1 8 0 
2 47 1 9 0 
2 46 1 10 0 
2 45 1 11 0 
2 44 1 12 0 
2 43 1 13 0 
2 42 1 14 0 
2 41 1 15 0 
2 40 1 16 0 
2 39 1 17 0 
1 18 1 
1 2 1 
1 20 0 
1 21 0 
2 53 0 22 1 
1 23 0 
1 24 0 
2 50 0 25 1 
1 26 0 
1 27 0 
1 28 0 
1 29 0 
1...

result:

ok ok

Test #25:

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

input:

234654 253129

output:

44
1 3 1 
0 
1 4 1 
1 5 1 
2 6 0 19 1 
2 44 1 7 0 
1 8 1 
2 42 1 9 0 
1 10 1 
2 40 1 11 0 
2 39 1 12 0 
1 13 1 
2 37 1 14 0 
2 36 1 15 0 
1 16 1 
1 17 1 
1 18 1 
1 32 1 
1 20 0 
2 43 0 21 1 
2 42 0 22 1 
2 41 0 23 1 
1 24 0 
1 25 0 
2 38 0 26 1 
2 37 0 27 1 
1 28 0 
1 29 0 
2 34 0 30 1 
1 31 0 
1 32...

result:

ok ok

Test #26:

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

input:

554090 608599

output:

48
1 3 1 
0 
1 4 0 
1 5 0 
2 6 0 21 1 
2 48 1 7 0 
1 8 1 
1 9 1 
1 10 1 
2 44 1 11 0 
1 12 1 
2 42 1 13 0 
2 41 1 14 0 
2 40 1 15 0 
1 16 1 
1 17 1 
2 37 1 18 0 
1 19 1 
2 35 1 20 0 
1 34 1 
1 22 0 
2 47 0 23 1 
1 24 0 
1 25 0 
2 44 0 26 1 
1 27 0 
1 28 0 
2 41 0 29 1 
1 30 0 
2 39 0 31 1 
1 32 0 
2...

result:

ok ok

Extra Test:

score: 0
Extra Test Passed