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 itertools import accumulate

N,C=map(int,input().split())
imos=[0 for i in range(0,10**5+2)]
bangumi={i:[] for i in range(1,C+1)}
for i in range(0,N):
    s,t,c=map(int,input().split())
    imos[s]+=1
    imos[t+1]+=-1
    bangumi[c].append((s,t))

ans=list(accumulate(imos))
for i in range(1,C+1):
    bangumi[i].sort()

for i in range(1,C+1):
    if len(bangumi[i])>1:
        for j in range(0,len(bangumi[i])-1):
            s,t=bangumi[i][j]
            u,v=bangumi[i][j+1]
            if t==u:
                ans[t]-=1

print(max(ans))

Submission status: Accepted

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

for _ in range(N):
    s, t, c = map(int, input().split())
    c -= 1
    X[c][s] += 1
    X[c][t + 1] -= 1
# print(X)
res = [[0] * MAX_N for _ in range(C)]
for c in range(C):
    for i in range(MAX_N - 1):
        res[c][i + 1] = res[c][i] + X[c][i]
# print(ans)
ans = 0
for i in range(MAX_N - 1):
    count = 0
    for c in range(C):
        if 0 < res[c][i]:
            count += 1
    ans = max(ans, count)
print(ans)

Submission status: Accepted

Solution code:
N,C=map(int,input().split())
ch=[[] for i in range(31)]
for i in range(N):
  s,t,c=map(int,input().split())
  ch[c].append([s,t])
arr=[[] for i in range(31)]
start=[]
end=[]
for i in range(31):
  score=[0]*(10**5+1)
  for j in range(len(ch[i])):
    score[ch[i][j][0]]+=1
    score[ch[i][j][1]]-=1
  for j in range(10**5+1):
    if score[j]==1:
      start.append(j)
    if score[j]==-1:
      end.append(j)
ans=[0]*(10**5+3)
for i in start:
  ans[i]+=1
for j in end:
  ans[j+1]-=1
for i in range(10**5):
  ans[i+1]+=ans[i]
print(max(ans))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
try:
    from typing import List
except ImportError:
    pass


def solve(N: int, C: int, s: "List[int]", t: "List[int]", c: "List[int]"):
    progs = [[] for _ in range(C)]
    for si, ti, ci in zip(s, t, c):
        progs[ci - 1].append((si, ti))
    ds = []
    for prog in progs:
        if not prog:
            continue
        prog.sort()
        ds.append((prog[0][0] - 1, 1))
        ds.append((prog[-1][1], -1))
        for i in range(len(prog) - 1):
            if prog[i][1] != prog[i + 1][0]:
                ds.append((prog[i][1], -1))
                ds.append((prog[i + 1][0] - 1, 1))
    ds.sort()
    ans = 0
    m = 0
    for _, d in ds:
        m += d
        ans = max(ans, m)
    print(ans)


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:
n,c= map(int,input().split())
nca = sorted([tuple(map(int,input().split())) for _ in range(n)])
cnf = [True]*n
line=0
while any(cnf):
    lst = ()
    for i in range(n):
        if cnf[i]==True:
            temp = nca[i]
            if (lst == ()) or (temp[2]==lst[2]) or (lst[1] < temp[0]):
                lst = temp
                cnf[i]=False
    line+=1
print(line)

Submission status: Accepted

Solution code:
#080_D
n, c = map(int, input().split())
stc = [list(map(int, input().split())) for _ in range(n)]
stc.sort(key= lambda x: (x[2], x[0]))
imo = [0 for _ in range(10 ** 5 + 2)]

for i in range(n):
    if i < n-1:
        if stc[i][2] == stc[i+1][2] and stc[i][1] == stc[i+1][0]:
            stc[i+1][0] = stc[i][0]
            continue
    
    s, t, c = stc[i]
    imo[s] += 1
    imo[t+1] -= 1

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

print(max(imo))

Submission status: Accepted

Solution code:
import numpy as np
n,C = map(int,input().split())
ch = [[] for _ in range(30)]
for _ in range(n):
    s,t,c = map(int,input().split())
    if s>t:
        s,t = t,s
    ch[c-1].append((s,t))

