wgic @ 2022-10-14 23:01:50
如题
或者帮忙下个数据点?(不知道为啥实名不了
a,n=map(int,input().split())
t=[[0,a]]
for i in range(n):
x,y=map(int,input().split())
for i in range(len(t)):
p,q=t[i]
if p<x<y<q:
t[i]=[p,x-1]
t.append([y+1,q])
elif p<x<=q<=y:
t[i]=[p,x-1]
elif x<=p<=y<q:
t[i]=[y+1,q]
elif x<=p<q<=y:
t.remove(t[i])
s=0
for i in t:
s+=i[1]-i[0]+1
print(s)
by wgic @ 2022-10-14 23:21:14
AC了(((
a,n=map(int,input().split())
t=[[0,a]]
for i in range(n):
x,y=map(int,input().split())
for i in range(len(t)):
p,q=t[i]
if p<x<y<q:
t[i]=[p,x-1]
t.append([y+1,q])
elif p<x<=q<=y:
t[i]=[p,x-1]
elif x<=p<=y<q:
t[i]=[y+1,q]
elif x<=p<q<=y:
pass
t[i]=[-1,-1]
s=0
for i in t:
if i==[-1,-1]: continue
s+=i[1]-i[0]+1
print(s)