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:
from fractions import gcd
# from datetime import date, timedelta
from heapq import*
import math
from collections import defaultdict, Counter, deque
import sys
from bisect import *
import itertools
import copy
sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7

input = sys.stdin.readline
def main():
    n, c = map(int, input().split())
    stk = [tuple(map(int, input().split())) for i in range(n)]
    stk = sorted(stk, key=lambda x: x[0])

    ans = 1
    l = []
    # heapify(l)
    # heappush(l, (stk[0][1], stk[0][2]))
    l = [(stk[0][1], stk[0][2])]
    for i in range(1, n):
        ll = []
        #heapify(ll)
        for j in range(len(l)):
            # v = heappop(l)
            v = l[j]
            if stk[i][2] == v[1]:
                if stk[i][0] < v[0]:
                    # heappush(ll, v)
                    ll.append(v)
            else:
                if stk[i][0] - 0.5 < v[0]:
                    # heappush(ll, v)
                    ll.append(v)
        # heappush(ll, stk[i][1:])
        ll.append(stk[i][1:])
        l = ll
        ans = max(ans, len(l))
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
import heapq  # heapqライブラリのimport

stdin = sys.stdin
 
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces

N, C = rl()
STC = [[] for _ in range(C+1)]

for _ in range(N):
    s, t, c = rl()
    STC[c].append((s, t))

for i in range(1, C+1):
    stc = STC[i]
    stc.sort()
    p = []
    for j in range(1, len(stc)):
        if stc[j][0] == stc[j-1][1]:
            stc[j] = (stc[j-1][0], stc[j][1])
            p.append(j-1)
    for x in p[::-1]:
        stc.pop(x)
    STC[i] = stc

program = []
for stc_list in STC:
    for s, t in stc_list:
        program.append((s, t))

program.sort()

recorder = [-1]
heapq.heapify(recorder)

for s, t in program:
    if s-0.5 > recorder[0]:
        heapq.heappop(recorder)
    heapq.heappush(recorder, t)

print(len(recorder))

Submission status: Accepted

Solution code:
import sys
from itertools import accumulate
N, C = [int(i) for i in sys.stdin.readline().split()]
ls = {j : [0 for i in range(2*10**5)] for j in range(1,C+1)}
for i in range(N):
    s, t, c = [int(i) for i in sys.stdin.readline().split()]
    ls[c][s] += 1
    ls[c][t+1] -= 1

res = [0 for i in range(2*10**5)]
for _c in range(1, C+1):
    for i, j in enumerate(accumulate(ls[_c])):
        res[i] += min(1,j)
print(max(res))

Submission status: Accepted

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


def solve(N: int, C: int, s: "List[int]", t: "List[int]", c: "List[int]"):
    imos = [[0]*(10**5+2) for _ in range(C+1)]
    channel = dict()

    for i in range(N):
        if channel.get(c[i]) != None:
            channel[c[i]].append((s[i],t[i]))
        else:
            channel[c[i]] = [(s[i],t[i])]

    from itertools import accumulate
    for c in range(1,C+1):
        if channel.get(c) == None:
            continue
        ## start 時間でsort
        channel[c].sort(key = lambda x:x[0])

        # 終了時間が現在一番遅いものを保持しておく
        t_last = -1
        for s,t in channel[c]:
            if t_last == s:
                imos[c][t_last+1] +=1
            else:
                imos[c][s] += 1
            t_last = t
            imos[c][t+1] -= 1
        imos[c]=list(accumulate(imos[c]))

    answer = 0
    for i in range(1,10**5+1):
        a = 0
        for c in range(1,C+1):
            a += imos[c][i]
        answer = max(a,answer)
    
    print(answer)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    s = [int()] * (N)  # type: "List[int]"
    t = [int()] * (N)  # type: "List[int]"
    c = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        s[i] = int(next(tokens))
        t[i] = int(next(tokens))
        c[i] = int(next(tokens))
    solve(N, C, s, t, c)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    N, C = map(int, input().split())
    D = [[0] * (10 ** 5 + 5) for _ in range(C)]    
    for _ in range(N):
        s, t, c = map(int, input().split())
        c -= 1
        D[c][s] += 1
        D[c][t] -= 1
    
    for c in range(C):
        for i in range(1,10 ** 5 + 1):
            D[c][i] += D[c][i-1]

    for c in range(C):
        for i in range(1,10 ** 5 + 1):
            if D[c][i] == 1:
                D[c][i-1] = 1

    S = [0] * (10 ** 5 + 5)
    for c in range(C):
        for i in range(10 ** 5 + 1):
            S[i] += D[c][i]

    print(max(S))

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# D - Recording

