QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#886426#9519. Build a ComputercbdsopaAC ✓1ms3840kbC++143.1kb2025-02-07 03:15:072025-02-07 03:15:08

Judging History

This is the latest submission verdict.

  • [2025-02-07 03:15:08]
  • Judged
  • Verdict: AC
  • Time: 1ms
  • Memory: 3840kb
  • [2025-02-07 03:15:07]
  • Submitted

answer

#include <bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define db double
#define file(a) freopen(#a".in", "r", stdin), freopen(#a".out", "w", stdout)
#define sky fflush(stdout)
#define gc getchar
#define pc putchar
namespace IO{
	template<class T>
	inline void read(T &s){
		s = 0;char ch = gc();bool f = 0;
		while(ch < '0' || '9'<ch) {if(ch == '-') f = 1; ch = gc();}
		while('0'<=ch && ch<='9') {s = s * 10 + (ch ^ 48); ch = gc();}
		if(ch == '.'){
			T p = 0.1;ch = gc();
			while('0' <= ch && ch <= '9') {s = s + p * (ch ^ 48);p /= 10;ch = gc();}
		}
		s = f ? -s : s;
	}
	template<class T,class ...A>
	inline void read(T &s,A &...a){
		read(s); read(a...);
	}
	template<class T>
	inline void write(T x){
		if(x<0) {x = -x; pc('-');}
		static char st[40];
		static int top;
		top = 0;
		do{st[++top] = x - x / 10 * 10 + '0';} while(x /= 10);
		while(top) {pc(st[top--]);}
	}
};
using IO::read;
using IO::write;
#define lowbit(x) (x & -x)
int highbit(int x){
	if(x == 0) return 0;
	int y;
	while(true){
		y = x;
		x -= lowbit(x);
		if(!x) break;
	}
	return y;
}
const int N = 100;
int l, r;
struct Edge{
	int v, w;	
};
std::vector<Edge>G[N + 3];
int n;
int ty[21];
int main(){
#ifdef LOCAL
	file(a);
#endif
	read(l, r);
	n = 2;
	ty[0] = 2;
	int mx = 0;
	if(highbit(l) == highbit(r) ){
		int a = 1, b = 1;
		int ld = 20;
		while(!(l >> ld & 1) ) --ld;
		bool flag = 1;
		for(int i = ld; i >= 0; --i){
			int c1 = l >> i & 1, c2 = r >> i & 1;
			if(c1 == c2 && flag){
				if(i != 0) G[a].push_back({++n, c1});
				else G[a].push_back({2, c1});
				a = b = n;
			}else{
				if(i != 0) G[a].push_back({++n, c1});
				else G[a].push_back({2, c1}); 
				if(!flag && c1 == 0) G[a].push_back({101 + i, 1}), mx = std::max(mx, i);
				a = n;
				if(i != 0) G[b].push_back({++n, c2});
				else G[b].push_back({2, c2}); 
				if(!flag && c2 == 1) G[b].push_back({101 + i, 0}), mx = std::max(mx, i);
				b = n;
				flag = 0;
			}
		}
	}else{
		int ld = 20;
		while(!(l >> ld & 1) ) --ld;
		int p = 1;
		for(int i = ld; i >= 0; --i){
			int c = l >> i & 1;
			if(i != 0) G[p].push_back({++n, c});
			else G[p].push_back({2, c});
			if(c == 0 && i != ld) G[p].push_back({101 + i, 1}), mx = std::max(mx, i);
			p = n;
		}
		ld = 20;
		while(!(r >> ld & 1) ) --ld;
		p = 1;
		for(int i = ld; i >= 0; --i){
			int c = r >> i & 1;
			if(i != 0) G[p].push_back({++n, c});
			else G[p].push_back({2, c});
			if(c == 1 && i != ld) G[p].push_back({101 + i, 0}), mx = std::max(mx, i);
			p = n;
		}
		r = highbit(r) >> 1;
		int now = ld - 1;
		while(highbit(r) != highbit(l) ){
			G[1].push_back({101 + now, 1});
			mx = std::max(mx, now);
			--now;
			r >>= 1;
		}
	}
	for(int i = 1; i <= mx; ++i){
		ty[i] = ++n;
		G[ty[i] ].push_back({ty[i - 1], 0});
		G[ty[i] ].push_back({ty[i - 1], 1});
	}	
	printf("%d\n", n);
	for(int i = 1; i <= n; ++i){
		printf("%d ", G[i].size() );
		for(auto it : G[i]){
			printf("%d %d ", it.v <= 100 ? it.v : ty[it.v - 101], it.w);
		}pc('\n');
	}
	return 0;
}

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

