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:
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import fractions
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
import collections
from collections import Counter
from collections import deque
import pprint
import itertools

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""


def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


# a^n
def power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod


# n*(n-1)*...*(l+1)*l
def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a

# Union Find
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


inf = 10 ** 18
mod = 10 ** 9 + 7

n,C = lr()
sc = [[] for i in range(C)]
sct = [0 for i in range(10**5+1)]
scts = [[0 for i in range(10**5+1)] for j in range(C)]
for i in range(n):
    s,t,c = lr()
    sc[c-1].append([s,t])
for i,S in enumerate(sc):
    pre = -1
    for s,t in S:
        if s == pre or s == pre+1:
            scts[i][s-1]=1
        for j in range(s,t+1):
            scts[i][j]=1
ans = 0
for i in range(10**5+1):
    pre = 0
    for j in range(C):
        pre+=scts[j][i]
    ans=max(ans,pre)
print(ans)

Submission status: Accepted

Solution code:
def Csum(a):
    b,c=[0],0
    for i in range(len(a)):
        c+=a[i]
        b.append(c)
    return b

n,c=map(int,input().split())
a=[list(map(int,input().split())) for i in range(n)]
b=[[0]*(10**5+10) for i in range(c)]
for i in a:
    b[i[2]-1][i[0]-1]+=1
    b[i[2]-1][i[1]]-=1
b=[Csum(i) for i in b]
ans=[]
for i in range(10**5+10):
    d=0
    for j in range(c):
        if b[j][i]>0:
            d+=1
    ans.append(d)
print(max(ans))

Submission status: Accepted

Solution code:
N, C = map(int, input().split())
accu = [[0]*(10**5+10) for _ in range(C)]
for _ in range(N):
    s, t, c = map(int, input().split())
    accu[c-1][s] += 1
    accu[c-1][t+1] -= 1
for i in range(C):
    for j in range(1, 10**5+10):
        accu[i][j] += accu[i][j-1]
ans = 0
for i in range(10**5+10):
    tmp = 0
    for j in range(C):
        tmp += accu[j][i]>0
    ans = max(ans, tmp)
print(ans)

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc080/tasks/abc080_d
# D - Recording

N,C = map(int,input().split())
s=[0]*N
t=[0]*N
c=[0]*N
f=[False]*C
yoyaku=[False]*C
L=[]
for i in range(N):
    s[i],t[i],c[i]= map(int,input().split())
    L.append( [s[i]-0.5,c[i]-1,1] )
    L.append( [t[i],c[i]-1,0] )

L.sort()
#print(L)
ans=0
tmp=0

for i,(time, ch, sw) in enumerate(L):
    if sw==1:
        if f[ch]==False:
            tmp +=1
            f[ch]=True
            ans = max(ans,tmp)
        else:
            yoyaku[ch]=True
    else:
        if yoyaku[ch]:
            yoyaku[ch]=False
        else:
            tmp -= 1
            f[ch]=False
   
print(ans)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.read
def main():
    n, c = map(int, input().split())
    d = {e: [0] * (c + 1) for e in range(100001)}
    d1 = [0] * 100001
    m = map(int, read().split())
    stc = zip(m, m, m)
    for s, t, c in stc:
        if d[s][c]:
            d1[s - 1] -= 1
            d1[s] += 1
        else:
            d[s][c] = 1
        if d[t][c]:
            d1[t - 1] -= 1
            d1[t] += 1
        else:
            d[t][c] = 1
        d1[s - 1] += 1
        d1[t] -= 1

    cur = 0
    r = 0
    for i1 in range(100001):
        cur += d1[i1]
        r = max(r, cur)
    print(r)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

N, C = MAP()
stc = [LIST() for _ in range(N)]
stc.sort(key=lambda x:(x[2], x[0]))

tmp_s = stc[0][0]
tmp_t = stc[0][1]
tmp_c = stc[0][2]