lst = []
for i in range(30):
    if len(ch[i])!=0:    
        for i, (ns,nt) in enumerate(ch[i]):
            if i==0:
                s,t = ns, nt
            else:
                if ns == t:
                    t = nt
                else:
                    lst.append((s,t))
                    s,t = ns, nt
        else:
            lst.append((s,t))
    
d = [0]*(10**6)
for s,t in lst:
    d[s-1] += 1
    d[t] -= 1
d = np.cumsum(d)
print(min(max(d), C))

Submission status: Accepted

Solution code:
#!/usr/bin/python3
# -*- coding:utf-8 -*-

import numpy

def main():
  n, c = map(int, input().split())
  recoders = numpy.zeros((c, 2*(10**5+1)), dtype=numpy.int)
  for _ in range(n):
    s, t, c = map(int, input().split())
    s = 2*s - 1
    t = 2*t
    c -= 1
    recoders[c][s:t] = 1
  
  print(max(numpy.sum(recoders, axis=0)))
    

if __name__=='__main__':
  main()

Submission status: Accepted

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

P.sort()

rec = []
rec_cha = [None] * C
for s, t, c in P:
    c -= 1
    if rec_cha[c] is None:
        for i, (pt, pc) in enumerate(rec):
            if pt < s:
                rec[i] = (t, c)
                rec_cha[pc] = None
                rec_cha[c] = i
                break
        else:
            rec.append((t, c))
            rec_cha[c] = len(rec) - 1
    else:
        rec[rec_cha[c]] = (t, c)

print(len(rec))

Submission status: Accepted

Solution code:
n,c = map(int,input().split())
L = [[] for i in range(c)]
for i in range(n):
    s,t,k = map(int,input().split())
    L[k-1].append([s,t])
for i in range(c):
    L[i].sort()
for i in range(c):
    d = [0]*(10**5+1)
    T = []
    for j in range(len(L[i])):
        d[L[i][j][0]] += 1
        d[L[i][j][1]] -= 1
    for j in range(10**5):
        d[j+1] += d[j]
    cur = 0
    start = 0
    end = 0
    for j in range(10**5+1):
        if d[j] == 1 and cur == 0:
            start = j
            cur = 1
        elif d[j] == 0 and cur == 1:
            end = j
            cur = 0
            T.append([start*2-1, end*2])
    L[i] = T
dp = [0]*(10**5)*3
ans = 0
for i in range(c):
    for j in range(len(L[i])):
        dp[L[i][j][0]] += 1
        dp[L[i][j][1]] -= 1
for j in range(1,(10**5)*2+3):
    dp[j] = dp[j-1]+dp[j]
    ans = max(ans, dp[j])
print(ans)

Submission status: Accepted

Solution code:
n,c = map(int,input().split())
L = [[] for i in range(c)]
for i in range(n):
    s,t,k = map(int,input().split())
    L[k-1].append([s,t])
for i in range(c):
    L[i].sort()
for i in range(c):
    d = [0]*(10**5+1)
    T = []
    for j in range(len(L[i])):
        d[L[i][j][0]] += 1
        d[L[i][j][1]] -= 1
    for j in range(10**5):
        d[j+1] += d[j]
    cur = 0
    start = 0
    end = 0
    for j in range(10**5+1):
        if d[j] == 1 and cur == 0:
            start = j
            cur = 1
        elif d[j] == 0 and cur == 1:
            end = j
            cur = 0
            T.append([start*2-1, end*2])
    L[i] = T
dp = [0]*(10**5)*3
ans = 0
for i in range(c):
    for j in range(len(L[i])):
        dp[L[i][j][0]] += 1
        dp[L[i][j][1]] -= 1
for j in range(1,(10**5)*3):
    dp[j] = dp[j-1]+dp[j]
    ans = max(ans, dp[j])
print(ans)

Submission status: Accepted

Solution code:
import sys
import itertools
input = sys.stdin.readline
sys.setrecursionlimit(100000)
mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


class v:
    def __init__(self, f):
        self.f = f
        self.v = None
 
    def __str__(self):
        return str(self.v)
 
    def ud(self, n):
        if self.v is None:
            self.v = n
        else:
            self.v = self.f(self.v, n) 