詳細信息

Test #1:

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

input:

5 7

output:

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

result:

ok ok

Test #2:

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

input:

10 27

output:

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

result:

ok ok

Test #3:

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

input:

5 13

output:

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

result:

ok ok

Test #4:

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

input:

1 1000000

output:

39
20 2 1 3 1 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 
0 
2 4 1 39 0 
2 5 1 38 0 
2 6 1 37 0 
1 7 0 
2 8 1 35 0 
1 9 0 
1 10 0 
1 11 0 
1 12 0 
2 13 1 30 0 
1 14 0 
1 15 0 
2 16 1 27 0 
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: 3840kb

input:

1 1

output:

2
1 2 1 
0 

result:

ok ok

Test #6:

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

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 1 2 0 

result:

ok ok

Test #7:

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

input:

3 7

output:

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

result:

ok ok

Test #8:

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

input:

1 5

output:

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

result:

ok ok

Test #9:

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

input:

1 4

output:

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

result:

ok ok

Test #10:

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

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

input:

7 51

output:

13
4 3 1 5 1 13 1 12 1 
0 
1 4 1 
1 2 1 
2 6 1 13 0 
1 7 0 
1 8 0 
2 9 1 10 0 
2 2 1 2 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 #12:

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

input:

51 79

output:

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

result:

ok ok

Test #13:

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

input:

92 99

output:

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

result:

ok ok

Test #14:

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

input:

27 36

output:

13
2 3 1 7 1 
0 
1 4 1 
2 5 0 13 1 
1 6 1 
1 2 1 
1 8 0 
1 9 0 
2 10 1 13 0 
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: 3840kb

input:

55 84

output:

17
2 3 1 8 1 
0 
1 4 1 
2 5 0 16 1 
1 6 1 
1 7 1 
1 2 1 
1 9 0 
2 10 1 17 0 
1 11 0 
2 12 1 15 0 
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: 3840kb

input:

297208 929600

output:

57
2 3 1 21 1 
0 
2 4 0 56 1 
2 5 0 55 1 
1 6 1 
2 7 0 53 1 
2 8 0 52 1 
2 9 0 51 1 
1 10 1 
2 11 0 49 1 
2 12 0 48 1 
2 13 0 47 1 
1 14 1 
1 15 1 
1 16 1 
1 17 1 
1 18 1 
2 19 0 41 1 
2 20 0 40 1 
2 2 0 2 1 
2 22 1 57 0 
2 23 1 56 0 
1 24 0 
1 25 0 
1 26 0 
2 27 1 52 0 
1 28 0 
2 29 1 50 0 
2 30 1 ...

result:

ok ok

Test #17:

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

input:

45728 589156

output:

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

result:

ok ok

Test #18:

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

input:

129152 138000

output:

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

result:

ok ok

Test #19:

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

input:

245280 654141

output:

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

result:

ok ok

Test #20:

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

input:

202985 296000

output:

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

result:

ok ok

Test #21:

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

input:

438671 951305

output:

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

result:

ok ok

Test #22:

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

input:

425249 739633

output:

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

result:

ok ok

Test #23:

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

input:

551207 961718

output:

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

result:

ok ok

Test #24:

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

input:

114691 598186

output:

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

result:

ok ok

Test #25:

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

input:

234654 253129

output:

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

result:

ok ok

Test #26:

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

input:

554090 608599

output:

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

result:

ok ok

Extra Test:

score: 0
Extra Test Passed