結果
問題 | No.2421 entersys? |
ユーザー | sepa38 |
提出日時 | 2023-07-20 11:56:47 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 2,063 ms / 3,000 ms |
コード長 | 2,514 bytes |
コンパイル時間 | 225 ms |
コンパイル使用メモリ | 82,560 KB |
実行使用メモリ | 281,004 KB |
最終ジャッジ日時 | 2024-09-20 11:15:23 |
合計ジャッジ時間 | 33,843 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 43 ms
52,736 KB |
testcase_01 | AC | 77 ms
70,016 KB |
testcase_02 | AC | 129 ms
77,696 KB |
testcase_03 | AC | 58 ms
62,208 KB |
testcase_04 | AC | 77 ms
70,656 KB |
testcase_05 | AC | 112 ms
77,312 KB |
testcase_06 | AC | 109 ms
77,440 KB |
testcase_07 | AC | 114 ms
77,696 KB |
testcase_08 | AC | 117 ms
77,696 KB |
testcase_09 | AC | 142 ms
78,592 KB |
testcase_10 | AC | 107 ms
77,312 KB |
testcase_11 | AC | 1,716 ms
263,140 KB |
testcase_12 | AC | 1,711 ms
264,216 KB |
testcase_13 | AC | 1,647 ms
264,224 KB |
testcase_14 | AC | 1,644 ms
264,300 KB |
testcase_15 | AC | 1,635 ms
263,936 KB |
testcase_16 | AC | 1,720 ms
263,348 KB |
testcase_17 | AC | 1,716 ms
263,892 KB |
testcase_18 | AC | 1,852 ms
263,752 KB |
testcase_19 | AC | 1,713 ms
264,256 KB |
testcase_20 | AC | 1,750 ms
263,416 KB |
testcase_21 | AC | 1,606 ms
253,140 KB |
testcase_22 | AC | 1,345 ms
261,896 KB |
testcase_23 | AC | 2,035 ms
281,004 KB |
testcase_24 | AC | 2,063 ms
280,884 KB |
testcase_25 | AC | 2,045 ms
280,604 KB |
testcase_26 | AC | 1,304 ms
270,064 KB |
testcase_27 | AC | 1,293 ms
269,932 KB |
testcase_28 | AC | 1,337 ms
270,620 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)] for i in range(q): qr[i][0] = int(qr[i][0]) if qr[i][0] == 1: 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: 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]) 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)