QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#692740#9519. Build a Computerzeng_wjAC ✓7ms15400kbC++201.9kb2024-10-31 14:58:342024-10-31 14:58:36

Judging History

This is the latest submission verdict.

  • [2024-10-31 14:58:36]
  • Judged
  • Verdict: AC
  • Time: 7ms
  • Memory: 15400kb
  • [2024-10-31 14:58:34]
  • Submitted

answer

#include<bits/stdc++.h>
#define int long long
#define rep(i,j,k) for(int i=(j),_i=(k);i<=_i;++i)
#define drp(i,j,k) for(int i=(j),_i=(k);i>=_i;--i)
using namespace std;
inline int read() {
	int x=0,f=0; char ch=getchar();
	while(!isdigit(ch)) f|=ch=='-',ch=getchar();
	while(isdigit(ch)) x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
	return f?-x:x;
}
//--------------------------------------------//
const int N=1e6+5;

int id[N],rk[N],pos;
int cnt=22,S=21,T=22;
vector<pair<int,int>>edge[N];

void add_edge(int x,int y,int w) {
	edge[x].push_back(make_pair(y,w));
}

int dfs(int L,int R,int w,int tpye) {
	if(w==-1) return T;
	if(!L&&R==(1<<(w+1))-1) return w+1;
	int cur=tpye?++cnt:S;
	if(R>=(1<<w)) {
		int rs=dfs(max(0ll,L-(1<<w)),R-(1<<w),w-1,1);
		add_edge(cur,rs,1);
	}
	if(L<(1<<w)) {
		int ls=dfs(L,min((1ll<<w)-1,R),w-1,tpye);
		if(tpye) add_edge(cur,ls,0);
	}
	return cur;
}

int vis[N];
void sou(int u,int num){
	if(u==T) vis[num]=1;
	for(auto nex:edge[u]) {
		if(!num&&!nex.second) {
			puts("no");
			puts("exist pre 0");
		}
		sou(nex.first,(num<<1)|nex.second); 
	}
}

int met[N];
void upd(int u) {
	id[rk[u]=++pos]=u;
	met[u]=1;
	for(auto nex:edge[u]) {
		int v=nex.first;
		if(met[v]) continue;
		upd(v);
	}
}

signed main() {
	// freopen("A.in","r",stdin);
	// freopen("A.out","w",stdout);
	add_edge(1,T,0);
	add_edge(1,T,1);
	rep(i,2,20) {
		add_edge(i,i-1,0);
		add_edge(i,i-1,1);
	}
	
	int L=read(),R=read();
	// int L=1,R=100000;
	dfs(L,R,19,0);
	
	sou(S,0);
	rep(i,1,N-1) {
		if(i>=L&&i<=R&&!vis[i]) printf("no\n%lld cant be find\n",i);
		if((i<L||i>R)&&vis[i]) printf("no\n%lld shouldn't be find\n",i);
	}
	// puts("YES");

	upd(S);
	
	printf("%lld\n",pos);
	rep(i,1,pos) {
		int u=id[i];
		printf("%lld ",edge[u].size());
		for(pair<int,int>tmp:edge[u])
		  printf("%lld %lld ",rk[tmp.first],tmp.second);
		printf("\n");
	}
}

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

詳細信息

Test #1:

score: 100
Accepted
time: 4ms
memory: 7888kb

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: 3ms
memory: 7936kb

input:

10 27

output:

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

result:

ok ok

Test #3:

score: 0
Accepted
time: 3ms
memory: 7932kb

input:

5 13

output:

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

result:

ok ok

Test #4:

score: 0
Accepted
time: 3ms
memory: 15400kb

input:

1 1000000

output:

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

result:

ok ok

Test #5:

score: 0
Accepted
time: 3ms
memory: 7928kb

input:

1 1

output:

2
1 2 1 
0 

result:

ok ok

Test #6:

score: 0
Accepted
time: 3ms
memory: 7924kb

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

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: 3ms
memory: 7980kb

input:

1 5

output:

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

result:

ok ok

Test #9:

score: 0
Accepted
time: 3ms
memory: 7864kb

input:

1 4

output:

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

result:

ok ok

Test #10:

score: 0
Accepted
time: 3ms
memory: 7932kb

input:

8 9

output:

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

result:

ok ok

Test #11:

score: 0
Accepted
time: 3ms
memory: 7864kb

input:

7 51

output:

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

result:

ok ok

Test #12:

score: 0
Accepted
time: 3ms
memory: 7940kb

input:

51 79

output:

13
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 5 1 11 0 
2 6 1 12 0 
1 13 1 
1 8 1 

result:

ok ok

Test #13:

score: 0
Accepted
time: 3ms
memory: 7992kb

input:

92 99

output:

11
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 6 1 

result:

ok ok

Test #14:

score: 0
Accepted
time: 3ms
memory: 7944kb

input:

27 36

output:

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

result:

ok ok

Test #15:

score: 0
Accepted
time: 2ms
memory: 7908kb

input:

55 84

output:

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

result:

ok ok

Test #16:

score: 0
Accepted
time: 3ms
memory: 12044kb

input:

297208 929600

output:

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

result:

ok ok

Test #17:

score: 0
Accepted
time: 7ms
memory: 11980kb

input:

45728 589156

output:

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

result:

ok ok

Test #18:

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

input:

129152 138000

output:

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

result:

ok ok

Test #19:

score: 0
Accepted
time: 2ms
memory: 9992kb

input:

245280 654141

output:

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

result:

ok ok

Test #20:

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

input:

202985 296000

output:

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

result:

ok ok

Test #21:

score: 0
Accepted
time: 6ms
memory: 11360kb

input:

438671 951305

output:

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

result:

ok ok

Test #22:

score: 0
Accepted
time: 5ms
memory: 11964kb

input:

425249 739633

output:

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

result:

ok ok

Test #23:

score: 0
Accepted
time: 2ms
memory: 9928kb

input:

551207 961718

output:

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

result:

ok ok

Test #24:

score: 0
Accepted
time: 6ms
memory: 12076kb

input:

114691 598186

output:

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

result:

ok ok

Test #25:

score: 0
Accepted
time: 3ms
memory: 7940kb

input:

234654 253129

output:

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

result:

ok ok

Test #26:

score: 0
Accepted
time: 3ms
memory: 7936kb

input:

554090 608599

output:

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

result:

ok ok

Extra Test:

score: 0
Extra Test Passed