QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#769240#9519. Build a Computer401rk8AC ✓0ms3804kbC++174.4kb2024-11-21 16:42:452024-11-21 16:42:45

Judging History

This is the latest submission verdict.

  • [2024-11-21 16:42:45]
  • Judged
  • Verdict: AC
  • Time: 0ms
  • Memory: 3804kb
  • [2024-11-21 16:42:45]
  • Submitted

answer

#include <bits/stdc++.h>
#include <bits/extc++.h>
using namespace std; using namespace __gnu_pbds; using namespace __gnu_cxx;
#define For(i,x,y,...) for(int i=x,##__VA_ARGS__;i<=(y);++i)
#define rFor(i,x,y,...) for(int i=x,##__VA_ARGS__;i>=(y);--i)
#define Rep(i,x,y,...) for(int i=x,##__VA_ARGS__;i<(y);++i)
#define pb emplace_back
#define sz(a) int((a).size())
#define all(a) (a).begin(),(a).end()
#define fi first
#define se second
#define mem(a,x,n) memset(a,x,sizeof(*a)*((n)+2))
typedef long long LL; typedef vector<int> Vi; typedef pair<int,int> Pii;
auto ckmax=[](auto &x,auto y) { return x<y ? x=y,true : false; };
auto ckmin=[](auto &x,auto y) { return y<x ? x=y,true : false; };
sfmt19937 mt(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l,int r) { return uniform_int_distribution<>(l,r)(mt); }
template<typename T=int>T read() { T x; cin>>x; return x; }

const int N = 105;
int n,s,t,L,R,m=-1,f[25];
vector<Pii> e[N];

int g(int i) {
	while( m < i ) {
		f[++m] = ++n;
		if( !m ) e[f[0]].pb(t,0), e[f[0]].pb(t,1);
		else e[f[m]].pb(f[m-1],0), e[f[m]].pb(f[m-1],1);
			
	}
	return f[i];
}

void dfs(int u,int i,bool liml,bool limr) {
	if( i < 0 ) return;
	int l = liml ? L>>i&1 : 0, r = limr ? R>>i&1 : 1;
	if( !i ) {
		For(x,l,r) e[u].pb(t,x);
		return;
	}
	if( !liml && !limr ) {
		e[u].pb(g(i-1),0), e[u].pb(g(i-1),1);
		return;
	}
	For(x,l,r) e[u].pb(++n,x), dfs(n,i-1,liml&&x==l,limr&&x==r);
}

void MAIN() {
	cin>>L>>R;
	if( R == 1 ) { cout<<"2\n1 2 1\n0\n"; return; }
	s = ++n, s = ++n, t = ++n, e[s-1].pb(s,1);
	if( L == 1 ) e[1].pb(t,1), L = 2;
	int l = 31-__builtin_clz(L), r = 31-__builtin_clz(R);
	if( l == r ) dfs(s,l-1,1,1);
	else {
		dfs(s,l-1,1,0), dfs(s,r-1,0,1);
		Rep(i,l+1,r) e[s].pb(g(i-2),0), e[s].pb(g(i-2),1);
	}
	cout<<n<<'\n';
	For(i,1,n) {
		cout<<sz(e[i])<<" ";
		for(auto [j,k] : e[i]) cout<<j<<" "<<k<<" ";
		cout<<'\n';
	}
} signed main() {
#ifdef FS
	freopen("in","r",stdin); freopen("out","w",stdout);
#endif
	ios::sync_with_stdio(0);cin.tie(0);
	int lft=1; while( lft-- ) {
		MAIN();
	}
	return 0;
}
/*
#include <bits/stdc++.h>
#include <bits/extc++.h>
using namespace std; using namespace __gnu_pbds; using namespace __gnu_cxx;
#define For(i,x,y,...) for(int i=x,##__VA_ARGS__;i<=(y);++i)
#define rFor(i,x,y,...) for(int i=x,##__VA_ARGS__;i>=(y);--i)
#define Rep(i,x,y,...) for(int i=x,##__VA_ARGS__;i<(y);++i)
#define pb emplace_back
#define sz(a) int((a).size())
#define all(a) (a).begin(),(a).end()
#define fi first
#define se second
#define mkp make_pair
#define mem(a,x,n) memset(a,x,sizeof(a[0])*(n+2))
typedef long long LL; typedef vector<int> Vi; typedef pair<int,int> Pii;
auto ckmax=[](auto &x,auto y) { return x<y ? x=y,true : false; };
auto ckmin=[](auto &x,auto y) { return y<x ? x=y,true : false; };
sfmt19937 mt(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l,int r) { return uniform_int_distribution<>(l,r)(mt); }
template<typename T=int>T read() { T x; cin>>x; return x; }

const int mod = 998244353;
struct mint {
    int x; mint(int x=0):x(x<0?x+mod:x<mod?x:x-mod){}
    mint(LL y) { y%=mod, x=y<0?y+mod:y; }
    mint& operator += (const mint &y) { x=x+y.x<mod?x+y.x:x+y.x-mod; return *this; }
    mint& operator -= (const mint &y) { x=x<y.x?x-y.x+mod:x-y.x; return *this; }
    mint& operator *= (const mint &y) { x=1ll*x*y.x%mod; return *this; }
    friend mint operator + (mint x,const mint &y) { return x+=y; }
    friend mint operator - (mint x,const mint &y) { return x-=y; }
    friend mint operator * (mint x,const mint &y) { return x*=y; }
};	mint Pow(mint x,LL y=mod-2) { mint z(1);for(;y;y>>=1,x*=x)if(y&1)z*=x;return z; }

const int N = 205;
int n,L,R,s,t,deg[N];
vector<Pii> e[N];
multiset<int> st;

void dfs(int u,int x) {
    // cerr<<u<<" "<<x<<'\n';
    if( u == t ) { st.emplace(x); return; }
    for(auto [v,w] : e[u]) dfs(v,x<<1|w);
}

void MAIN() {
    ifstream fin("in");
    ifstream fout("out");
    fin>>L>>R;
    fout>>n;
    For(i,1,n, m) {
        fout>>m;
        e[i].resize(m);
        for(auto &[j,k] : e[i]) fout>>j>>k, ++deg[j];
        if( e[i].empty() ) assert(!t), t = i;
    }
    For(i,1,n) if( !deg[i] ) assert(!s), s = i;
    dfs(s,0);
    assert(sz(st)==R-L+1);
    For(i,L,R) assert(st.count(i));
} signed main() {
    ios::sync_with_stdio(0);cin.tie(0);
    int lft=1; while( lft-- ) {
        MAIN();
    }
    return 0;
}
*/

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

