結果
問題 | No.2421 entersys? |
ユーザー | sepa38 |
提出日時 | 2023-07-20 11:59:58 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,717 ms / 3,000 ms |
コード長 | 2,563 bytes |
コンパイル時間 | 189 ms |
コンパイル使用メモリ | 82,460 KB |
実行使用メモリ | 280,764 KB |
最終ジャッジ日時 | 2024-09-20 11:13:38 |
合計ジャッジ時間 | 29,194 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 42 ms
53,256 KB |
testcase_01 | AC | 67 ms
70,336 KB |
testcase_02 | AC | 98 ms
77,580 KB |
testcase_03 | AC | 48 ms
62,420 KB |
testcase_04 | AC | 69 ms
72,412 KB |
testcase_05 | AC | 88 ms
77,452 KB |
testcase_06 | AC | 93 ms
77,488 KB |
testcase_07 | AC | 94 ms
77,288 KB |
testcase_08 | AC | 92 ms
77,580 KB |
testcase_09 | AC | 120 ms
78,252 KB |
testcase_10 | AC | 86 ms
77,012 KB |
testcase_11 | AC | 1,476 ms
263,132 KB |
testcase_12 | AC | 1,451 ms
264,028 KB |
testcase_13 | AC | 1,473 ms
263,928 KB |
testcase_14 | AC | 1,434 ms
264,300 KB |
testcase_15 | AC | 1,406 ms
263,700 KB |
testcase_16 | AC | 1,492 ms
267,804 KB |
testcase_17 | AC | 1,497 ms
264,128 KB |
testcase_18 | AC | 1,516 ms
263,924 KB |
testcase_19 | AC | 1,549 ms
263,876 KB |
testcase_20 | AC | 1,515 ms
262,996 KB |
testcase_21 | AC | 1,363 ms
252,816 KB |
testcase_22 | AC | 1,395 ms
261,708 KB |
testcase_23 | AC | 1,670 ms
280,740 KB |
testcase_24 | AC | 1,698 ms
280,764 KB |
testcase_25 | AC | 1,717 ms
280,608 KB |
testcase_26 | AC | 1,107 ms
270,056 KB |
testcase_27 | AC | 1,168 ms
269,880 KB |
testcase_28 | AC | 1,122 ms
270,212 KB |
ソースコード
class segt: def __init__(self, n, ele, calc): self.num = 2 ** (n - 1).bit_length() self.el = ele self.data = [ele] * (2 * self.num) self.calc = calc def update(self, idx, x): idx += self.num - 1 self.data[idx] = x while idx > 0: idx = (idx - 1) // 2 self.data[idx] = self.calc(self.data[2*idx+1], self.data[2*idx+2]) def renew(self, idx, x): self.update(idx, self.calc(self.get(idx), x)) def prod(self, left, right): l = left + self.num r = right + self.num res = self.el while l < r: if l % 2: res = self.calc(res, self.data[l-1]) l += 1 if r % 2: r -= 1 res = self.calc(res, self.data[r-1]) l //= 2 r //= 2 return res def get(self, idx): return self.data[idx+self.num-1] def add(x, y): return x + y def cc(a): b = sorted(a) d = dict() cnt = 0 for v in b: if v not in d: d[v] = cnt cnt += 1 res = [d[v] for v in a] return d n = int(input()) tm = [] ls = [list(map(str, input().split())) for _ in range(n)] d = dict() for i in range(n): s, l, r = ls[i] l, r = int(l), int(r) ls[i][1:] = [l, r] tm.append(l) tm.append(r) if s not in d: d[s] = [] d[s].append(l) d[s].append(r) q = int(input()) qr = [list(map(str, input().split())) for _ in range(q)] flg = 1 for i in range(q): qr[i][0] = int(qr[i][0]) if qr[i][0] == 1: flg = 0 qr[i][2] = int(qr[i][2]) tm.append(qr[i][2]) if qr[i][1] not in d: d[qr[i][1]] = [] d[qr[i][1]].append(qr[i][2]) elif qr[i][0] == 2: flg = 0 qr[i][1] = int(qr[i][1]) tm.append(qr[i][1]) else: qr[i][2] = int(qr[i][2]) qr[i][3] = int(qr[i][3]) tm.append(qr[i][2]) tm.append(qr[i][3]) if qr[i][1] not in d: d[qr[i][1]] = [] d[qr[i][1]].append(qr[i][2]) d[qr[i][1]].append(qr[i][3]) if flg: exit() tm = list(set(tm)) idx = cc(tm) st = segt(len(idx)+1, 0, add) idx2 = dict() sd = dict() for s in d.keys(): idx2[s] = cc(list(set(d[s]))) sd[s] = segt(len(idx2[s])+1, 0, add) for s, l, r in ls: st.renew(idx[l], 1) st.renew(idx[r]+1, -1) sd[s].renew(idx2[s][l], 1) sd[s].renew(idx2[s][r]+1, -1) for i in range(q): if qr[i][0] == 1: flg = sd[qr[i][1]].prod(0, idx2[qr[i][1]][qr[i][2]]+1) print("Yes" if flg else "No") elif qr[i][0] == 2: ans = st.prod(0, idx[qr[i][1]]+1) print(ans) else: s, l, r = qr[i][1:] st.renew(idx[l], 1) st.renew(idx[r]+1, -1) sd[s].renew(idx2[s][l], 1) sd[s].renew(idx2[s][r]+1, -1)