#P11760. [IAMOI R1] 智力检测

    ID: 11229 远端评测题 500ms 128MiB 尝试: 0 已通过: 0 难度: 5 上传者: 标签>数学洛谷原创位运算洛谷比赛

[IAMOI R1] 智力检测

Description

The father-in-law gives an array aa indexed from 11, where initially ai=2i1a_i = 2^{i-1}.

The mother-in-law asks Xiao L to perform the following operations several times:

In the ii-th operation, choose two numbers ui,vi (2ui<vi)u_i, v_i\ (2 \le u_i < v_i), then execute sequentially:

  • aviavi+aui+aui1a_{v_i} \gets a_{v_i} + a_{u_i} + a_{u_i - 1}
  • auia_{u_i} \gets -\infty
  • aui1a_{u_i - 1} \gets -\infty

The first operation has no special restrictions, but for each subsequent operation, it must satisfy vi>vi1v_i > v_{i-1}.

Given TT queries, each with two numbers kk and xx, determine whether it's possible to make ak=xa_k = x through a finite number of operations.

The queries are independent (i.e., the array aa should be reset after each query).

Input Format

Due to large input size, it's recommended to use fast input methods.

The input consists of T+1T + 1 lines:

  • The first line contains a positive integer TT, the number of queries.
  • The next TT lines each contain two positive integers kk and xx, representing a query.

Output Format

Output a binary string of length TT.
The ii-th character of the string indicates the answer to the ii-th query:

  • 1 if it's possible to make ak=xa_k = x;
  • 0 otherwise.
4
6 36
6 35
5 30
5 31
0101

Hint

For 100%100\% of the data:

  • 1T5×1061 \le T \le 5 \times 10^6
  • 1k601 \le k \le 60
  • 0x4×10180 \le x \le 4 \times 10^{18}
Test Case TT kk Special Property Score
1 100\le 100 10\le 10 None 20
2 60\le 60 60\le 60 A
3 1×105\le 1 \times 10^5 None 30
4 5×106\le 5 \times 10^6

Special Property A: Guarantees x=2k1x = 2^{k} - 1.

Please optimize your code for constant factors.

The time and memory limits are at least 2.5 times those of the standard solution (with fast I/O).

Due to large input/output volume, we strongly recommend using fast I/O templates.

char *p1,*p2,buf[1<<20];
inline char gc(){if(p1==p2)p2=(p1=buf)+fread(buf,1,1<<20,stdin);return p1==p2?' ':*p1++;}
inline long long read(){
	register long long s=0; register char c=gc();
	while(c<'0'||c>'9') c=gc();
	while(c>='0'&&c<='9') s=(s<<3)+(s<<1)+(c^48),c=gc();
	return s;
}

x = read() //input x

Translation by DeepSeek R1