N, C = map(int, input().split())
max_time = 10**5
gantt = [[0] * (max_time + 1) for _ in range(C+1)]
stc = []

for _ in range(N):
    stc.append(list(map(int, input().split())))
    
stc = sorted(stc, key = lambda x: x[0])
stc = sorted(stc, key = lambda x: x[2])    

for idx in range(N):
    s, t, c = stc[idx][0], stc[idx][1], stc[idx][2]
    try:
        if stc[idx-1][2] == c and stc[idx-1][1] == s:
            gantt[c][s+1] += 1
        else:
            gantt[c][s] += 1
    except IndexError:
        gantt[c][s] += 1
    if t+1 <= max_time:
        gantt[c][t+1] -= 1

for c in range(C+1):
    for idx in range(1, max_time+1):
        gantt[c][idx] += gantt[c][idx-1]

ans = 0
for idx in range(1, max_time+1):
    tmp = 0
    for c in range(C+1):
        tmp += gantt[c][idx]
    ans = max(ans, tmp)
    
print(ans)

Submission status: Accepted

Solution code:
# D - Recording

N, C = map(int, input().split())
max_time = 10**5
gantt = [[0] * (max_time + 1) for _ in range(C+1)]
stc = []

for _ in range(N):
    stc.append(list(map(int, input().split())))
    
stc = sorted(stc, key = lambda x: x[0])
stc = sorted(stc, key = lambda x: x[2])    

for idx in range(N):
    s, t, c = stc[idx][0], stc[idx][1], stc[idx][2]
    try:
        if stc[idx-1][2] == c and stc[idx-1][1] == s:
            gantt[c][s+1] += 1
        else:
            gantt[c][s] += 1
    except IndexError:
        gantt[c][s] += 1
    if t+1 <= max_time:
        gantt[c][t+1] -= 1

for c in range(C+1):
    for idx in range(1, max_time+1):
        gantt[c][idx] += gantt[c][idx-1]
    
import numpy as np
print(np.max(np.sum(gantt, axis = 0)))

Submission status: Accepted

Solution code:
n,c=map(int,input().split())
d=[[0]*c for _ in [0]*int(1e5)]
for _ in range(n):
    s,t,c=map(int,input().split())
    for j in range(s-1,t):
        d[j][c-1]=1

ans=1
for i in range(int(1e5)):
    s=sum(d[i])
    if s>ans:
        ans=s

print(ans)

Submission status: Accepted

Solution code:
N,C=map(int,input().split())
f=[[0]*int(1e5) for _ in range(C)]

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

print(max(map(sum,zip(*f))))

Submission status: Accepted

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

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

n = 0
nmax = 0
ie = 0
X = [0]*31
while ie<len(E):
    t = E[ie][0]
    while ie<len(E) and E[ie][0]==t and E[ie][2]==1:
        c = E[ie][1]
        if X[c]==0: n+=1
        X[c] +=1
        ie+=1

    nmax = max(nmax, n)
        
    while ie<len(E) and E[ie][0]==t and E[ie][2]==-1:
        c = E[ie][1]
        X[c] -= 1
        if X[c]==0: n-=1
        ie+=1

print(nmax)

Submission status: Accepted

Solution code:
import collections
N, C = map(int, input().split())
stc = [list(map(int, input().split())) for i in range(N)]

stc.sort(key=lambda x: x[0])
table = collections.defaultdict(list)
for s, t, c in stc:
    table[c].append((s, t))