stc = stc[1:]
stc_new = []

for s, t, c in stc:
	if c == tmp_c and s == tmp_t:
		tmp_t = t
	else:
		stc_new.append((tmp_s, tmp_t))
		tmp_s = s
		tmp_t = t
		tmp_c = c
stc_new.append((tmp_s, tmp_t))

now = [0]*(10**5+1)

for s, t in stc_new:
	now[s-1] += 1
	now[t] -= 1

now_acc = list(accumulate(now))

print(max(now_acc))

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
import numpy as np
#decimal.getcontext().prec = 10

N, C = MAP()

n = [[] for _ in range(C)]
for _ in range(N):
	s, t, c = MAP()
	n[c-1].append((s, t))

m = [[] for _ in range(C)]

for i in range(C):
	if n[i] == []:
		continue
	n[i].sort(key = lambda y:y[0])
	s = n[i][0][0]
	t = n[i][0][1]
	L = len(n[i])
	n[i].append((0, 0))
	for j in range(L):
		if j < L and n[i][j][1] == n[i][j+1][0]:
			t = n[i][j+1][1]
		else:
			m[i].append((s, t))
			s = n[i][j+1][0]
			t = n[i][j+1][1]

#print(m)
cnt = [0]*(10**5+1)

for x in m:
	for s, t in x:
		cnt[s-1] += 1
		cnt[t] -= 1


cnt = list(accumulate(cnt))
#print(cnt)
print(max(cnt))

Submission status: Accepted

Solution code:
N, C = map(int, input().split())
tv = [[0]*C for _ in range(100000)]
for _ in range(N):
    s, t, c = map(int, input().split())
    for i in range(s-1, t): tv[i][c-1] = 1
print(max([sum(tv[i]) for i in range(100000)]))

Submission status: Accepted

Solution code:
n,c = map(int,input().split())
ab = []
for _ in range(n):
    s, t, cha = (int(x) for x in input().split())
    ab.append([s, t, cha])

ab = sorted(ab, key=lambda x: x[0])
ab = sorted(ab, key=lambda x: x[2])

for i in range(1,n):
    if ab[i][0] == ab[i-1][1] and ab[i][2] == ab[i-1][2]:
        ab[i][0] = ab[i-1][0]
        ab[i-1][0] = -1

time = [0]*(10**5+1)

for i in range(n):
    if ab[i][0] == -1:
        continue
    time[ab[i][0]-1] += 1
    time[ab[i][1]] -= 1

ans = 0
memo = 0

for i in time:
    memo += i
    ans = max(ans,memo)

print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
# hello worldと表示する
#float型を許すな
#numpyはpythonで
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n,c=MI()
dp=[[0]*c for i in range(10**5+1)]
for i in range(n):
    s,t,ch=MI()
    for j in range(s,t+1):
        dp[j][ch-1]=1
mx=0
#print(dp)
for i in range(10**5):
    u=sum(dp[i])
    if u>mx:
        mx=u
print(mx)

Submission status: Accepted

Solution code:
N, C = map(int, input().split())
stc = [list(map(lambda x:int(x), input().split())) for _ in range(N)]

stc = sorted(stc, key=lambda x:(x[2], x[0], x[1]))
l = []
i = N-1
s, t, c = 0, 0, 0
while i >= 0:
    if stc[i][2] == stc[i-1][2] and stc[i][0] == stc[i-1][1]:
        s = stc[i-1][0]
        if t == 0:
            t = stc[i][1]
        c = stc[i][2]
    else:
        if s != 0:
            l += [[s, t, c]]
            s, t, c = 0, 0, 0
        else:
            l += [stc[i]]

    i -= 1
        
imos = [0]*(2*10**5+1)
for s, t, c in l:
    imos[s-1] += 1
    imos[t] -= 1

for i in range(len(imos)-1):
    imos[i] = imos[i] + imos[i-1]

print(max(imos))

Submission status: Accepted

