Problem:


Score : 400 points

Problem Statement

Joisino is planning to record N TV programs with recorders.

The TV can receive C channels numbered 1 through C.

The i-th program that she wants to record will be broadcast from time s_i to time t_i (including time s_i but not t_i) on Channel c_i.

Here, there will never be more than one program that are broadcast on the same channel at the same time.

When the recorder is recording a channel from time S to time T (including time S but not T), it cannot record other channels from time S-0.5 to time T (including time S-0.5 but not T).

Find the minimum number of recorders required to record the channels so that all the N programs are completely recorded.

Constraints

1≤N≤10^5

1≤C≤30

1≤s_i<t_i≤10^5

1≤c_i≤C

If c_i=c_j and i≠j, either t_i≤s_j or s_i≥t_j.

All input values are integers.

Input

Input is given from Standard Input in the following format:

N C
s_1 t_1 c_1
:
s_N t_N c_N

Output

When the minimum required number of recorders is x, print the value of x.

Sample Input 1

3 2
1 7 2
7 8 1
8 12 1

Sample Output 1

2

Two recorders can record all the programs, for example, as follows:

With the first recorder, record Channel 2 from time 1 to time 7. The first program will be recorded. Note that this recorder will be unable to record other channels from time 0.5 to time 7.

With the second recorder, record Channel 1 from time 7 to time 12. The second and third programs will be recorded. Note that this recorder will be unable to record other channels from time 6.5 to time 12.

Sample Input 2

3 4
1 3 2
3 4 4
1 4 3

Sample Output 2

3

There may be a channel where there is no program to record.

Sample Input 3

9 4
56 60 4
33 37 2
89 90 3
32 43 1
67 68 3
49 51 3
31 32 3
70 71 1
11 12 3

Sample Output 3

2



Sample input:
3 2
1 7 2
7 8 1
8 12 1


Sample output:
2

Submission status: Accepted

Solution code:
import math
#import sys
#input = sys.stdin.readline

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

def ValueToBits(x,digit):
    res = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        res[i]=now%2
        now = now >> 1
    return res

def BitsToValue(arr):
    n = len(arr)
    ans = 0
    for i in range(n):
        ans+= arr[i] * 2**i
    return ans

def ZipArray(a):
    aa = [[a[i],i]for i in range(n)]

    aa.sort(key = lambda x : x[0])
    for i in range(n):
        aa[i][0]=i+1
    aa.sort(key = lambda x : x[1])
    b=[aa[i][0] for i in range(len(a))]
    return b

def ValueToArray10(x, digit):
    ans = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        ans[digit-i-1] = now%10
        now = now //10
    return ans

def Zeros(a,b):
    if(b<=-1):
        return [0 for i in range(a)]
    else:
        return [[0 for i in range(b)] for i in range(a)]

def AddV2(v,w):
    return [v[0]+w[0],v[1]+w[1]]

dir4 = [[1,0],[0,1],[-1,0],[0,-1]]


def clamp(x,y,z):
    return max(y,min(z,x))

class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
 
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i
            
#
def Zaatsu(a):
    a.sort()
    now = a[0][0]
    od = 0
    for i in range(n):
        if(now==a[i][0]):
            a[i][0]=od
        else:
            now = a[i][0]
            od+=1
            a[i][0] = od
    
    a.sort(key = lambda x : x[1])
    return a

class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)

    # 検索
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    # 併合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    # 同じ集合に属するか判定
    def same_check(self, x, y):
        return self.find(x) == self.find(y)


'''
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 2
N = 10 ** 6 + 2
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

'''

def rl(x):
    return range(len(x))

# a = list(map(int, input().split()))

#################################################
#################################################
#################################################
#################################################


#11-


n,c = list(map(int, input().split()))

info2 = [[] for i in range(c)]
info=[]

for i in range(n):
    temp = list(map(int, input().split()))
    info2[temp[2]-1].append(temp)
    
for i in range(c):
    info2[i].sort()
for i in range(c):
    if(len(info2[i])==0):
        continue
    info.append(info2[i][0])
    for j in range(1,len(info2[i])):
        if(info2[i][j][0] == info[-1][1]):
            info[-1][1] = info2[i][j][1]
        else:
            info.append(info2[i][j])
        


tl = []

