add 处理输入后ac.

This commit is contained in:
licsber 2023-07-08 15:08:10 +08:00
parent f674b758aa
commit 4d1c595a6b

View File

@ -10,24 +10,16 @@ sys.stdin = io.StringIO('''3
1 4 3 2''')
# TLE
def fun(n, p):
def fun(n, loc):
ans = [0] * n
loc = [0] * n
for i in range(n):
loc[i] = (p.index(i + 1))
ans[0] = 1
for i in range(n):
nums = loc[:i + 1]
nums.sort()
flag = True
for j in range(1, i + 1):
if nums[j] - nums[j - 1] > 1:
flag = False
break
if flag:
ans[i] = 1
l, r = loc[1], loc[1]
for i in range(2, n + 1):
l = min(l, loc[i])
r = max(r, loc[i])
if r - l + 1 == i:
ans[i - 1] = 1
print(''.join(map(str, ans)))
@ -35,8 +27,15 @@ def fun(n, p):
t = int(input())
for _ in range(t):
n = int(input())
p = list(map(int, input().split()))
fun(n, p)
p = []
loc = [0] * (n + 1)
nums = input().split()
for i in range(n):
num = int(nums[i])
p.append(num)
loc[num] = i
fun(n, loc)
if __name__ == '__main__':
pass