結果
問題 |
No.674 n連勤
|
ユーザー |
![]() |
提出日時 | 2020-08-09 19:05:50 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 525 ms / 2,000 ms |
コード長 | 1,723 bytes |
コンパイル時間 | 205 ms |
コンパイル使用メモリ | 12,928 KB |
実行使用メモリ | 23,740 KB |
最終ジャッジ日時 | 2024-10-05 08:42:57 |
合計ジャッジ時間 | 5,047 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 17 |
ソースコード
import sys sys.setrecursionlimit(10 ** 6) int1 = lambda x: int(x) - 1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.readline()) def MI(): return map(int, sys.stdin.readline().split()) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def SI(): return sys.stdin.readline()[:-1] class BitMax: def __init__(self, n): self.inf=10**9 self.n = n + 3 self.table = [-self.inf] * (self.n + 1) def update(self, i, x): i += 1 while i <= self.n: if x > self.table[i]: self.table[i] = x i += i & -i def max(self, i): i += 1 res = -self.inf while i > 0: if self.table[i] > res: res = self.table[i] i -= i & -i return res class BitMin: def __init__(self, n): self.inf=10**9 self.n = n + 3 self.table = [self.inf] * (self.n + 1) def update(self, i, x): i += 1 while i <= self.n: if x < self.table[i]: self.table[i] = x i += i & -i def min(self, i): i += 1 res = self.inf while i > 0: if self.table[i] < res: res = self.table[i] i -= i & -i return res d,q=MI() s=set() ab=[] for _ in range(q): a,b=MI() b+=1 ab.append((a,b)) s.add(a) s.add(b) dec=[a for a in sorted(s)] enc={a:i for i,a in enumerate(dec)} n=len(dec) ll=BitMin(n) rr=BitMax(n) ans=0 for a,b in ab: a=enc[a] b=enc[b] ll.update(n-b,a) rr.update(a,b) l=ll.min(n-a) r=rr.max(b) ll.update(n-r,l) rr.update(l,r) ans=max(ans,dec[r]-dec[l]) print(ans)