def main():
    import bisect
    N, C = read_values()
    W = read_lists(N)
    W.sort(key=lambda x: x[1], reverse=True)

    R = []
    for s, t, c in W:
        i = bisect.bisect_left(R, (t, -1))

        while i < len(R):
            if R[i][0] != t:
                break
            if R[i][1] == c:
                break
            i += 1

        if i < len(R):
            del R[i]

        bisect.insort(R, (s, c))
    print(len(R))


if __name__ == "__main__":
    main()

Submission status: Accepted

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

data = [[0]*(10**5+1) for i in range(C)]

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

ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
import sys
rline = sys.stdin.readline


def solve():
    N, C = map(int, rline().split())
    schedule = [[0] * 100001 for _ in range(C)]
    for _ in range(N):
        s, t, c = map(lambda x: int(x) - 1, rline().split())
        schedule[c][s] += 1
        schedule[c][t] -= 1
    
    imos = [0] * 100001
    for ch_i in schedule:
        for i in range(100001):
            if ch_i[i] == 1:
                imos[i] += 1
            elif ch_i[i] == -1:
                imos[i + 1] -= 1
    for i in range(1, 100001):
        imos[i] += imos[i - 1]
    print(max(imos))


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
import sys
INF = 10 ** 9
MOD = 10 ** 9 + 7
from collections import deque
sys.setrecursionlimit(100000000)

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

    for _ in range(n):
        s,t,c1 = map(int,input().split())
        c1 -= 1
        time[s][c1] += 1
        time[t][c1] -= 1
    
    for i in range(10 ** 5):
        for j in range(c):
            if time[i][j] == 0 and time[i + 1][j] == 1:
                time[i][j] = 1
                time[i + 1][j] = 0

    ans = sum(time[0])
    tmp = ans
    for i in range(1,10 ** 5 + 1):
        tmp += sum(time[i])
        ans = max(ans, tmp)
    
    print(ans)
if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
N,C=map(int,input().split())
from collections import defaultdict
Cbef=defaultdict(int)
time=defaultdict(int)
TV=[tuple(map(int,input().split())) for i in range(N)]
TV.sort(key=lambda x:x[0])
for s,t,c in TV:
    if Cbef[c]==s:
        time[s]+=1
        time[t]-=1
        Cbef[c]=t
    else:
        time[s-1]+=1
        time[t]-=1
        Cbef[c]=t
ans=0
now=time[0]
ans=now
for i in range(1,10**5+1):
    now+=time[i]
    ans=max(ans,now)
print(ans)

Submission status: Accepted

Solution code:
n, c = map(int, input().split())
a = [[0 for _ in range(c)] for _ in range(10 ** 5 + 1)]
for _ in range(n):
    s, t, u = map(int, input().split())
    a[s][u - 1] += 1
    a[t][u - 1] -= 1
m = 0
x = 0
for b in a:
    x += b.count(1)
    if x > m:
        m = x
    x -= b.count(-1)
print(m)

Submission status: Accepted

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

program.sort()
program.sort(key = lambda x: x[2])
 
for i in range(1,n):
    if program[i][2]==program[i-1][2] and program[i][0]==program[i-1][1]:
        program[i][0] = program[i-1][0]
        program[i-1][0] = None
#print(program)
 
for i in range(n):
    if program[i][0] == None:
        continue
    time[program[i][0]-1] += 1
    time[program[i][1]] -= 1
 
count = 0
max_count = 0
 
for i in range(10**5+1):
    count += time[i]
    max_count = max(max_count,count)
 
print(max_count)

Submission status: Accepted

Solution code:
class Solution:
    def solve(self, N: int, C: int, stc) -> int:

        p = [[0 for _ in range(2*10**5)] for _ in range(C)]

        for s, t, c in stc:
            for i in range(2*s-1, 2*t):
                p[c-1][i] = 1

        ans = 0
        for i in range(2*10**5):
            q = 0
            for c in range(C):
                q += p[c][i]
            ans = max(ans, q)

        return ans


