QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#759578 | #9519. Build a Computer | W_Trace2 | AC ✓ | 1ms | 7084kb | C++14 | 1.7kb | 2024-11-18 10:12:07 | 2024-11-18 10:12:14 |
Judging History
answer
#include<bits/stdc++.h>
#define gc getchar()
#define cin(a) a=read()
#define M 100011
using namespace std;
int read(){
int x=0;bool fl=0;char s=gc;
while(!isdigit(s)){if(s=='-')fl=1;s=gc;}
while(isdigit(s)) x=(x<<1)+(x<<3)+s-'0',s=gc;
return fl?-x:x;
}
struct Node{
int x,y;
};
int a[M],b[M],id[M];
vector<Node> e[M];
void add(int x,int y,int z){
if(x==y) return;
e[x].push_back((Node){y,z});
}
int main(){
int cin(L),cin(R),n=0;
if(L==R){
while(R) a[++n]=R%2,R/=2;
cout<<n+1<<'\n';
for(int i=1;i<=n;i++){
cout<<1<<' '<<i+1<<' '<<a[n-i+1]<<'\n';
}
cout<<0<<'\n';
return 0;
}
while(R) a[++n]=R%2,R/=2;
for(int i=1;i<=n;i++) b[i]=L%2,L/=2;
int m=n;
while(b[n]==a[n]) n--;
for(int i=1;i<=n/2;i++) swap(a[i],a[n-i+1]),swap(b[i],b[n-i+1]);
for(int i=2;i<n;i++) add(i,i+1,a[i]);
for(int i=1;i<=n;i++) id[i]=i;
if(m==n){
int cnt=n;
while(b[cnt+1-n]==0) cnt++,id[cnt]=1;
for(int i=cnt+1,j=n+1;i<=70;i++,j++) id[i]=j;
}
else for(int i=1;i<=70;i++) id[i]=i;
for(int i=n+1;i<2*n-1;i++) add(id[i],id[i+1],b[i+1-n]);
add(1,2,a[1]);
add(1,id[n+1],b[1]);
if(n>1) add(n,id[2*n],a[n]);
if(n>1) add(id[2*n-1],id[2*n],b[n]);
int maxn=2*n,cnt=2*n;
for(int i=n;i>1;i--){
if(b[i]==0) add(id[n+i-1],id[cnt],1),maxn=cnt;
if(a[i]==1) add(i,id[cnt],0),maxn=cnt;
cnt++;
add(id[cnt],id[cnt-1],0);
add(id[cnt],id[cnt-1],1);
}
if(n<m) e[id[++maxn]].clear(),add(id[maxn],1,a[++n]);
for(int i=n+1;i<=m;i++){
e[id[++maxn]].clear();
add(id[maxn],id[maxn-1],a[i]);
}
cout<<id[maxn]<<'\n';
for(int i=1;i<=id[maxn];i++){
cout<<e[i].size()<<' ';
for(Node A:e[i]) cout<<A.x<<' '<<A.y<<' ';
cout<<endl;
}
return 0;
}
这程序好像有点Bug,我给组数据试试?
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 6836kb
input:
5 7
output:
5 2 2 1 3 0 2 4 1 4 0 1 4 1 0 1 1 1
result:
ok ok
Test #2:
score: 0
Accepted
time: 1ms
memory: 7060kb
input:
10 27
output:
12 2 6 1 2 1 2 3 1 12 0 1 4 0 2 5 1 10 0 2 9 1 9 0 2 7 0 11 1 1 8 1 2 9 0 9 1 0 2 9 0 9 1 2 10 0 10 1 2 11 0 11 1
result:
ok ok
Test #3:
score: 0
Accepted
time: 1ms
memory: 6232kb
input:
5 13
output:
9 2 5 1 2 1 2 3 1 9 0 1 4 0 2 7 1 7 0 2 6 0 8 1 1 7 1 0 2 7 0 7 1 2 8 0 8 1
result:
ok ok
Test #4:
score: 0
Accepted
time: 1ms
memory: 6636kb
input:
1 1000000
output:
39 20 2 1 21 1 22 1 23 1 24 1 25 1 26 1 27 1 28 1 29 1 30 1 31 1 32 1 33 1 34 1 35 1 36 1 37 1 38 1 39 1 2 3 1 39 0 2 4 1 38 0 2 5 1 37 0 1 6 0 2 7 1 35 0 1 8 0 1 9 0 1 10 0 1 11 0 2 12 1 30 0 1 13 0 1 14 0 2 15 1 27 0 1 16 0 1 17 0 1 18 0 1 19 0 1 20 0 1 21 0 0 2 21 0 21 1 2 2...
result:
ok ok
Test #5:
score: 0
Accepted
time: 1ms
memory: 7060kb
input:
1 1
output:
2 1 2 1 0
result:
ok ok
Test #6:
score: 0
Accepted
time: 1ms
memory: 6968kb
input:
7 9
output:
7 2 5 1 2 1 1 3 0 1 4 0 2 7 1 7 0 1 6 1 1 7 1 0
result:
ok ok
Test #7:
score: 0
Accepted
time: 0ms
memory: 7084kb
input:
3 7
output:
6 2 4 1 2 1 2 3 1 6 0 2 5 1 5 0 1 5 1 0 2 5 0 5 1
result:
ok ok
Test #8:
score: 0
Accepted
time: 1ms
memory: 6140kb
input:
1 5
output:
5 3 2 1 4 1 5 1 1 3 0 2 4 1 4 0 0 2 4 0 4 1
result:
ok ok
Test #9:
score: 0
Accepted
time: 1ms
memory: 6848kb
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: 1ms
memory: 6044kb
input:
8 9
output:
5 2 2 1 2 0 0 1 1 0 1 3 0 1 4 1
result:
ok ok
Test #11:
score: 0
Accepted
time: 1ms
memory: 6208kb
input:
7 51
output:
13 4 7 1 2 1 12 1 13 1 2 3 1 13 0 1 4 0 1 5 0 2 6 1 10 0 2 9 1 9 0 1 8 1 1 9 1 0 2 9 0 9 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: 1ms
memory: 5932kb
input:
51 79
output:
16 2 8 1 2 1 1 3 0 1 4 0 2 5 1 16 0 2 6 1 15 0 2 7 1 14 0 2 13 1 13 0 1 9 1 2 10 0 16 1 2 11 0 15 1 1 12 1 1 13 1 0 2 13 0 13 1 2 14 0 14 1 2 15 0 15 1
result:
ok ok
Test #13:
score: 0
Accepted
time: 1ms
memory: 6432kb
input:
92 99
output:
14 2 2 1 7 0 1 3 0 1 4 0 1 5 0 2 6 1 13 0 2 12 1 12 0 1 8 1 1 9 1 1 10 1 2 11 0 13 1 2 12 0 12 1 0 2 12 0 12 1 1 1 1
result:
ok ok
Test #14:
score: 0
Accepted
time: 0ms
memory: 6004kb
input:
27 36
output:
13 2 7 1 2 1 1 3 0 1 4 0 2 5 1 13 0 1 6 0 1 11 0 1 8 1 2 9 0 13 1 1 10 1 1 11 1 0 2 11 0 11 1 2 12 0 12 1
result:
ok ok
Test #15:
score: 0
Accepted
time: 0ms
memory: 6868kb
input:
55 84
output:
17 2 8 1 2 1 1 3 0 2 4 1 17 0 1 5 0 2 6 1 15 0 1 7 0 1 13 0 1 9 1 2 10 0 16 1 1 11 1 1 12 1 1 13 1 0 2 13 0 13 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: 6852kb
input:
297208 929600
output:
57 2 21 1 2 1 2 3 1 57 0 2 4 1 56 0 1 5 0 1 6 0 1 7 0 2 8 1 52 0 1 9 0 2 10 1 50 0 2 11 1 49 0 2 12 1 48 0 2 13 1 47 0 1 14 0 2 15 1 45 0 1 16 0 1 17 0 1 18 0 1 19 0 1 20 0 1 39 0 2 22 0 56 1 2 23 0 55 1 1 24 1 2 25 0 53 1 2 26 0 52 1 2 27 0 51 1 1 28 1 2 29 0 49 1 2 30 0...
result:
ok ok
Test #17:
score: 0
Accepted
time: 1ms
memory: 6300kb
input:
45728 589156
output:
54 5 21 1 2 1 52 1 53 1 54 1 1 3 0 1 4 0 1 5 0 2 6 1 51 0 2 7 1 50 0 2 8 1 49 0 2 9 1 48 0 2 10 1 47 0 2 11 1 46 0 1 12 0 2 13 1 44 0 1 14 0 2 15 1 42 0 2 16 1 41 0 1 17 0 1 18 0 2 19 1 38 0 1 20 0 1 36 0 2 22 0 50 1 1 23 1 1 24 1 2 25 0 47 1 2 26 0 46 1 1 27 1 2 28 0 44 1 ...
result:
ok ok
Test #18:
score: 0
Accepted
time: 1ms
memory: 6612kb
input:
129152 138000
output:
47 2 19 1 2 1 1 3 0 1 4 0 1 5 0 1 6 0 2 7 1 47 0 2 8 1 46 0 1 9 0 2 10 1 44 0 2 11 1 43 0 1 12 0 1 13 0 1 14 0 2 15 1 39 0 1 16 0 1 17 0 1 18 0 1 35 0 1 20 1 1 21 1 1 22 1 1 23 1 1 24 1 2 25 0 45 1 2 26 0 44 1 2 27 0 43 1 1 28 1 2 29 0 41 1 2 30 0 40 1 2 31 0 39 1 2 32 ...
result:
ok ok
Test #19:
score: 0
Accepted
time: 0ms
memory: 5972kb
input:
245280 654141
output:
56 3 21 1 2 1 56 1 1 3 0 1 4 0 2 5 1 54 0 2 6 1 53 0 2 7 1 52 0 2 8 1 51 0 2 9 1 50 0 2 10 1 49 0 1 11 0 2 12 1 47 0 2 13 1 46 0 1 14 0 1 15 0 2 16 1 43 0 2 17 1 42 0 2 18 1 41 0 2 19 1 40 0 1 20 0 2 38 1 38 0 1 22 1 1 23 1 2 24 0 52 1 1 25 1 1 26 1 1 27 1 1 28 1 1 29 1 2...
result:
ok ok
Test #20:
score: 0
Accepted
time: 0ms
memory: 6148kb
input:
202985 296000
output:
52 2 20 1 2 1 1 3 0 1 4 0 2 5 1 52 0 1 6 0 1 7 0 1 8 0 1 9 0 2 10 1 47 0 1 11 0 1 12 0 1 13 0 2 14 1 43 0 1 15 0 1 16 0 1 17 0 1 18 0 1 19 0 1 37 0 1 21 1 2 22 0 52 1 2 23 0 51 1 2 24 0 50 1 1 25 1 1 26 1 2 27 0 47 1 2 28 0 46 1 2 29 0 45 1 1 30 1 1 31 1 1 32 1 2 33 0 ...
result:
ok ok
Test #21:
score: 0
Accepted
time: 1ms
memory: 5916kb
input:
438671 951305
output:
57 2 21 1 2 1 2 3 1 57 0 2 4 1 56 0 1 5 0 2 6 1 54 0 1 7 0 1 8 0 1 9 0 1 10 0 2 11 1 49 0 1 12 0 1 13 0 1 14 0 1 15 0 1 16 0 1 17 0 2 18 1 42 0 1 19 0 1 20 0 2 39 1 39 0 1 22 1 2 23 0 55 1 1 24 1 2 25 0 53 1 1 26 1 1 27 1 2 28 0 50 1 2 29 0 49 1 2 30 0 48 1 1 31 1 1 32 ...
result:
ok ok
Test #22:
score: 0
Accepted
time: 1ms
memory: 6044kb
input:
425249 739633
output:
56 2 21 1 2 1 1 3 0 2 4 1 56 0 2 5 1 55 0 1 6 0 2 7 1 53 0 1 8 0 1 9 0 2 10 1 50 0 1 11 0 1 12 0 2 13 1 47 0 1 14 0 1 15 0 2 16 1 44 0 2 17 1 43 0 1 18 0 1 19 0 1 20 0 2 39 1 39 0 1 22 1 2 23 0 55 1 2 24 0 54 1 1 25 1 1 26 1 1 27 1 1 28 1 1 29 1 2 30 0 48 1 1 31 1 2 32 ...
result:
ok ok
Test #23:
score: 0
Accepted
time: 0ms
memory: 5996kb
input:
551207 961718
output:
56 2 2 1 20 0 2 3 1 55 0 1 4 0 2 5 1 53 0 1 6 0 2 7 1 51 0 1 8 0 2 9 1 49 0 2 10 1 48 0 1 11 0 1 12 0 2 13 1 45 0 1 14 0 2 15 1 43 0 2 16 1 42 0 1 17 0 2 18 1 40 0 2 19 1 39 0 1 38 0 2 21 0 55 1 2 22 0 54 1 2 23 0 53 1 1 24 1 1 25 1 2 26 0 50 1 1 27 1 2 28 0 48 1 2 29 0 47...
result:
ok ok
Test #24:
score: 0
Accepted
time: 1ms
memory: 5936kb
input:
114691 598186
output:
55 4 21 1 2 1 54 1 55 1 1 3 0 1 4 0 2 5 1 53 0 1 6 0 1 7 0 2 8 1 50 0 1 9 0 1 10 0 1 11 0 1 12 0 1 13 0 2 14 1 44 0 1 15 0 2 16 1 42 0 1 17 0 2 18 1 40 0 1 19 0 2 20 1 38 0 1 37 0 1 22 1 1 23 1 2 24 0 50 1 2 25 0 49 1 2 26 0 48 1 2 27 0 47 1 2 28 0 46 1 2 29 0 45 1 2 30 0...
result:
ok ok
Test #25:
score: 0
Accepted
time: 0ms
memory: 6072kb
input:
234654 253129
output:
46 2 2 1 16 0 1 3 0 2 4 1 42 0 2 5 1 41 0 2 6 1 40 0 1 7 0 1 8 0 2 9 1 37 0 2 10 1 36 0 1 11 0 1 12 0 2 13 1 33 0 1 14 0 1 15 0 2 30 1 30 0 2 17 0 43 1 1 18 1 2 19 0 41 1 1 20 1 2 21 0 39 1 2 22 0 38 1 1 23 1 2 24 0 36 1 2 25 0 35 1 1 26 1 1 27 1 1 28 1 1 29 1 2 30 0 30 1...
result:
ok ok
Test #26:
score: 0
Accepted
time: 0ms
memory: 5948kb
input:
554090 608599
output:
52 2 2 1 18 0 1 3 0 2 4 1 48 0 1 5 0 1 6 0 2 7 1 45 0 1 8 0 1 9 0 2 10 1 42 0 1 11 0 2 12 1 40 0 1 13 0 2 14 1 38 0 1 15 0 2 16 1 36 0 2 17 1 35 0 2 34 1 34 0 2 19 0 49 1 1 20 1 1 21 1 1 22 1 2 23 0 45 1 1 24 1 2 25 0 43 1 2 26 0 42 1 2 27 0 41 1 1 28 1 1 29 1 2 30 0 38 1...
result:
ok ok
Extra Test:
score: 0
Extra Test Passed