5 7

output:

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

result:

ok ok

Test #2:

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

input:

10 27

output:

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

result:

ok ok

Test #3:

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

input:

5 13

output:

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

result:

ok ok

Test #4:

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

input:

1 1000000

output:

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

result:

ok ok

Test #5:

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

input:

1 1

output:

2
1 2 1
0

result:

ok ok

Test #6:

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

input:

7 9

output:

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

result:

ok ok

Test #7:

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

input:

3 7

output:

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

result:

ok ok

Test #8:

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

input:

1 5

output:

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

result:

ok ok

Test #9:

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

input:

1 4

output:

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

result:

ok ok

Test #10:

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

input:

8 9

output:

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

result:

ok ok

Test #11:

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

input:

7 51

output:

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

result:

ok ok

Test #12:

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

input:

51 79

output:

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

result:

ok ok

Test #13:

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

input:

92 99

output:

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

result:

ok ok

Test #14:

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

input:

27 36

output:

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

result:

ok ok

Test #15:

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

input:

55 84

output:

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

result:

ok ok

Test #16:

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

input:

297208 929600

output:

73
1 2 1 
4 4 0 45 1 47 0 49 1 
0 
2 5 0 42 1 
1 6 1 
2 7 0 40 1 
2 8 0 38 1 
2 9 0 35 1 
1 10 1 
2 11 0 33 1 
2 12 0 31 1 
2 13 0 24 1 
1 14 1 
1 15 1 
1 16 1 
1 17 1 
1 18 1 
2 19 0 22 1 
2 20 0 21 1 
2 3 0 3 1 
2 3 0 3 1 
2 23 0 23 1 
2 3 0 3 1 
2 30 0 30 1 
2 23 0 23 1 
2 25 0 25 1 
2 26 0 26 1 ...

result:

ok ok

Test #17:

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

input:

45728 589156

output:

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

result:

ok ok

Test #18:

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

input:

129152 138000

output:

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

result:

ok ok

Test #19:

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

input:

245280 654141

output:

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

result:

ok ok

Test #20:

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

input:

202985 296000

output:

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

result:

ok ok

Test #21:

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

input:

438671 951305

output:

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

result:

ok ok

Test #22:

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

input:

425249 739633

output:

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

result:

ok ok

Test #23:

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

input:

551207 961718

output:

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

result:

ok ok

Test #24:

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

input:

114691 598186

output:

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

result:

ok ok

Test #25:

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

input:

234654 253129

output:

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

result:

ok ok

Test #26:

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

input:

554090 608599

output:

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

result:

ok ok

Extra Test:

score: 0
Extra Test Passed