maxtime = 0
for x in table:
    for i in range(len(table[x]) - 1):
        if table[x][i][1] == table[x][i+1][0]:
            table[x][i+1] = (table[x][i][0], table[x][i+1][1])
            table[x][i] = (-1, -1)
    maxtime = max(maxtime, table[x][-1][1])

im = [0]*(maxtime+2)

for x in table:

    for s, t in table[x]:
        if s == -1:
            continue
        im[s] += 1
        im[t+1] -= 1

s = [0]*(maxtime+3)
for i in range(1, maxtime+2):
    s[i+1] = s[i]+im[i]

print(max(s))

Submission status: Accepted

Solution code:
maxlen = 10**5+1
n, channel = [ int(v) for v in input().split() ]
use_list = [ [ 0 for i in range(maxlen) ] for i in range(channel) ]

for i in range(n):
    a, b, c = [ int(v) for v in input().split() ]
    for j in range(a,b+1):
        use_list[c-1][j] = 1


ans = 0
for i in range(maxlen):
    max_at_i = sum([ use_list[j][i] for j in range(channel) ])
    ans = max(max_at_i,ans)
print(ans)

Submission status: Accepted

Solution code:
from itertools import *

def main():
	n, c, *L = map(int, open(0).read().split())
	a = [0] * (10 ** 5 + 1)
	bef = (0, 0)
	for c, s, t in sorted((c, s, t) for s, t, c in zip(*[iter(L)] * 3)):
		a[s - 1 + (bef==(c, s))] += 1
		a[t] -= 1
		bef = (c, t)
	print(max(accumulate(a)))

if __name__=="__main__":
	main()

Submission status: Accepted

Solution code:
from itertools import*
n,c,*L=map(int,open(0).read().split())
a=[0]*(max(L[1::3])+1)
bef=(0,0)
for c,s,t in sorted((c,s,t) for s,t,c in zip(*[iter(L)]*3)):
	a[s-1+(bef==(c,s))]+=1
	a[t]-=1
	bef=(c,t)
print(max(accumulate(a)))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
N, C = map(int, input().split(' '))
lim = (10 ** 5 + 2) * 2
buf = [0 for _ in range(lim)]

import collections

c_durations_dict = collections.defaultdict(list)
for _ in range(N):
    s, t, c = map(int, input().split(' '))
    c_durations_dict[c].append((s, t))

for durations in c_durations_dict.values():
    durations.sort(key=lambda x: x[0])
    i = 0
    while i < len(durations):
        s1, t1 = durations[i]
        while i + 1 < len(durations) and t1 == durations[i + 1][0]:
            t1 = durations[i + 1][1]
            i += 1

        buf[s1 * 2 - 1] += 1
        buf[t1 * 2] -= 1
        i += 1

ans = 0
for i in range(1, lim):
    buf[i] += buf[i - 1]
    ans = max(ans, buf[i])

print(ans)

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

def main():
    pn, cn = map(int, input().split())
    st = [[set(), set()] for _ in range(cn)]
    # 同じチャンネルの連続した番組を結合
    for _ in range(pn):
        s, t, c = map(int, input().split())
        c -= 1
        if s in st[c][1]:
            st[c][1].remove(s)
            if t in st[c][0]:
                st[c][0].remove(t)
            else:
                st[c][1].add(t)
        elif t in st[c][0]:
            st[c][0].remove(t)
            st[c][0].add(s)
        else:
            st[c][0].add(s)
            st[c][1].add(t)
    #print(st)
    # 座標圧縮
    tt = set()
    for c_st in st:
        for s in c_st[0]:
            tt.add(s)
        for t in c_st[1]:
            tt.add(t)
    tn = len(tt)
    ttoi = {}
    for i, t in enumerate(sorted(tt)):
        ttoi[t] = i
    #print(ttoi)
    # imos法のためにチャンネル数の増減をcntに入力
    cnt = [0] * (tn + 1)
    for c_st in st:
        for s in c_st[0]:
            i = ttoi[s]
            cnt[i] += 1
        for t in c_st[1]:
            i = ttoi[t]
            cnt[i + 1] -= 1
    #print(cnt)
    # 累積和をとって最大のチャンネル数を取得
    ans = 0
    for i in range(tn):
        cnt[i + 1] += cnt[i]
        ans = max(ans, cnt[i + 1])
    #print(cnt)
    print(ans)

