小白70分,3RE求助(python3

P1047 [NOIP2005 普及组] 校门外的树

wgic @ 2022-10-14 23:01:50

如题

4,#7,#8 RE

或者帮忙下个数据点?(不知道为啥实名不了

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)

|