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