for i in info:
    tl.append([i[0]-0.5,1])
    tl.append([i[1],-1])


ans = 0
now = 0

tl.sort()
#print(tl)

for i in tl:
    now += i[1]
    ans = max(ans,now)
        
print(ans)

Submission status: Accepted

Solution code:
N,C = map(int, input().split())
s =[0]*N
t =[0]*N
c =[0]*N
for i in range(N):
    s[i],t[i],c[i] = map(int, input().split())

imos = [[0]*int(1e5+20) for _ in range(31)]
for i in range(N):
    imos[c[i]][s[i]]+=1
    imos[c[i]][t[i]+1]-=1

ans = 0
for i in range(1,int(1e5+10)):
    sm = 0
    for j in range(C+1):
        imos[j][i]=imos[j][i-1]+ imos[j][i]
        if imos[j][i] >= 1:
            sm+=1
    ans = max(ans,sm)
print(ans)

Submission status: Accepted

Solution code:
N,C = map(int, input().split())
s =[0]*N
t =[0]*N
c =[0]*N
for i in range(N):
    s[i],t[i],c[i] = map(int, input().split())

imos = [[0]*int(1e5+20) for _ in range(31)]
for i in range(N):
    imos[c[i]][s[i]]+=1
    imos[c[i]][t[i]+1]-=1

ans = 0
for i in range(1,int(1e5+10)):
    sm = 0
    for j in range(31):
        imos[j][i]=imos[j][i-1]+ imos[j][i]
        if imos[j][i] >= 1:
            sm+=1
    ans = max(ans,sm)
print(ans)

Submission status: Accepted

Solution code:
n,c = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]

import numpy as np
a = np.zeros((c+1, 10**5))

for i in range(n):
    a[ab[i][2]][(ab[i][0]-1):ab[i][1]] = [1]*(ab[i][1]-ab[i][0]+1)

b = a.sum(axis=0)

print(int(max(b)))

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, c = map(int, input().split())
    STC = sorted([list(map(int, input().split())) for _ in range(n)], key=lambda x:[x[2], x[0]])

    STC2 = []
    tmp = STC[0]
    for i in range(1, n):
        pre_s, pre_t, pre_c = tmp
        now_s, now_t, now_c = STC[i]
        if pre_c == now_c:
            if pre_t == now_s:
                tmp = [pre_s, now_t, now_c]
            else:
                STC2.append(tmp)
                tmp = STC[i]
        else:
            STC2.append(tmp)
            tmp = STC[i]
    if len(tmp):
        STC2.append(tmp)

    imos = [[0] * (10 ** 5 + 1) for _ in range(c)]
    for i in range(len(STC2)):
        s, t, c = STC2[i]
        imos[c - 1][s - 1] += 1
        imos[c - 1][t] -= 1

    for i in range(c):
        for j in range(1, 10 ** 5 + 1):
            imos[i][j] += imos[i][j - 1]

    res = [0] * (10 ** 5 + 1)
    for i in range(c):
        for j in range(10 ** 5 + 1):
            res[j] += imos[i][j]

    print(max(res))


if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
# heapqの方針で上手くいかなかった
# 解説放送を見てimosにした

def main():
    from collections import namedtuple
    from heapq import heappop, heappush
    import sys
    input = sys.stdin.readline

    Prog = namedtuple('Prog', 'L R')
    Prog.__eq__ = lambda self, other: self.R == other.R
    Prog.__lt__ = lambda self, other: self.R < other.R

    N, C = map(int, input().split())
    ps = tuple([] for _ in range(30))
    for _ in range(N):
        l, r, ch = map(int, input().split())
        heappush(ps[ch - 1], Prog(l, r))

    imos = [0] * (10 ** 5 + 1)
    for ps_ch in ps:
        while ps_ch:
            l, r = heappop(ps_ch)
            while ps_ch and ps_ch[0].L == r:
                r = ps_ch[0].R
                heappop(ps_ch)
            else:
                imos[l - 1] += 1
                imos[r] -= 1

    for i in range(10 ** 5):
        imos[i + 1] += imos[i]

    print(max(imos))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# heapqの方針で上手くいかなかった
# 解説放送を見てimosにした