main()

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n,c=map(int,input().split())
    STC=[tuple(map(int,input().split())) for _ in range(n)]
    STC.sort(lambda x:(x[2],x[0],x[1]))

    # 同じチャンネルで連続するものは結合しておく
    for i in range(n-1):
        s0,t0,c0=STC[i]
        s1,t1,c1=STC[i+1]
        if(c0!=c1): continue
        if(t0==s1):
            STC[i]=(None,None,None)
            STC[i+1]=(s0,t1,c0)
    # 残りについて、[s-1,t)のimosを行う
    M=100000
    imos=[0]*(M+1)
    for s,t,c in STC:
        if(s is None): continue
        imos[s-1]+=1
        imos[t]-=1
    for i in range(M):
        imos[i+1]+=imos[i]
    print(max(imos))
resolve()

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline

def main():
    N, C = map(int, input().split())
    
    event = []
    
    for i in range(N):
        s, t, c = map(int, input().split())
        event.extend([[s, c-1, 1], [t+0.5, c-1, 0]])
        
    event.sort()
    
    nums = [0] * C
    ans = cur = 0
    
    for e, c, m in event:
        if m:
            if not nums[c]: 
                cur += 1
                ans = max(ans, cur)
            nums[c] += 1
        else:
            nums[c] -= 1
            if not nums[c]: cur -= 1
            
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

A = sorted(A)
for s, t, c in A:
    if X[c] and X[c][-1][1] == s:
        X[c][-1][1] = t
    else:
        X[c].append([s-1, t])
Y = []
for x in X:
    Y += x
Z = [0] * 101010
for s, t in Y:
    Z[s+1] += 1
    Z[t+1] -= 1

for i in range(1, 101010):
    Z[i] += Z[i-1]

print(max(Z))

Submission status: Accepted

Solution code:
def examD():
    N, C = LI()
    S = [0] * N; T = [0] * N; c = [0] * N
    # s = t = c =0
    maxt = int(0)
    for i in range(N):
        s, t, a = LI()
        S[i], T[i] = s, t
        c[i] = a
        if maxt < t:
            maxt = t
    pairs = zip(S, T,c)
    sortedpairs = sorted(pairs, key=lambda x: x[1])
    sortedpairs = sorted(sortedpairs, key=lambda x: x[0])
    for i in range(N):
        S[i] = sortedpairs[i][0]
        T[i] = sortedpairs[i][1]
        c[i] = sortedpairs[i][2]
#    print(S)
#    print(T)
#    print(c)
    ans = int(0)
    time = [0] * (maxt + 2)
    timeC = [[] for _ in range(maxt + 2)]
    for i in range(N):
        ##########同じチャンネル
        timeC[T[i]].append(c[i])
        if not c[i] in timeC[S[i]]:
            time[S[i]] += 1
            time[T[i] + 1] -= 1
        else:
            time[S[i] + 1] += 1
            time[T[i] + 1] -= 1

    ansC = int(0)
    for i in range(maxt + 1):
        ansC += time[i]
        ans = max(ansC, ans)
    # print(time)
    print(ans)
    # print(timeC)

import sys,copy,bisect,itertools
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examD()

Submission status: Accepted

Solution code:
import sys
import numpy as np
read = sys.stdin.read

N, C, *stc = map(int, read().split())
recoder = np.zeros((C + 1, 10 ** 5 + 1), np.int64)

for s, t, c in zip(*[iter(stc)] * 3):
    recoder[c, s - 1:t] = 1

answer = np.cumsum(recoder, axis=0).max()

print(answer)

Submission status: Accepted

Solution code:
N,C=map(int,input().split())
L=[list(map(int,input().split())) for _ in range(N)]
L.sort()
stc=[[] for _ in range(C)]
for i in range(N):
  s,t,c=L[i]
  if stc[c-1] and s-stc[c-1][-1][1]<=1:
    stc[c-1][-1]=[stc[c-1][-1][0],t]
  else:
    stc[c-1].append([s-1,t])