if __name__ == '__main__':

    # standard input
    N, C = map(int, input().split())
    stc = []
    for _ in range(N):
        stc.append(tuple(map(int, input().split())))

    # solve
    solution = Solution()
    print(solution.solve(N, C, stc))

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

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()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

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 tmp_c != c:
		stc_new.append((tmp_s, tmp_t))
		tmp_s = s
		tmp_t = t
		tmp_c = c
		
	elif tmp_t != s:
		stc_new.append((tmp_s, tmp_t))
		tmp_s = s
	
	tmp_t = t
stc_new.append((tmp_s, tmp_t))

now = [0]*(10**5+2)
for s, t in stc_new:
	now[s] += 1
	now[t+1] -= 1

now_acc = accumulate(now)
print(max(now_acc))

Submission status: Accepted

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]
N,C=map(int,input().split())
l=[[0]*10**5 for i in range(C)]
for i in range(N):
    s,t,c=map(lambda x: int(x)-1,input().split())
    for j in range(s,t+1):
        l[c][j]=1
a=0
for i in range(10**5):
    t=0
    for j in range(C):
        if l[j][i]:
            t+=1
    if t>a:
        a=t
print(a)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.buffer.readline
from operator import itemgetter

def main():
    N,C = map(int,input().split())
    ch = [[] for _ in range(C)]
    l = 0
    for _ in range(N):
        s,t,c = map(int,input().split())
        l = max(l,t)
        ch[c-1].append((s,t))
    
    for x in ch:
        x.sort(key=itemgetter(0))

    imos = [0 for _ in range(l+2)]
    for x in ch:
        now = -1
        for st,ft in x:
            if st == now:
                imos[st] += 1
            else:
                imos[st-1] += 1
            imos[ft] -= 1
            now = ft
                
    for i in range(l+1):
        imos[i+1] += imos[i]
    
    print(max(imos))
    
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc080/tasks/abc080_d
# 縦時系列の番組表の四角を横にスライドさせてmaxを求めれば良い
# つまりimos法
# ただし予約タイムが存在するので、開始時刻を-1してあげる
# また同じチャンネルで連続するところは連結してしまおう


class Imos1d:
    def __init__(self, N: int):
        '''
        [0]*N の配列に対して、区間の加算を管理する。
        '''
        self.ls = [0] * (N + 1)  # 配列外参照を防ぐため多くとっておく
        self.N = N

    def add(self, l, r, x):
        '''
        [l,r)の区間にxを足し込む O(1)
        '''
        self.ls[l] += x
        self.ls[min(r, self.N)] -= x  # 配列外参照は余分に作ったところにまとめておく(どうせ使わない)

    def get_result(self):
        '''
        O(N) かけて、区間の加算結果を取得する
        '''
        from itertools import accumulate
        return list(accumulate(self.ls[:-1]))


import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


N, C = read_ints()
from collections import defaultdict, Counter
STbyC = defaultdict(lambda: [])
for n in range(N):
    s, t, c = read_ints()
    STbyC[c].append(s)
    STbyC[c].append(t)

kukan = []
for c in STbyC:
    tmp = Counter(STbyC[c])
    tmp = [k for k, v in tmp.items() if v == 1]  # 二回出現したやつというのは連続録画
    kukan.extend(sorted(tmp))


imos = Imos1d(10 ** 5 + 1)
for i in range(0, len(kukan), 2):
    j = i + 1
    imos.add(kukan[i] - 1, kukan[j], 1)


# print(imos.get_result()[:20])
print(max(imos.get_result()))

Submission status: Accepted