def main():
    from collections import namedtuple
    from heapq import heappop, heappush
    import sys
    input = sys.stdin.readline

    Prog = namedtuple('Prog', 'L R')
    Prog.__eq__ = lambda self, other: self.R == other.R
    Prog.__lt__ = lambda self, other: self.R < other.R

    N, C = map(int, input().split())
    ps = [[] for _ in range(30)]
    for _ in range(N):
        l, r, ch = map(int, input().split())
        heappush(ps[ch - 1], Prog(l, r))

    imos = [0] * (10 ** 5 + 1)
    for ps_ch in ps:
        while ps_ch:
            l, r = heappop(ps_ch)
            while ps_ch and ps_ch[0].L == r:
                r = ps_ch[0].R
                heappop(ps_ch)
            else:
                imos[l - 1] += 1
                imos[r] -= 1

    ans = imos[0]
    for i in range(10 ** 5):
        imos[i + 1] += imos[i]
        ans = max(ans, imos[i + 1])

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import numpy as np
N,C=map(int, input().split())

#s~tでc
L=np.zeros((C, 10**5+1))

for i in range(N):
    s,t,c=map(int, input().split())
    L[c-1,s-1]+=1
    L[c-1,t]-=1

L=np.cumsum(L, axis=1)
print(int((L>0).sum(axis=0).max()))

Submission status: Accepted

Solution code:
from bisect import bisect_left
import sys
input = sys.stdin.readline
N, C = map(int, input().split())
stc = [[int(i) for i in input().split()] for _ in range(N)]
stc.sort()
stc.sort(key=lambda x: x[2])
a = []
S, T, C = stc[0]
for s, t, c in stc[1:]:
    if c == C and T == s:
        T = t
    else:
        a.append((S, T, C))
        S, T, C = s, t, c
a.append((S, T, C))

a.sort(key=lambda x: x[1])
l = [a[0][1]]
for s, t, c in a[1:]:
    i = bisect_left(l, s)
    if 0 < i and l[i - 1] < s:
        l.pop(i - 1)
    l.append(t)
print(len(l))

Submission status: Accepted

Solution code:
import numpy as np

n,c = map(int,input().split())

li = np.zeros(10**5+1,int)
ch = [[] for _ in range(10**5+1)]
lin = []

for _ in range(n):
    s,t,c = map(int,input().split())
    lin.append((s,t,c))

lin.sort()

for i,j,k in lin:
    if k in ch[i-1]:
        li[i:j] += 1
        ch[j-1].append(k)
    else:
        li[i-1:j] += 1
        ch[j-1].append(k)

print(np.max(li))

Submission status: Accepted

Solution code:
N,C = map(int,input().split())
G = {i:[0 for _ in range(10**5+1)] for i in range(1,C+1)}
for i in range(N):
    s,t,c = map(int,input().split())
    G[c][s] += 1
    G[c][t] -= 1
F = [0 for _ in range(2*(10**5)+1)]
for c in range(1,C+1):
    for i in range(10**5+1):
        if G[c][i]==1:
            F[2*i-1] += 1
        elif G[c][i]==-1:
            F[2*i] -= 1
H = [0 for _ in range(2*(10**5)+1)]
for i in range(1,2*(10**5)+1):
    H[i] = H[i-1]+F[i]
print(max(H))

Submission status: Accepted

Solution code:
def examA():
    C1 = SI()
    C2 = SI()
    ans = "YES"
    if C1[0]!=C2[2] or C1[1]!=C2[1] or C1[2]!=C2[0]:
        ans = "NO"
    print(ans)
    return

def examB():
    A, B, C, X, Y = LI()
    loop = max(X,Y)
    ans = inf
    for i in range(loop+1):
        cost = i*2*C
        if X>i:
            cost += A*(X-i)
        if Y>i:
            cost += B*(Y-i)
        ans = min(ans,cost)
    print(ans)
    return

def examC():
    def gcd(x, y):
        if y == 0:
            return x
        while (y != 0):
            x, y = y, x % y
        return x
    N, x = LI()
    X = LI()
    if N==1:
        print(abs(X[0]-x))
        return
    for i in range(N):
        X[i] = abs(X[i]-x)
    now = gcd(X[0],X[1])
    for i in range(2,N):
        now = gcd(now,X[i])
    ans = now
    print(ans)
    return