STC=[j for i in stc for j in i]
STC.sort()

RCM=[[0,0] for _ in range(C)]
for S,T in STC:
  for i in range(C):
    if RCM[i][1]<=S:
      RCM[i][1]=T
      break

for i in range(C):
  if RCM[i]==[0,0]:
    print(i)
    exit()
print(C)

Submission status: Accepted

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

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

pgs = []
for _ in range(N):
    s, t, c = map(int, input().split())
    pgs.append((s, t, c))

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

for i in range(N):
    s, t, c = pgs[i]
    if i >= 1 and pgs[i-1][2] == pgs[i][2] and pgs[i-1][1] == pgs[i][0]:
        imos[s] += 1
        imos[t] -= 1
    else:
        imos[s-1] += 1
        imos[t] -= 1

ans = 0
a = 0
for i in imos:
    a += i
    ans = max(ans, a)

print(ans)

Submission status: Accepted

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

ans = [0]*C
chan = [0]*C
L.sort()
for i in range(N):
    for j in range(C):
        if ans[j] == L[i][0] and chan[j] == L[i][2]:
            ans[j] = L[i][1]
            break
        elif ans[j] < L[i][0]:
            ans[j] = L[i][1]
            chan[j] = L[i][2]
            break
    ans.sort(reverse=True)
    
num = 0
for i in range(C):
    if ans[i] > 0:
        num += 1
        
print(num)

Submission status: Accepted

Solution code:
import sys

N,C = map(int,input().split())
STC = []
for _ in range(N):
  s,t,c = map(int,sys.stdin.readline().split())
  STC.append([s,t,c])
STC.sort()

rs = [[STC[0][1],STC[0][2]]]
for i in range(1,N):
  len_rs = len(rs)
  
  min_idx = None
  for j in range(len_rs):
    if rs[j][1] != STC[i][2]: tmp_stc_r = STC[i][0] - 0.5
    else: tmp_stc_r = STC[i][0]
 
    if rs[j][0] <= tmp_stc_r:
      if min_idx is None: min_idx = j
      else:
        if rs[j][0] < rs[min_idx][0]: min_idx = j

  if min_idx is None: rs.append([STC[i][1], STC[i][2]])
  else: rs[min_idx] = [STC[i][1], STC[i][2]]
  
print(len(rs))

Submission status: Accepted

Solution code:
# imos 法
from operator import itemgetter

N, C = map(int, input().split())
stc = [list(map(int, input().split())) for _ in range(N)]
stc.sort(key=itemgetter(2, 0))

cs = [0] * (10 ** 5 + 1)
pt, pc = -1, -1
for s, t, c in stc:
    if pt == s and pc == c:
        cs[s] += 1
    else:
        cs[s - 1] += 1
    cs[t] -= 1
    pt, pc = t, c

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

print(max(cs))

Submission status: Accepted

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

tt = [[0] * (10 ** 5 + 1) for _ in range(C)]
for _ in range(N):
    s, t, c = map(int, input().split())
    for i in range(s - 1, t):
        tt[c - 1][i] = 1

ct = [0] * (10 ** 5 + 1)
for i in range(C):
    for j in range(10 ** 5 + 1):
        ct[j] += tt[i][j]

print(max(ct))

Submission status: Accepted

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

tt = [[0] * (10 ** 5 + 1) for _ in range(C)]
for _ in range(N):
    s, t, c = map(int, input().split())
    ttc = tt[c - 1]
    for i in range(s - 1, t):
        ttc[i] = 1

ct = [0] * (10 ** 5 + 1)
for i in range(C):
    tti = tt[i]
    for j in range(10 ** 5 + 1):
        ct[j] += tti[j]

print(max(ct))

Submission status: Accepted

Solution code:
# imos 法
from operator import itemgetter

N, C = map(int, input().split())
stc = [list(map(int, input().split())) for _ in range(N)]
stc.sort(key=itemgetter(2, 0))

cs = [0] * (10 ** 5 + 1)
pc = -1
for s, t, c in stc:
    if pc != c:
        pt = -1
        pc = c
    if pt == s:
        cs[s] += 1
    else:
        cs[s - 1] += 1
    cs[t] -= 1
    pt = t

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