Solution code:
class SegmentTreeLazy():
    def __init__(self, arr, ti, ei, func, op, merge):
        self.h = len(arr).bit_length()
        self.n = 2**self.h
        self.func = func
        self.op = op
        self.merge = merge
        self.ti = ti
        self.ei = ei
        self.data = [ti for _ in range(2 * self.n)]
        for i in range(len(arr)):
            self.data[i + self.n] = arr[i]
        for i in range(1, self.n)[::-1]:
            self.data[i] = self.func(self.data[2 * i], self.data[2 * i + 1])
        self.lazy = [ei for _ in range(2 * self.n)]

    def reflect(self, k):
        if self.lazy[k] == self.ei:
            return self.data[k]
        return self.op(self.data[k], self.lazy[k])

    def propagate(self, k):
        if self.lazy[k] == self.ei:
            return
        self.lazy[2 * k] = self.merge(self.lazy[2 * k], self.lazy[k])
        self.lazy[2 * k + 1] = self.merge(self.lazy[2 * k + 1], self.lazy[k])
        self.data[k] = self.reflect(k)
        self.lazy[k] = self.ei

    def thrust(self, k):
        for i in range(1, self.h + 1)[::-1]:
            self.propagate(k >> i)

    def recalc(self, k):
        while k:
            k //= 2
            self.data[k] = self.func(
                self.reflect(2 * k), self.reflect(2 * k + 1))

    def update(self, left, right, x):
        l, r = left, right
        left += self.n
        right += self.n
        self.thrust(left)
        self.thrust(right - 1)
        while right - left > 0:
            if left & 1:
                self.lazy[left] = self.merge(self.lazy[left], x)
                left += 1
            if right & 1:
                right -= 1
                self.lazy[right] = self.merge(self.lazy[right], x)
            left //= 2
            right //= 2
        self.recalc(l + self.n)
        self.recalc(r + self.n - 1)

    def query(self, left, right):
        left += self.n
        right += self.n
        self.thrust(left)
        self.thrust(right - 1)
        tmp_l = tmp_r = self.ti
        while right - left > 0:
            if left & 1:
                tmp_l = self.func(tmp_l, self.reflect(left))
                left += 1
            if right & 1:
                right -= 1
                tmp_r = self.func(self.reflect(right), tmp_r)
            left //= 2
            right //= 2
        return self.func(tmp_l, tmp_r)


import sys
input = sys.stdin.readline
from operator import add

N, C = map(int, input().split())
A = [0 for _ in range(101010)]

st = SegmentTreeLazy(A, 0, 0, max, add, add)

P = [list(map(int, input().split())) for _ in range(N)]
P.sort()
P.sort(key=lambda x:x[2])

Q = []
prev = P[0]
for i in range(1, N):
    if prev[2] != P[i][2] or prev[1] != P[i][0]:
        Q.append((prev[0], prev[1]))
        prev = P[i]
    else:
        prev = (prev[0], P[i][1], prev[2])
Q.append((prev[0], prev[1]))

for i in range(len(Q)):
    s, t = Q[i]
    st.update(s, t+1, 1)

print(st.query(0, 100010))

Submission status: Accepted

Solution code:
import numpy as np
N, C, *L = map(int, open(0).read().split())
program = np.zeros((10**5+2,C+1),np.int32)
for s,t,c in zip(*[iter(L)]*3):
  program[s][c] += 1
  program[t+1][c] += -1
program = np.cumsum(program, axis=0)
ans = max(np.count_nonzero(a) for a in program)
print(ans)

Submission status: Accepted

Solution code:
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

n,c = m()

time = [[0 for i in range(31)] for j in range(10**5+2)]

popopo = [[] for i in range(30)]

for i in range(n):
    s,t,c = m()
    popopo[c-1].append([s,t])


for i in range(30):
    popopo[i].sort()
    
for i in range(30):
    for j in range(len(popopo[i])):
        s,t = popopo[i][j]
        if time[s][i+1] == 0:
            time[t][i+1] = 1
            time[s-1][0] += 1
            time[t][0] -= 1
        else:
            time[t][i+1] = 1
            time[s][0] += 1
            time[t][0] -= 1

ma = time[0][0]
for i in range(1,10**5+2):
    time[i][0] += time[i-1][0]
    ma = max(ma,time[i][0])
print(ma)

Submission status: Accepted

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

A = [0] * (R+1)
ans = 0
for i in range(R):
    for c in range(C):
        A[i] += T[c][i+1] if T[c][i+1] > 0 else 0
        A[i] += T[c][i] if T[c][i] < 0 else 0
    A[i+1] += A[i]
    ans = max(ans, A[i+1])
print(ans)

Submission status: Accepted

Solution code:
n, c = map(int, input().split())
stc = [list(map(int, input().split())) for _ in range(n)]
T = 10**5+1
record = [[0]*(T+3) for _ in range(c+1)]
channel = [[] for _ in range(c+1)]
stc.sort()

for s, t, c in stc:
    if not channel[c]:
        channel[c].append([s - 1, t])
        continue
    if channel[c][-1][1] == s:
        channel[c][-1][1] = t
    else:
        channel[c].append([s-1, t])