Solution code:
n,C=map(int,input().split())

chs=[[] for i in range(31)]

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

for q in range(len(chs)):
    ch=chs[q][:]
    ch.sort()
    new=[]
    if len(ch)<=1:
        continue
    else:
        now=ch[0]
        for i in range(1,len(ch)):
            if now[1]==ch[i][0]:
                now=(now[0],ch[i][1])
            else:
                new.append(now)
                now=ch[i]
        new.append(now)
        chs[q]=new[:]

tim=[0 for i in range(200002)]

for ch in chs:
    for pro in ch:
        tim[pro[0]*2-1]+=1
        tim[pro[1]*2]-=1

cnt=0
ans=0
for i in range(len(tim)):
    cnt+=tim[i]
    ans=max(ans,cnt)
print(ans)

Submission status: Accepted

Solution code:
import heapq
N, C = list(map(int, input().split()))

ans = C
d = [list() for _ in range(C+1)]
for _ in range(N):
    s, t, c = map(int, input().split())
    d[c].append([s, t])

S = [0]*(10**5+1)
T = [0]*(10**5+1)

for i in range(C+1):
    if not d[i]:
        continue
    d[i].sort()
    s, t = d[i][0]
    for j in range(1, len(d[i])):
        if t == d[i][j][0]:
            t = d[i][j][1]
        else:
            S[s] += 1
            T[t] += 1
            s, t = d[i][j]
    S[s] += 1
    T[t] += 1

temp = 0
ans = 0
for i in range(1, 10**5+1):
    temp += S[i]-T[i-1]
    ans = max(ans, temp)
    
print(ans)

Submission status: Accepted

Solution code:
N, C = [int(_) for _ in input().split()]

MT = (10 ** 5 + 10)

memo = [[0] * C for _ in range(MT)]

stc = sorted([[int(_) for _ in input().split()] for _ in range(N)])
for s, t, c in stc:
    if memo[s][c - 1] < 0:
        memo[s][c - 1] = 0
    else:
        memo[s - 1][c - 1] += 1
    memo[t][c - 1] -= 1
ans = 0
cnt = 0
for i in range(MT):
    cnt += sum(memo[i])
    ans = max(ans,cnt)
print(ans)

Submission status: Accepted

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7


#############
# Main Code #
#############

N, C = getNM()
query = [getList() for i in range(N)]
dp = [[0] * (C + 1) for i in range(10 ** 5 + 2)]
for i in range(N):
    s, t, c = query[i]
    dp[s][c] += 1
    dp[t + 1][c] -= 1

for i in range(1, 10 ** 5 + 2):
    for j in range(C + 1):
        dp[i][j] += dp[i - 1][j]

ans = 0
for i in range(10 ** 5 + 2):
    cnt = 0
    for j in dp[i]:
        if j > 0:
            cnt += 1
    ans = max(ans, cnt)
print(ans)

Submission status: Accepted