print(max(cs))

Submission status: Accepted

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

tt = [[0] * (10 ** 5 + 1) for _ in range(30)]
for _ in range(N):
    s, t, c = map(int, input().split())
    ttc = tt[c - 1]
    for i in range(s - 1, t):
        ttc[i] = 1

ct = [0] * (10 ** 5 + 1)
for i in range(30):
    tti = tt[i]
    for j in range(10 ** 5 + 1):
        ct[j] += tti[j]

print(max(ct))

Submission status: Accepted

Solution code:
from operator import itemgetter

N, C = map(int, input().split())
stc = [list(map(int, input().split())) for _ in range(N)]
stc.sort(key=itemgetter(2, 0))

cs = [0] * (10 ** 5 * 2 + 1)
pc = -1
for s, t, c in stc:
    if pc != c:
        pt = -1
        pc = c
    if pt == s:
        cs[s * 2] += 1
    else:
        cs[s * 2 - 1] += 1
    cs[t * 2] -= 1
    pt = t

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

print(max(cs))

Submission status: Accepted

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

tt = [[0] * (2 * 10 ** 5 + 1) for _ in range(30)]
for _ in range(N):
    s, t, c = map(int, input().split())
    ttc = tt[c - 1]
    for i in range(s * 2 - 1, t * 2):
        ttc[i] = 1

ct = [0] * (2 * 10 ** 5 + 1)
for i in range(30):
    tti = tt[i]
    for j in range(2 * 10 ** 5 + 1):
        ct[j] += tti[j]

print(max(ct))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
from collections import deque

N,C=map(int, sys.stdin.readline().split()) 
stc=[ map(int, sys.stdin.readline().split()) for _ in range(N)]
stc.sort(key=lambda x:(x[0]) )
max_t=max(stc, key=(lambda x: x[1]))[1]

channel=[ deque() for _ in range(C+1) ]

for s,t,c in stc:
    try:
        prev_s,prev_t=channel[c].pop()
        if prev_t==s:
            channel[c].append((prev_s,t))
        else:
            channel[c].append((prev_s,prev_t))
            channel[c].append((s,t))
    except:
        channel[c].append((s,t))


T=[ 0 for _ in range(max_t+1) ] #時間軸

c=1
for c in range(1,C+1):  #チャンネル
    while channel[c]:
        s,t=channel[c].pop()
        for i in range(s,t+1):
            T[i]+=1

print max(T)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N, C = map(int, input().split())
c = [list(map(int, input().split())) for _ in range(N)]
t = [[0] * (10 ** 5 + 1) for _ in range(C + 1)]
for i in range(N):
  for j in range(c[i][0], c[i][1] + 1):
    t[c[i][2]][j] = 1
res = 0
for i in range(10 ** 5 + 1):
  p = 0
  for j in range(C + 1):
    p += t[j][i]
  res = max(p, res)
print(res)

Submission status: Accepted

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

list_tv = [tuple(map(int, input().split())) for _ in range(n)]
for start, end, ch in list_tv:
  list_rec[ch-1][(start-1):end] = [1] * (end - (start - 1))

count = max(map(sum, zip(*list_rec)))
print(count)

Submission status: Accepted

Solution code:
n,C=map(int,input().split())
stc=[list(map(int,input().split())) for i in range(n)]
d=[[0]*(10**5+1) for i in range(C+1)]
for u in stc:
    s,t,c=u
    if d[c][s]==-1:
        d[c][s]=0
        if d[c][t]==1:
            d[c][t]=0
        else:
            d[c][t]=-1
    else:
        d[c][s]=1
        if d[c][t]==1:
            d[c][t]=0
        else:
            d[c][t]=-1
for i in range(1,C+1):
    for j in range(10**5):
        if d[i][j+1]==1:
            d[i][j]+=1
            d[i][j+1]=0
data=[0]*(10**5+1)
for j in range(1,C+1):
    data[0]+=d[j][0]
