Problem p03037 (python)

Fixed submission:
N, M = map(int, input().split())

Ls = []
Rs = []
for i in range(0, M):
    l, r = input().split()
    Ls.append(int(l))
    Rs.append(int(r))

maxL = max(Ls)
minR = min(Rs)
result = max(0, minR-maxL+1)

print(result)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
L, R = 1, N

import math

def merge_list(target):
    L = target[-1][0]
    print(target)
    R = sorted(target, key=lambda x: x[1])[0][1]
    return (L, R)

data = []
for i in range(0, M):
    l, r = input().split()
    data.append((int(l), int(r)))
data = sorted(data, key=lambda x: x[0])

import numpy as np
def saiki(totyuu):
    D = 2 # ぶんかつすう
    if len(totyuu[0]) < 10:
        return merge_list(map(merge_list, totyuu))
    else:
        return saiki(np.array_split(totyuu, D))

data = saiki(data)

print(max(0, data[1]-data[0]+1))

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
L, R = 1, N

import math

def merge_list(target):
    L = target[-1][0]
    R = sorted(target, key=lambda x: x[1])[0][1]
    return (L, R)

data = []
for i in range(0, M):
    l, r = input().split()
    data.append((int(l), int(r)))
data = sorted(data, key=lambda x: x[0])

import numpy as np
def saiki(totyuu):
    D = 2 # ぶんかつすう
    if len(totyuu) < 100:
        return merge_list(list(totyuu))
    else:
        return merge_list(np.array_split(totyuu, D))

data = saiki(data)

print(max(0, data[1]-data[0]+1))

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
L, R = 1, N

import math

def merge_list(target):
    L = target[-1][0]
    R = sorted(target, key=lambda x: x[1])[-1][1]
    return (L, R)

data = []
for i in range(0, M):
    l, r = input().split()
    data.append((int(l), int(r)))
data = sorted(data, key=lambda x: x[0])

import numpy as np
def saiki(totyuu):
    D = 2 # ぶんかつすう
    if len(totyuu) < 100:
        return merge_list(list(totyuu))
    else:
        return merge_list(np.array_split(totyuu, D))

data = saiki(data)

print(max(0, data[1]-data[0]+1))

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
L, R = 1, N

import math

def merge_list(list):
    L = list[-1][0]
    R = sorted(data, key=lambda x: x[1])[-1][1]
    return (L, R)

data = []
for i in range(0, M):
    l, r = input().split()
    data.append((int(l), int(r)))
data = sorted(data, key=lambda x: x[0])

import numpy as np
def saiki(totyuu):
    D = 2 # ぶんかつすう
    if len(totyuu) < 100:
        return merge_list(list(totyuu))
    else:
        return merge_list(np.array_split(totyuu, D))

data = saiki(data)

print(max(0, data[1]-data[0]+1))

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
L, R = 1, N

import math

def merge_list(list):
    L = list[-1][0]
    R = sorted(data, key=lambda x: x[1])[-1][1]
    return (L, R)

data = []
for i in range(0, M):
    l, r = input().split()
    data.append((int(l), int(r)))
data = sorted(data, key=lambda x: x[0])

print(1)

import numpy as np
def saiki(totyuu):
    D = 2 # ぶんかつすう
    if len(totyuu) < 100:
        return merge_list(list(totyuu))
    else:
        return merge_list(np.array_split(totyuu, D))

data = saiki(data)

print(max(0, data[1]-data[0]+1))

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
L, R = 1, N

import math

def merge_list(list):
    L = list[-1][0]
    R = sorted(data, key=lambda x: x[1])[-1][1]
    return (L, R)

data = []
for i in range(0, M):
    l, r = input().split()
    data.append((int(l), int(r)))
data = sorted(data, key=lambda x: x[0])

import numpy as np
def saiki(totyuu):
    mid = int(math.floor(len(totyuu)/2))
    D = 2 # ぶんかつすう
    if len(totyuu) < 100:
        return merge_list(totyuu)
    else:
        return merge_list(np.array_split(totyuu, D))