Solution code:
def main():
    from itertools import accumulate
    n, c, *stc = map(int, open(0).read().split())
    table = [0] * (10 ** 5 + 2)
    m = sorted(list(zip(*[iter(stc)] * 3)), key=lambda a: (a[2], a[0]))

    ch_ = 0
    t_ = 0
    for s, t, ch in m:
        if ch != ch_:
            ch_ = ch
            t_ = 0
        if t_ == s:
            table[t_ + 1] += 1
        else:
            table[s] += 1

        table[t + 1] -= 1
        t_ = t

    *x, = accumulate(table)
    ans = max(x)

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    from itertools import accumulate
    n, c, *stc = map(int, open(0).read().split())
    table = [0] * (10 ** 5 + 2)
    m = sorted(list(zip(*[iter(stc)] * 3)), key=lambda a: (a[2], a[0], a[1]))

    ch_ = 0
    t_ = 0
    for s, t, ch in m:
        if ch != ch_:
            ch_ = ch
            t_ = 0
        if t_ == s:
            table[t_ + 1] += 1
        else:
            table[s] += 1

        table[t + 1] -= 1
        t_ = t

    *x, = accumulate(table)
    ans = max(x)

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    from itertools import accumulate
    n, c, *stc = map(int, open(0).read().split())
    table = [0] * (10 ** 5 + 2)
    m = list(zip(stc[::3], stc[1::3], stc[2::3]))
    m.sort(key=lambda a: (a[2], a[0], a[1]))

    ch_ = 0
    t_ = 0
    for s, t, ch in m:
        if ch != ch_:
            ch_ = ch
            t_ = 0
        if t_ == s:
            table[t_ + 1] += 1
        else:
            table[s] += 1

        table[t + 1] -= 1
        t_ = t

    *x, = accumulate(table)
    ans = max(x)

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    from itertools import accumulate
    n, c, *stc = map(int, open(0).read().split())
    table = [0] * 2 * (10 ** 5 + 1)
    m = list(zip(stc[::3], stc[1::3], stc[2::3]))
    m.sort(key=lambda a: (a[2], a[0], a[1]))

    ch_ = 0
    t_ = 0
    for s, t, ch in m:
        if ch != ch_:
            ch_ = ch
            t_ = 0
        if t_ == 2 * s:
            table[t_ + 1] += 1
        else:
            table[2 * s - 1] += 1

        table[2 * t + 1] -= 1
        t_ = 2 * t

    *x, = accumulate(table)
    ans = max(x)

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
import heapq
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache

#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')
AZ = "abcdefghijklmnopqrstuvwxyz"

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n): return kaijo_memo[n]
  if(len(kaijo_memo) == 0): kaijo_memo.append(1)
  while(len(kaijo_memo) <= n): kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n): return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0): gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n): gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if n == r: return 1
  if n < r or r < 0: return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1: arr.append([temp, 1])
  if arr==[]: arr.append([n, 1])
  return arr

#####MakeDivisors######
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)
  return divisors

#####MakePrimes######
def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum

#####GCD#####
def gcd(a, b):
    while b: a, b = b, a % b
    return a

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n-1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n: return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))

def base_10_to_n_without_0(X, n):
  X -= 1
  if X//n: return base_10_to_n_without_0(X//n, n)+[X%n]
  return [X%n]

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############

N,C = IL()
L = ILL(N)
L.sort()

count = 1
q = [(L[0][1],L[0][2])]
for s,t,c in L[1:]:
  if (s,c) in q:
    q.remove((s,c))
    heapq.heappush(q,(t,c))
  elif q[0][0] < s:
    heapq.heappop(q)
    heapq.heappush(q,(t,c))
  else:
    count += 1
    heapq.heappush(q,(t,c))

print(count)

Submission status: Accepted

Solution code:
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n, c = map(int, readline().split())
    l = 2 * (10 ** 5) + 1
    cum = [0] * l
    used = [[False] * l for _ in range(c + 1)]

    for i in range(n):
        s, t, c = map(int, readline().split())
        if used[c][2 * s]:
            cum[2 * s] += 1
        else:
            cum[2 * s - 1] += 1
            used[c][2 * s] = True

        if used[c][2 * t]:
            cum[2 * t - 1] -= 1
        else:
            cum[2 * t] -= 1
            used[c][2 * t] = True

    ans = 0
    cur = 0
    for x in cum:
        cur += x
        ans = max(ans, cur)

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N, C = map(int, input().split())

tv = [[0]*C for _ in range(100000)]
for _ in range(N):
    s, t, c = map(int, input().split())
    for i in range(s-1, t): tv[i][c-1] = 1
    