for i in range(1,10**5+1):
    for j in range(1,C+1):
        data[i]+=d[j][i]
    data[i]+=data[i-1]
print(max(data))

Submission status: Accepted

Solution code:
# ABC080D - Recording
def main():
    N, C, *STC = map(int, open(0).read().split())
    recorders = [[0] * (10 ** 5 + 1) for _ in range(C + 1)]
    for s, t, c in zip(*[iter(STC)] * 3):
        recorders[c][s - 1 : t] = [1] * (t - s + 1)
    ans = max(sum(sliced) for sliced in zip(*recorders))
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# ABC080D - Recording
def main():
    N, C, *STC = map(int, open(0).read().split())
    recorders = [[0] * (10 ** 5 + 1) for _ in range(C + 1)]
    for s, t, c in zip(*[iter(STC)] * 3):
        recorders[c][s - 1 : t] = [1] * (t - s + 1)
    ans = max(map(sum, zip(*recorders)))
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# ABC080D - Recording
from itertools import accumulate as acc


def main():
    N, C, *STC = map(int, open(0).read().split())
    recorders = [[0] * (10 ** 5 + 1) for _ in range(C + 1)]
    for s, t, c in zip(*[iter(STC)] * 3):
        recorders[c][s - 1 : t] = [1] * (t - s + 1)
    ans = max(map(sum, zip(*recorders)))
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:

def main():
        
    N,C = map(int, input().split())

    #　各時間各チャンネルで録画機が動いてるかどうか
    R = [[0]*(10**5) for _ in range(C)]

    for _ in range(N):
        s,t,c = map(int, input().split())
        #チャンネルｃをｓからｔまで録画、ｓの0.5秒前から録画機を使うのでs-1始まりにする
        R[c-1][s-1:t] = [1] * (t-(s-1))

    ans = max(map(sum, zip(*R)))
    """
    ans = 0
    for t in range(10**5):
        cnt = 0
        #時刻ごとにそれぞれのチャンネルで録画機を使ってるかどうか数え上げる
        for ch in range(C):
            if R[ch][t] == 1: cnt += 1

        ans = max(ans, cnt)
    """
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:

def main():
        
    N,C = map(int, input().split())

    #　各時間各チャンネルで録画機が動いてるかどうか
    R = [[0]*(10**5) for _ in range(C)]

    for _ in range(N):
        s,t,c = map(int, input().split())
        #チャンネルｃをｓからｔまで録画、ｓの0.5秒前から録画機を使うのでs-1始まりにする
        R[c-1][s-1:t] = [1] * (t-(s-1))

    ans = 0
    for t in range(10**5):
        cnt = 0
        #時刻ごとにそれぞれのチャンネルで録画機を使ってるかどうか数え上げる
        for ch in range(C):
            if R[ch][t] == 1: cnt += 1

        ans = max(ans, cnt)

    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:

def main():
        
    N,C = map(int, input().split())

    #　各時間各チャンネルで録画機が動いてるかどうか
    R = [[0]*(10**5) for _ in range(C)]

    for _ in range(N):
        s,t,c = map(int, input().split())
        #チャンネルｃをｓからｔまで録画、ｓの0.5秒前から録画機を使うのでs-1始まりにする
        R[c-1][s-1:t] = [1] * (t-(s-1))

    ans = 0
    for t in range(10**5):
        cnt = 0
        for ch in range(C):
            if R[ch][t] == 1: cnt += 1

        ans = max(ans, cnt)

    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import numpy as np

LIM = int(10e5)
time = [0] * (LIM + 1)
N, C = list(map(int, input().split(" ")))
schs = []
for _ in range(N):
    s, t, c = list(map(int, input().split(" ")))
    schs.append((s,t,c))
schs.sort(key = lambda x:x[0])

schs.sort(key = lambda x:x[2])

# print(schs)
for i,temp in enumerate(schs):
    s,t,c = temp

    s_p,t_p,c_p = schs[i-1]
    if i != 0 and c_p == c and t_p == s:
        time[t_p + 1] += 1
        time[t + 1] -= 1

    else:
        time[s] += 1
        time[t + 1] -= 1