data = saiki(data)

print(max(0, data[1]-data[0]+1))

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
L, R = 1, N

import math

def merge_list(list):
    return (list[-1][0], min(map(lambda x: x[1], list)))

data = []
for i in range(0, M):
    l, r = input().split()
    data.append((int(l), int(r)))
data = sorted(data, key=lambda x: x[0])

def saiki(totyuu):
    mid = int(math.floor(len(totyuu)/2))
    if len(totyuu) < 10000:
        m1 = merge_list(totyuu[:mid])
        m2 = merge_list(totyuu[mid:])
        return merge_list(totyuu)
    else:
        return merge_list([saiki(totyuu[:mid]), saiki(totyuu[mid:])])

data = saiki(data)

print(max(0, data[1]-data[0]+1))

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
L, R = 1, N

import math

def merge_list(list):
    return (list[-1][0], min(map(lambda x: x[1], list)))

data = []
for i in range(0, M):
    l, r = input().split()
    data.append((int(l), int(r)))
data = sorted(data, key=lambda x: x[0])

def saiki(totyuu):
    mid = int(math.floor(len(totyuu)/2))
    if len(totyuu) < 10000000:
        m1 = merge_list(totyuu[:mid])
        m2 = merge_list(totyuu[mid:])
        return merge_list(totyuu)
    else:
        return merge_list([saiki(totyuu[:mid]), saiki(totyuu[mid:])])

data = saiki(data)

print(max(0, data[1]-data[0]+1))

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
L, R = 1, N

import math

def merge_list(list):
    return (list[-1][0], min(map(lambda x: x[1], list)))

data = []
for i in range(0, M):
    l, r = input().split()
    data.append((int(l), int(r)))
data = sorted(data, key=lambda x: x[0])

def saiki(totyuu):
    mid = int(math.floor(len(totyuu)/2))
    if len(totyuu) < 100:
        m1 = merge_list(totyuu[:mid])
        m2 = merge_list(totyuu[mid:])
        return merge_list(totyuu)
    else:
        return merge_list([saiki(totyuu[:mid]), saiki(totyuu[mid:])])

data = saiki(data)

print(max(0, data[1]-data[0]+1))

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
L, R = 1, N

import math

def merge_list(list):
    return (list[-1][0], min(map(lambda x: x[1], list)))

data = []
for i in range(0, M):
    l, r = input().split()
    data.append((int(l), int(r)))
data = sorted(data, key=lambda x: x[0])

def saiki(totyuu):
    if len(totyuu) < 1000:
        mid = int(math.floor(len(totyuu)/2))
        m1 = merge_list(totyuu[:mid])
        m2 = merge_list(totyuu[mid:])
        return merge_list([m1, m2])
    else:
        return merge_list([saiki(totyuu[:mid]), saiki(totyuu[mid:])])

data = saiki(data)

print(max(0, data[1]-data[0]+1))

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
L, R = 1, N

import math

def merge_list(list):
    # sortずみ
    return (list[-1][0], min(map(lambda x: x[1], list)))

data = []
for i in range(0, M):
    l, r = input().split()
    data.append((int(l), int(r)))
data = sorted(data, key=lambda x: x[0])

# 2つずつくみでしょりしたい
def saiki(totyuu):
    if len(totyuu) < 1000:
        mid = int(math.floor(len(totyuu)/2))
        m1 = merge_list(totyuu[:mid])
        m2 = merge_list(totyuu[mid:])
        return merge_list([m1, m2])
    else:
        return merge_list([saiki(totyuu[:mid]), saiki(totyuu[mid:])])

data = saiki(data)
L = data[0]
R = data[1]

print(max(0, R-L+1))

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
L, R = 1, N

def merge_list(list):
    # sortずみ
    return (list[-1][0], min(map(lambda x: x[1], list)))

data = []
for i in range(0, M):
    l, r = input().split()
    data.append((int(l), int(r)))
data = sorted(data, key=lambda x: x[0])