print(max([sum(tv[i]) for i in range(100000)]))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# N,M = map(int,sys.stdin.readline().split())
# a = tuple(map(int,sys.stdin.readline().split())) # single line with multi param
# a = tuple(int(sys.stdin.readline()) for _ in range(N)) # multi line with single param
# a = tuple(tuple(map(int,sys.stdin.readline().rstrip().split())) for _ in range(N)) # multi line with multi param
# s = sys.stdin.readline().rstrip()
# N = int(sys.stdin.readline())
# INF = float("inf")
import sys

N,C = map(int,sys.stdin.readline().split())
stc = tuple(tuple(map(int,sys.stdin.readline().rstrip().split())) for _ in range(N)) # multi line with multi param
M = 10**5
imos=[[0]*(M+1) for _ in range(C+1)]

for s,t,c in stc:
    imos[c][s] += 1
    if t+1 < M+1:
        imos[c][t+1] -= 1

#print(imos)
s = set()
ret = 0
for i in range(M):
    for c in range(C+1):
        imos[c][i+1] += imos[c][i]
    ret = max(ret,sum(min(1,imos[c][i+1]) for c in range(C+1)))
#print(imos)
print(ret)

Submission status: Accepted

Solution code:
n,c=map(int,input().split())
chan=[[] for _ in range(c)]
for _ in range(n):
    s,t,sc=map(int,input().split())
    sc-=1
    chan[sc].append((s,t))
for i in range(c):
    chan[i].sort()
#print(chan)
for i in range(c):
    lis=[]
    if len(chan[i])==1:
        lis.append(chan[i][0][0])
        lis.append(chan[i][0][1])
    elif len(chan[i])>=2:
        lis.append(chan[i][0][0])
        for j in range(len(chan[i])-1):
            if chan[i][j][1]!=chan[i][j+1][0]:
                lis.append(chan[i][j][1])
                lis.append(chan[i][j+1][0])
        lis.append(chan[i][j+1][1])
    chan[i]=lis
#print(chan)
accum=[0]*(10**5+2)
for i in range(c):
    for j in range(0,len(chan[i])-1,2):
        accum[chan[i][j]]+=1
        accum[chan[i][j+1]+1]-=1
for i in range(10**5+1):
    accum[i+1]+=accum[i]
#print(accum)
print(max(accum))

Submission status: Accepted

Solution code:
from operator import itemgetter
def resolve():
    N, C = list(map(int, input().split()))
    STC = sorted([list(map(int, input().split())) for _ in range(N)], key=itemgetter(2, 0))
    
    counts = [0]*(10**5+1)
    prevt, prevc = -1, -1
    for stc in STC:
        s, t, c = stc
        if prevt == s and prevc == c:
            counts[s] += 1
        else:
            counts[s - 1] += 1
        counts[t] -= 1
        prevt, prevc = t, c
    for i in range(1, 10**5+1):
        counts[i] += counts[i-1]
    #print(counts[:15])
    print(max(counts))


if '__main__' == __name__:
    resolve()

Submission status: Accepted

Solution code:
N, C = map(int, input().split())
tv = [[0]*C for _ in range(100000)]
for _ in range(N):
    s, t, c = map(int, input().split())
    for i in range(s-1, t): tv[i][c-1] = 1
print(max([sum(tv[i]) for i in range(100000)]))

Submission status: Accepted

Solution code:
n,C=map(int,input().split())
dp=[[0 for i in range(100002)] for j in range(31)]
for i in range(n):
  s,t,c=map(int,input().split())
  t+=1
  dp[c][s]+=1
  dp[c][t]-=1
nm=[0 for i in range(100002)]
for i in range(31):
  s=1
  for j in range(1,100002):
    dp[i][j]+=dp[i][j-1]
    if dp[i][j]==0 and dp[i][j-1]==1:
      nm[s]+=1
      nm[j]-=1
    elif dp[i][j]==1 and dp[i][j-1]==0:
      s=j
for i in range(1,100002):
  nm[i]+=nm[i-1]
print(max(nm))

Submission status: Accepted

Solution code:
N,C=map(int,input().split())

old=[[] for i in range(C)]