for i, v in enumerate(channel):
    for s, t in v:
        record[i][s] += 1
        record[i][t] -= 1

for i in record:
    for j in range(T+2):
        i[j+1] += i[j]

ans = 0
for i in range(T+2):
    y = 0
    for r in record:
        y += r[i]
    ans = max(ans, y)
print(ans)

Submission status: Accepted

Solution code:
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
from collections import Counter
#from scipy.misc import comb

N,C = map(int, input().split())
L = [list(map(int, input().split())) for i in range(N)]

T_MAX = 10**5
time = [[0]*C for i in range(T_MAX)]

for s,t,c in L:
    time[s-1][c-1] += 1
    time[t-1][c-1] -= 1
 
ans = 0
tmp = 0
for i in range(T_MAX):
    tmp += time[i].count(1)
    ans = max(ans,tmp)
    tmp -= time[i].count(-1)

print(ans)

Submission status: Accepted

Solution code:
N, C = map(int, input().split())
stc = [None] * N
for i in range(N):
    stc[i] = list(map(int, input().split()))
stc.sort()
recorders = []
for s, t, c in stc:
    ok = False
    for i, rec in enumerate(recorders):
        t2, c2 = rec
        if c == c2 and t2 <= s or c != c2 and t2 < s:
            recorders[i] = [t, c]
            ok = True
            break
    if not ok:
        recorders.append([t, c])
print(len(recorders))

Submission status: Accepted

Solution code:
n, channel = map(int, input().split())
STC = []
for _ in range(n):
    s, t, c = map(int, input().split())
    STC.append([2*s,2*t,c])

STC = sorted(STC, key=lambda x: (x[2], x[1]))
# print(STC)

now_s = STC[0][0]
now_t = STC[0][1]
now_c = STC[0][2]

All_bangumi = []

for i in range(1,n):
    if now_c == STC[i][2]:
        if now_t == STC[i][0]:
            now_t = STC[i][1]
            if i == n-1:
                All_bangumi.append([now_s, now_t])
        else:
            All_bangumi.append([now_s, now_t])
            now_s = STC[i][0]
            now_t = STC[i][1]

    else:   
        All_bangumi.append([now_s, now_t])
        now_s = STC[i][0]
        now_t = STC[i][1]
        now_c = STC[i][2]
        if i == n-1:
            All_bangumi.append([now_s, now_t])

if n == 1:
    All_bangumi.append([STC[0][0], STC[0][1]])

for i in range(len(All_bangumi)):
    All_bangumi[i][0] = All_bangumi[i][0] -1


Imos = [0 for _ in range(2*(10**5)+1)]
for i in range(len(All_bangumi)):
    Imos[All_bangumi[i][0]] += 1
    Imos[All_bangumi[i][1]] -= 1

Imos_rui = [0]
for i in range(len(Imos)):
    Imos_rui.append(Imos_rui[-1]+Imos[i])

print(max(Imos_rui))

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
N,C=map(int,input().split())

log=[[0]*C for i in range(10**5)]


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

ans=0
temp=0
for i in range(10**5):
    plus=log[i].count(1)
    temp+=plus
    ans=max(ans,temp)
    minus=log[i].count(-1)
    temp-=minus
#print(log[:15])
print(ans)

Submission status: Accepted

Solution code:
from heapq import heappop, heappush

N, C, *STC = map(int, open(0).read().split())

A = [[] for _ in range(C + 1)]
for s, t, c in zip(*[iter(STC)] * 3):
    A[c].append((s, t))

ST = []
for a in A:
    if not a:
        continue
    a = sorted(a)
    B = [a[0]]
    for s2, t2 in a[1:]:
        s1, t1 = B[-1]
        if t1 == s2:
            B[-1] = (s1, t2)
        else:
            B.append((s2, t2))
    ST += B

ST.sort(key=lambda x: x[0])

ans = 0
Q = []
for s, t in ST:
    while Q and Q[0] < s:
        heappop(Q)
    heappush(Q, t)
    ans = max(ans, len(Q))

print(ans)

Submission status: Accepted