def examD():
    N = I()
    C = [LI()for _ in range(N-1)]
    ans = [inf]*N
    for i in range(N):
        cur = 0
        for j in range(i,N-1):
            c, s, f = C[j]
            next = 0
            if cur<=s:
                cur = s+c
            else:
                cur = (1+(cur-1)//f)*f + c
        ans[i] = cur
    for v in ans:
        print(v)
    return

def examE():
    class segment_():
        def __init__(self, A, n, segfunc, ide_ele=0):
            #####単位元######要設定0or1orinf
            self.ide_ele = ide_ele
            ####################
            self.num = 1 << (n - 1).bit_length()
            self.seg = [self.ide_ele] * 2 * self.num
            self.segfunc = segfunc
            # set_val
            for i in range(n):
                self.seg[i + self.num] = A[i]
                # built
            for i in range(self.num - 1, 0, -1):
                self.seg[i] = self.segfunc(self.seg[2 * i], self.seg[2 * i + 1])

        def update(self, k, r):
            k += self.num
            self.seg[k] = r
            while k:
                k >>= 1
                self.seg[k] = self.segfunc(self.seg[k * 2], self.seg[k * 2 + 1])

        # 値xに1加算
        def add(self, k, x=1):
            k += self.num
            self.seg[k] += x
            while k:
                k >>= 1
                self.seg[k] = self.segfunc(self.seg[k * 2], self.seg[k * 2 + 1])

        def query(self, p, q):
            # qは含まない
            if q < p:
                return self.ide_ele
            p += self.num;
            q += self.num
            res = self.ide_ele
            while p < q:
                if p & 1 == 1:
                    res = self.segfunc(res, self.seg[p])
                    p += 1
                if q & 1 == 1:
                    q -= 1
                    res = self.segfunc(res, self.seg[q])
                p >>= 1;
                q >>= 1
            return res
    N, C = LI()
    S = defaultdict(list)
    T = 0
    for _ in range(N):
        s,t,c = LI()
        c -= 1
        T = max(t,T)
        S[c].append([s,t])
    Seg = segment_([0]*(T+1), (T+1), lambda a, b: a + b)
    for i in range(C):
        if not S[i]:
            continue
        S[i].sort()
        #print(S[i])
        Seg.add(S[i][0][0])
        Seg.add(S[i][0][1] + 1, -1)
        for j in range(1,len(S[i])):
            s,t = S[i][j]
            if S[i][j-1][1]==s:
                Seg.add(s + 1)
                Seg.add(t + 1, -1)
            else:
                Seg.add(s)
                Seg.add(t + 1, -1)
    ans = 0
    for j in range(T):
        cur = Seg.query(0,j+1)
        ans = max(ans,cur)
    print(ans)
    return

def examF():
    class combination():
        # 素数のmod取るときのみ　速い
        def __init__(self, n, mod):
            self.n = n
            self.mod = mod
            self.fac = [1] * (n + 1)
            self.inv = [1] * (n + 1)
            for j in range(1, n + 1):
                self.fac[j] = self.fac[j - 1] * j % mod

            self.inv[n] = pow(self.fac[n], mod - 2, mod)
            for j in range(n - 1, -1, -1):
                self.inv[j] = self.inv[j + 1] * (j + 1) % mod

        def comb(self, n, r):
            if r > n or n < 0 or r < 0:
                return 0
            return self.fac[n] * self.inv[n - r] * self.inv[r] % self.mod
    N, M, K = LI()
    B = N*M
    C = combination(B,mod)
    ans = 0
    for i in range(N):
        for j in range(M):
            if i>0 and j>0:
                ans += (i+j)*(N - i) * (M - j) * C.comb(B - 2, K-2) *2
            else:
                ans += (i+j)*(N - i) * (M - j) * C.comb(B - 2, K-2)
            ans %= mod
            #print(ans)
    print(ans)
    return

from decimal import Decimal as dec
import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(input())
def LI(): return list(map(int,sys.stdin.readline().split()))
def DI(): return dec(input())
def LDI(): return list(map(dec,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    examE()

"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""

Submission status: Accepted

Solution code:
n, cc = [int(i) for i in input().split()]
up = [[0] * (2 * 10 ** 5) for _ in range(cc)]
ch = [[0] * (2 * 10 ** 5) for _ in range(cc)]

for _ in range(n):
    s, t, c = map(int, input().split())
    c -= 1
    up[c][s] += 1
    up[c][t] -= 1

for j in range(cc):
    k = 0
    for i in range(2 * 10 ** 5):
        if up[j][i] == 1:
            k = 1
        ch[j][i] = k
        if up[j][i] == -1:
            k = 0
ans = 0
for i in range(2 * 10 ** 5):
    k = 0
    for j in range(cc):
        k += ch[j][i]
    ans = max(ans, k)
print(ans)

Submission status: Accepted

Solution code:
import math
import numpy as np
import queue
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    n,c = map(int,ipt().split())
    cc = [[] for _ in [0]*c]
    tma = 0
    for i in range(n):
        s,t,c = map(int,ipt().split())
        hpq.heappush(cc[c-1],(s,t))
        if t > tma:
            tma = t
    cnt = np.zeros(tma+1,dtype=int)
    for i in cc:
        ps = -1
        pt = -1
        while len(i) > 0:
            ns,nt = hpq.heappop(i)
            if pt == ns:
                pt = nt
                continue
            elif not pt == -1:
                cnt[ps:pt+1:] += np.ones(pt-ps+1,dtype=int)
            ps = ns
            pt = nt
        if not pt == -1:
            cnt[ps:pt+1:] += np.ones(pt-ps+1,dtype=int)
    print(max(cnt))
    return

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**6)
# buff_readline = sys.stdin.buffer.readline
buff_readline = sys.stdin.readline
readline = sys.stdin.readline

INF = 2**62-1


def read_int():
    return int(buff_readline())


def read_int_n():
    return list(map(int, buff_readline().split()))


def read_float():
    return float(buff_readline())


def read_float_n():
    return list(map(float, buff_readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap



@mt
def slv(N, C, STC):
    from collections import Counter
    se = [(2*s, 0, c) for s, t, c in STC]
    te = [(2*t+1, 1, c) for s, t, c in STC]
    e = se + te
    e.sort(reverse=True)
    r = Counter()
    ans = 0
    while e:
        _, k, c = e.pop()
        if k == 0:
            r[c] += 1
        else:
            r[c] -= 1
            if r[c] == 0:
                r.pop(c)
        ans = max(ans, len(r))
    return ans


def main():
    N, C = read_int_n()
    STC = [read_int_n() for _ in range(N)]
    print(slv(N, C, STC))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n,C = map(int,input().split())
ch = [[0]*(200001) for _ in range(C)]
m = 0
for _ in range(n):
    s,t,c = map(int,input().split())
    s = s*2-1
    t *= 2
    c -= 1
    ch[c][s] += 1
    ch[c][t] -= 1
    m = max(m,t)

cnt = [0]*(m+1)
for c in range(C):
    for i in range(1,m+1):
        ch[c][i] += ch[c][i-1]
        if ch[c][i-1] == 0 and ch[c][i] > 0: cnt[i] += 1
        if ch[c][i-1] > 0 and ch[c][i] == 0: cnt[i] -= 1

for i in range(1,m+1): cnt[i] += cnt[i-1]
print(max(cnt))

Submission status: Accepted

Solution code:
n,c=map(int,input().split())
table=[0]*220000
chanels=[[]for i in range(c)]
for i in range(n):
    a,s,ch=map(int,input().split())
    chanels[ch-1].append((a,s))
for i in range(c):
    if chanels[i]:
        chanels[i].sort()
        x,y=chanels[i][0]
        for p,q in chanels[i][1:]+[(0,0)]:
            if y==p:y=q
            else:
                table[2*x-1]+=1
                table[2*y]-=1
                x,y=p,q

from itertools import accumulate
print(max(list(accumulate(table))))

Submission status: Accepted

Solution code:
import numpy as np
N, C = map(int,input().split())
T1 = [[] for _ in range(C)]
for _ in range(N):
    s, t, c = map(int,input().split())
    T1[c-1].append([s,t])
for i in range(C):
    T1[i].sort()
T2 = [[] for _ in range(C)]
for i in range(C):
    for s, t in T1[i]:
        if len(T2[i]) != 0 and T2[i][-1][1] == s:
            T2[i][-1][1] = t
        else:
            T2[i].append([s,t])

L = np.zeros(10 ** 5 + 2, int)
for i in range(C):
    for time in T2[i]:
        L[time[0]] += 1
        L[time[1]+1] -= 1

ans = L.cumsum().max()

print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

import sys
# import time
# import math
# import numpy as np
# import scipy.sparse.csgraph as cs            # csgraph_from_dense(ndarray, null_value=inf), bellman_ford(G, return_predecessors=True), dijkstra, floyd_warshall
# import random                                # random, uniform, randint, randrange, shuffle, sample
# import string                                # ascii_lowercase, ascii_uppercase, ascii_letters, digits, hexdigits
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from datetime import date, datetime          # date.today(), date(year,month,day) => date obj; datetime.now(), datetime(year,month,day,hour,second,microsecond) => datetime obj; subtraction => timedelta obj
# from datetime.datetime import strptime       # strptime('2019/01/01 10:05:20', '%Y/%m/%d/ %H:%M:%S') returns datetime obj
# from datetime import timedelta               # td.days, td.seconds, td.microseconds, td.total_seconds(). abs function is also available.
# from copy import copy, deepcopy              # use deepcopy to copy multi-dimentional matrix without reference
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product, permutations  # product(iter, repeat=n), permutations(iter[,r])
# from itertools import combinations, combinations_with_replacement
# from itertools import accumulate             # accumulate(iter[, f])
from operator import itemgetter              # itemgetter(1), itemgetter('key')
# from fractions import gcd                    # for Python 3.4 (previous contest @AtCoder)

def channel_seamless_join(channel):
    """
    >>> channel_seamless_join([(1, 2), (2, 3), (7, 10), (5, 6), (10, 11)])
    [(1, 3), (5, 6), (7, 11)]
    """
    size = len(channel)
    concatnated = []
    channel.sort(key=itemgetter(0))
    s_memo = -1
    for i in range(size):
        if s_memo < 0:
            s_memo = channel[i][0]
        if i != size - 1:
            if channel[i][1] != channel[i+1][0]:
                concatnated.append((s_memo, channel[i][1]))
                s_memo = -1
        else:
            concatnated.append((s_memo, channel[i][1]))
    return concatnated


def calc_min_machine(seq):
    h = []
    cnt = 0
    for s, t in seq:
        if len(h) == 0 or h[0] > s:
            cnt += 1
        else:
            heappop(h)
        heappush(h, t+1)
    return cnt



def main():
    mod = 1000000007                # 10^9+7
    inf = float('inf')              # sys.float_info.max = 1.79...e+308
    # inf = 2 ** 64 - 1             # (for fast JIT compile in PyPy) 1.84...e+19
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())

    
    n, c = mi()
    channels_list = [[] for _ in range(c)]
    for _ in range(n):
        s, t, c = mi()
        c -= 1
        channels_list[c].append((s, t))

    seq = sum([channel_seamless_join(channel) for channel in channels_list], [])
    # print(seq)
    seq.sort(key=itemgetter(0))
    print(calc_min_machine(seq))


if __name__ == "__main__":
    # import doctest
    # doctest.testmod()
    main()

Submission status: Accepted

Solution code:
N, C = map(int, input().split())
table = [[0]*(10**5 + 1) for i in range(C)]

st = [[] for i in range(C)]
for i in range(N):
  s, t, c = map(int, input().split())
  st[c-1].append([s, t])

st_new = [[] for i in range(C)]
for c in range(C):
  if st[c]:
    st[c].sort()
    st_new[c].append(st[c][0])
    n = len(st[c])
    for i in range(1, n):
      si, ti = st[c][i]
      sii, tii = st_new[c][-1]
      if si == tii:
        st_new[c][-1][1] = ti
      else:
        st_new[c].append([si, ti])

for c in range(C):
  for s, t in st_new[c]:
    table[c][s-1] += 1
    table[c][t] -= 1
  
for c in range(C):
  for i in range(1, 10**5+1):
    table[c][i] += table[c][i-1]

ans = 0
for i in range(10**5 + 1):
  num = 0
  for c in range(C):
    num += table[c][i]
  ans = max(ans, num)

print(ans)

Submission status: Accepted

Solution code:
n, c = map(int, input().split())
cnt = [[0 for _ in range(10 ** 5 + 1)] for _ in range(c)]

for _ in range(n):
    s, t, _c = map(int, input().split())
    for j in range(s, t + 1):
        cnt[_c - 1][j] = 1
ans = 0
for i in range(10 ** 5 + 1):
    ans = max(ans, sum(cnt[j][i] for j in range(c)))
print(ans)

Submission status: Accepted

Solution code:
def main():
    N, C = list(map(int, input().split(' ')))
    progams = [list(map(int, input().split(' '))) for _ in range(N)]
    progams.sort(key=lambda p: p[0])  # sort in ascending order of start time
    recorders = [[0, 0] for _ in range(C)]  # (end time, channel)
    for prog in progams:
        s, t, c = prog
        for i in range(C):
            can_record = (c == recorders[i][1] and recorders[i][0] <= s) or \
                (c != recorders[i][1] and recorders[i][0] < s)
            if can_record:
                recorders[i][0] = t
                recorders[i][1] = c
                break
    ans = 0
    for i in range(C):
        if recorders[i][0] > 0:
            ans += 1
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n, C = map(int, input().split())
T = 10**5
channel = []
recorder = [0 for _ in range(2*T+1)]
for loop in range(n):
    s, t, ch = map(int, input().split())
    channel.append([s, t, ch-1])

for c in range(C):
    time = [0 for _ in range(2*T+1)] # 0.5秒刻み
    for i in range(n):
        s, t, ch = channel[i]
        if ch == c:
            time[2*s-1] += 1
            time[2*t] -= 1
    for t in range(1, 2*T+1):
        time[t] += time[t-1]
    for t in range(2*T+1):
        if time[t] > 0:
            recorder[t] += 1
ans = 0
for t in range(2*T+1):
    ans = max(ans, recorder[t])
print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
n,C = map(int,input().split())
ch = [[] for _ in range(C)]
tmax = 0
for _ in range(n):
  s,t,c = map(int,input().split())
  ch[c-1].append((s,t))
  tmax = max(tmax,t)
ch = [sorted(i,key= lambda x:x[0]) for i in ch]
imos = [0]*(tmax+2)
for i in ch:
  now = -1
  for ds,dt in i:
    if ds == now:
      imos[ds] +=1
    else:
      imos[ds-1] += 1
    imos[dt] -= 1
    now = dt
for i in range(tmax +1):
  imos[i+1] += imos[i]
print(max(imos))

Submission status: Accepted

Solution code:
import sys
import numpy as np
input = sys.stdin.readline
n,C = map(int,input().split())
a = np.zeros((C,10**5),dtype="int")
for _ in range(n):
  s,t,c = map(int,input().split())
  a[c-1,s-1:t] = 1
print(max(np.sum(a,axis=0)))

Submission status: Accepted

Solution code:
n,C=map(int,input().split())
schedule=[]
time=[[0 for i in range(C)] for j in range(2*10**5+2)]

for i in range(n):
    s,t,c=map(int,input().split())
    schedule.append([s,t,c])

schedule.sort()

for s,t,c in schedule:
    if time[2*s][c-1]==-1:
        time[2*s][c-1]+=1
    else:
        time[2*s-1][c-1]+=1
    time[2*t][c-1]-=1

for i in range(2*10**5+1):
    for j in range(C):
        time[i+1][j]+=time[i][j]
ans=1
for i in range(2*10**5+2):
    tmp=0
    for j in range(C):
        tmp+=time[i][j]
    ans=max(ans,tmp)

print(ans)

Submission status: Accepted

Solution code:
n,C = map(int,input().split())
st = [[] for _ in range(C)]
st2 = [[] for _ in range(C)]

for _ in range(n):
    s,t,c = map(int,input().split())
    st[c-1].append((s,t))

for i in range(C):
    st[i].sort()

for i,e in enumerate(st):
    s1 = -1
    t1 = -1
    for j in e:
        if s1 == -1:
            s1 = j[0]
            t1 = j[1]
        else:
            if j[0] == t1:
                t1 = j[1]
            else:
                st2[i].append((s1-1,t1))
                s1 = j[0]
                t1 = j[1]
    if s1 != -1:
        st2[i].append((s1-1,t1))

imos = [0]*(2*10**5+10)

for i in st2:
    for j in i:
        imos[int(j[0]*2)] += 1
        imos[int(j[1]*2)] -= 1

for i in range(2*10**5+5):
    imos[i+1] += imos[i]

print(max(imos))