# 2つずつくみでしょりしたい
def saiki(totyuu):
    if len(totyuu) < 1000:
        mid = int(math.floor(len(totyuu)/2))
        m1 = merge_list(totyuu[:mid])
        m2 = merge_list(totyuu[mid:])
        return merge_list([m1, m2])
    else:
        return merge_list([saiki(totyuu[:mid]), saiki(totyuu[mid:])])

data = saiki(data)
L = data[0]
R = data[1]

print(max(0, R-L+1))

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
L, R = 1, N

def merge_list(list):
    # sortずみ
    return (list[-1][0], min(map(lambda x: x[1], list)))

data = []
for i in range(0, M):
    l, r = input().split()
    data.append((int(l), int(r)))
data = sorted(data, key=lambda x: x[0])

import math
logM = int(math.floor(math.log2(M)))

# 2つずつくみでしょりしたい
def saiki(totyuu):
    for i in range(0, logM):
        if len(totyuu) < 1000:
            mid = int(math.floor(len(totyuu)/2))
            m1 = merge_list(totyuu[:mid])
            m2 = merge_list(totyuu[mid:])
            return merge_list([m1, m2])
        else:
            return merge_list([saiki(totyuu[:mid]), saiki(totyuu[mid:])])

data = saiki(data)
L = data[0]
R = data[1]

print(max(0, R-L+1))

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
L, R = 1, N

def merge_list(list):
    # sortずみ
    return (list[-1][0], min(map(lambda x: x[1], list)))

data = []
for i in range(0, M):
    l, r = input().split()
    data.append((int(l), int(r)))
data = sorted(data, key=lambda x: x[0])

import math
logM = int(math.floor(math.log2(M)))

# 2つずつくみでしょりしたい
def saiki(totyuu):
    for i in range(0, logM):
        if len(totyuu) < 100:
            mid = int(math.floor(len(totyuu)/2))
            m1 = merge_list(totyuu[:mid])
            m2 = merge_list(totyuu[mid:])
            return merge_list([m1, m2])
        else:
            return merge_list([saiki(totyuu[:mid]), saiki(totyuu[mid:])])

data = saiki(data)
L = data[0]
R = data[1]

print(max(0, R-L+1))

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
L, R = 1, N

def merge_list(list):
    # sortずみ
    return (list[-1][0], min(map(lambda x: x[1], list)))

data = []
for i in range(0, M):
    l, r = input().split()
    data.append((int(l), int(r)))
data = sorted(data, key=lambda x: x[0])

import math
logM = math.floor(math.log2(M))

# 2つずつくみでしょりしたい
def saiki(totyuu):
    for i in range(0, logM):
        if len(totyuu) < 100:
            mid = int(math.floor(len(totyuu)/2))
            m1 = merge_list(totyuu[:mid])
            m2 = merge_list(totyuu[mid:])
            return merge_list([m1, m2])
        else:
            return merge_list([saiki(totyuu[:mid]), saiki(totyuu[mid:])])

data = saiki(data)
L = data[0]
R = data[1]

print(max(0, R-L+1))

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
L, R = 1, N

def merge(P1, P2):
    L1, R1 = P1
    L2, R2 = P2
    return (max(L1, L2), min(R1, R2))

data = []
for i in range(0, M):
    data.append(map(int, input().split()))
data = sorted(data, lambda x: x[0])

import math
logM = math.floor(math.log2(M))

totyuu = data
# 2つずつくみでしょりしたい
for i in range(0, logM):
    half = []
    if len(totyuu)%2==1:
        half.append(totyuu[-1])
    for j in range(0, int(math.floor(len(totyuu)/2))):
        # じっさいににこずつ
        half.append(merge(totyuu[2*j], totyuu[2*j+1]))
    # halfに半分入っている
    # totyuuをおきかえる
    totyuu = half
data = totyuu

for i in range(0, len(data)):
  tmpL, tmpR = data[i]
  L = max(1, tmpL)
  R = min(tmpR, R)
  if L>R:
    print(0)
    exit()
print(max(0, R-L+1))