Solution code:
def main():
    N, C, *STC = map(int, open(0).read().split())

    T = [[0] * 10 ** 5 for _ in range(C + 1)]
    for s, t, c in zip(*[iter(STC)] * 3):
        T[c][s - 1:t] = [1] * (t - s + 1)

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

main()

Submission status: Accepted

Solution code:
N, C, *STC = map(int, open(0).read().split())

T = [[0] * 10 ** 5 for _ in range(C + 1)]
for s, t, c in zip(*[iter(STC)] * 3):
    T[c][s - 1:t] = [1] * (t - s + 1)

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

Submission status: Accepted

Solution code:
#!/usr/bin/env PyPy3
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
mod=10**9+7

def main():
    N,C=MI()
    T=10**5
    
    tc=[[0]*(T+1) for _ in range(C)]
    
    
    for i in range(N):
        s,t,c=MI()
        tc[c-1][s-1]+=1
        tc[c-1][t]-=1
        
    for c in range(C):
        for i in range(T):
            tc[c][i+1] +=tc[c][i]
            
    ans=0
    
    for i in range(T+1):
        temp=0
        for c in range(C):
            if tc[c][i]>0:
                temp+=1
        ans=max(ans,temp)
        
    print(ans)        
                    
        



main()

Submission status: Accepted

Solution code:
N,C = map(int,input().split())
stc = sorted([list(map(int,input().split())) for i in range(N)], key = lambda x:(x[2],x[0]))
cnow = 0
tnow = 0
end = max(i[1] for i in stc)
imos = [0 for i in range(end+2)]
for s,t,c in stc:
    if cnow == c and tnow == s:
        imos[s]+=1
    else:
        imos[s-1] += 1
    imos[t] -=1
    cnow = c
    tnow = t
for i in range(end):
    imos[i+1] += imos[i]
print(max(imos))

Submission status: Accepted

Solution code:
#14:29
n,cn = map(int,input().split())
event = []
for _ in range(n):
  s,t,c = map(int,input().split())
  event.append([s-1,1,c-1])
  event.append([t  ,0,c-1])
event.sort()
can = []
now = 0
chan = [0 for _ in range(cn)]
for x in event:
  u,i,c = x
  if chan[c] == 0 and i == 1:
    chan[c] += 1
    now += 1
    can.append(now)
  elif chan[c] == 1 and i == 1:
    chan[c] += 1
  elif chan[c] == 1 and i == 0:
    chan[c] -= 1
    now -= 1
  elif chan[c] == 2 and i == 0:
    chan[c] -= 1
  else:
    print(fuck)
  #print(chan,u)
print(max(can))

Submission status: Accepted

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

# 同チャンネルの連続する放送を一つにまとめる
stc.sort(key=lambda x: (x[2], x[0]))
 
imos = [0] * (10**5 + 1)

curr_c = 0
curr_t = 0
for s, t, c in stc:
  if curr_c == c and curr_t == s:
    imos[s] += 1
  else:
    imos[s-1] += 1
  imos[t] -= 1
  curr_t = t
  curr_c = c
  
rui = [0] * (10**5 + 1)

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

Submission status: Accepted

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

# 同チャンネルの連続する放送を一つにまとめる
stc.sort(key=lambda x: (x[2], x[0]))
 
imos = [0] * (10**5 + 1)

curr_c = 0
cuur_t = 0
for s, t, c in stc:
  if curr_c == c and curr_t == s:
    imos[s] += 1
  else:
    imos[s-1] += 1
  imos[t] -= 1
  curr_t = t
  curr_c = c
  
rui = [0] * (10**5 + 1)

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

Submission status: Accepted

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

rec = []

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

L.sort(key=lambda x: x[0])

for i in range(n):
    s = L[i][0]
    t = L[i][1]
    c = L[i][2]
    if i == 0:
        rec.append([c, t])
    else:
        for j in range(len(rec)):
            if rec[j][0] == c and rec[j][1] <= s:
                rec[j][1] = t
                break
        else:
            rec.sort(key=lambda x: x[1])
            for k in range(len(rec)):
                if rec[k][1]+1 <= s:
                    rec[k][0] = c
                    rec[k][1] = t
                    break
            else:
                rec.append([c, t])
#print(rec)
print(len(rec))