for i in range(N):
    s,t,c=map(int,input().split())
    old[c-1].append((s,t))
ch=[]
for li in old:
    li.sort()
    j=0
    while(j<len(li)):
        start=li[j][0]
        while(j<len(li)-1 and li[j][1]==li[j+1][0]):
            j+=1
        end=li[j][1]
        ch.append((((start-1)*2)+1,end*2))
        j+=1
    
        
imos=[0]*(2*10**5+10)
for s,t in ch:
    imos[s]+=1
    imos[t]-=1
for i in range(1,2*10**5+10):
    imos[i]=imos[i-1]+imos[i]
print(max(imos))

Submission status: Accepted

Solution code:
import numpy as np
import sys
input = sys.stdin.readline

def main(args):
    N,C = map(int,input().split())
    
    time = [[0]*(10**5+1) for _ in range(C)]
    
    for _ in range(N):
        s, t, c = map(lambda x:int(x)-1,input().split())
        time[c-1][s] += 1
        time[c-1][t+1] -= 1
        
    recorder = np.where(np.cumsum(time[0]) > 0, 1, 0)
    
    for i in range(1,C):
        recorder += np.where(np.cumsum(time[i]) > 0, 1, 0)
    
    print(max(recorder))
    
if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Accepted

Solution code:
n, c = map(int, input().split())
imos = [0 for _ in range(10 ** 5 + 1)]
ans = 0
channel = [[] for _ in range(30)]
for _ in range(n):
    s, t, c = map(int, input().split())
    channel[c - 1].append([s, t])
    
for lst in channel:
    lst.sort()
    before = 0
    for s, t in lst:
        start = max(before, s - 1)
        imos[start] += 1
        end = min(t, 10 ** 5 + 1)
        imos[end] -= 1
        before = end
tmp = 0
for num in imos:
    tmp += num
    ans = max(ans, tmp)
print(ans)

Submission status: Accepted

Solution code:
n, c = map(int, input().split())
# input時に前処理として以下のことをしておく
#   * 開始時間を-1(-0.5の制約だが、-1しても変わらないので-1する)しておく

# テレビ局の番組をチャンネルごとに登録
r = [[0 for i in range(c)] for j in range(100000)]
for _ in range(n):
    s,t,c = map(int, input().split())
    for j in range(s-1, t):
        r[j][c - 1] = 1
# print(*r,sep='\n')

ans = 0
for i in range(len(r)):
    ans = max(ans, sum(r[i]))
print(ans)


# 補足
# チャンネル数4の場合以下のような配列ができる
# 1行でとある時間のチャンネル状態(1: 録画する, 0: 録画しない)がつく
#[0, 0, 0, 0]
#[0, 0, 1, 0]
#[1, 1, 1, 0]  <- この時間で3チャンネル録画が必要
#[1, 1, 0, 0]  <- この時間で2チャンネル録画が必要
#[1, 1, 0, 0]
#[1, 0, 0, 0]

Submission status: Accepted

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

for i in range(C):
    table[i].sort()
    for j in range(len(table[i])-1):
        if table[i][j][1] == table[i][j+1][0]:
            table[i][j+1][0] = table[i][j][0]
            table[i][j] = [-1, -1]

imos = [0] * (10 ** 5 + 1000)
for channel in table:
    for s, t in channel:
        if s + t < 0:
            continue
        imos[s] += 1
        imos[t+1] -= 1

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

print(max(imos))

Submission status: Accepted

Solution code:
# 1-index
from sys import stdin
import numpy as np
N, C = [int(x) for x in stdin.readline().rstrip().split()]
imos = np.array([[0]*(10**5+1) for i in range(C+1)])

for i in range(N):
    s, t, c = [int(x) for x in stdin.readline().rstrip().split()]
    imos[c, s - 1:t] = 1

imos = np.array(imos)
# print(np.cumsum(imos,axis=1))
ans = max(imos.sum(axis=0))
print(ans)