# print(time[:100])
ruiseki = np.cumsum(time)

# print(ruiseki[:10])x
print(np.max(ruiseki[1:]))

Submission status: Accepted

Solution code:
import sys
from itertools import accumulate
input = sys.stdin.readline
def inputs():return [int(x) for x in input().split()]
N,C = inputs()
stc = [inputs() for i in range(N)]
stc = sorted(stc,key=lambda x:x[1])
stc = sorted(stc,key=lambda x:x[2])
ans = [0]*(10**5+2)
for i in range(N):
    s,t,c, = stc[i]
    if i>0 and c==stc[i-1][2] and s==stc[i-1][1]:
      ans[s+1]+=1
      ans[t+1]-=1
      continue
    ans[s]+=1
    ans[t+1]-=1
ans = list(accumulate(ans))
print(max(ans))

Submission status: Accepted

Solution code:
import bisect

N,C = map(int,input().split())
STC = [list(map(int,input().split())) for _ in range(N)]
STC.sort(key=lambda x:x[1])
#print(STC)

P = {}
for p in STC:
  if p[2] not in P:
    P[p[2]] = [p[:2]]
  else:
    pe = P[p[2]][-1]
    if pe[1] == p[0]:
      P[p[2]][-1][1] = p[1]
    else:
      P[p[2]].append(p[:2])
#print(P)

P2 = []
maxt = 0
for val in P.values():
  for v in val:
    P2.append([v[0]-1,v[1]])
    maxt = max(maxt,v[1])
#print(P2)

T = [0 for _ in range(maxt+2)]
for p in P2:
  T[p[0]] += 1
  T[p[1]] -= 1
#print(T)
for i in range(1,maxt+2):
  T[i] += T[i-1]
#print(T)
print(max(T))

Submission status: Accepted

Solution code:
N,C = map(int,input().split())
num = 100009*2
channel = [[0]*num for _ in range(C)]
time = [0]*num

max_num = 0
for i in range(N):
  s,t,c = map(int,input().split())
  s,t,c = 2*s-1,2*t,c-1
  if(channel[c][s-1] == 1): channel[c][s-1] = 0
  else: channel[c][s] = 1 
  channel[c][t] = 1
  max_num = max(max_num,t)

tmp = 0
for i in range(C):
 for j in range(max_num+15):
  if((tmp == 0)and(channel[i][j] == 1)):
    tmp = 1
    a = j
  elif((tmp == 1)and(channel[i][j] == 1)):
    tmp = 0
    b = j
    time[a] += 1
    time[b+1] -= 1

ans = 0    
for i in range(max_num+15):
  if(i != 0): time[i] += time[i-1]
  ans = max(ans,time[i])
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)
input = sys.stdin.readline
from math import factorial
import heapq, bisect
import math
import itertools
# from copy import deepcopy, copy

import queue
from collections import deque




def main():
    num_bangumi, num_channel = map(int, input().split())
    data = [list(map(int, input().split())) for i in range(num_bangumi)]
    max_len = 10 ** 5 + 10

    ans_list = [[0 for i in range(max_len)] for j in range(num_channel)]

    for i in range(num_bangumi):
        s, t, c = data[i]
        ans_list[c - 1][s] += 1
        ans_list[c - 1][t] -= 1
    #
    # for i in range(num_channel):
    #     print(ans_list[i])
    # print()

    for i in range(num_channel):
        for j in range(1, max_len):
            if ans_list[i][j] == 1:
                ans_list[i][j - 1] += ans_list[i][j]
                ans_list[i][j] = 0

    # for i in range(num_channel):
    #     for j in range(max_len - 1)[::-1]:
    #         if ans_list[i][j] == -1:
    #             ans_list[i][j + 1] += ans_list[i][j]
    #             ans_list[i][j] = 0
    #
    # for i in range(num_channel):
    #     print(ans_list[i])
    #     print()



    ans = 0
    now_bangumi = 0

    for j in range(max_len):
        for i in range(num_channel):
            now_bangumi += ans_list[i][j]
        ans = max(ans, now_bangumi)

    print(ans)















if __name__ == '__main__':
    main()