結果
問題 | No.2421 entersys? |
ユーザー | sepa38 |
提出日時 | 2023-07-20 12:07:06 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,430 ms / 3,000 ms |
コード長 | 2,643 bytes |
コンパイル時間 | 164 ms |
コンパイル使用メモリ | 82,444 KB |
実行使用メモリ | 270,904 KB |
最終ジャッジ日時 | 2024-09-20 11:05:55 |
合計ジャッジ時間 | 28,043 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 42 ms
52,608 KB |
testcase_01 | AC | 65 ms
67,968 KB |
testcase_02 | AC | 89 ms
76,856 KB |
testcase_03 | AC | 49 ms
62,080 KB |
testcase_04 | AC | 58 ms
66,560 KB |
testcase_05 | AC | 90 ms
76,864 KB |
testcase_06 | AC | 83 ms
76,416 KB |
testcase_07 | AC | 85 ms
77,056 KB |
testcase_08 | AC | 89 ms
76,800 KB |
testcase_09 | AC | 110 ms
77,440 KB |
testcase_10 | AC | 82 ms
76,416 KB |
testcase_11 | AC | 1,366 ms
263,848 KB |
testcase_12 | AC | 1,365 ms
264,308 KB |
testcase_13 | AC | 1,364 ms
264,488 KB |
testcase_14 | AC | 1,391 ms
264,612 KB |
testcase_15 | AC | 1,430 ms
264,052 KB |
testcase_16 | AC | 1,393 ms
266,380 KB |
testcase_17 | AC | 1,366 ms
264,232 KB |
testcase_18 | AC | 1,354 ms
264,220 KB |
testcase_19 | AC | 1,358 ms
264,756 KB |
testcase_20 | AC | 1,331 ms
263,732 KB |
testcase_21 | AC | 1,398 ms
242,932 KB |
testcase_22 | AC | 871 ms
261,748 KB |
testcase_23 | AC | 1,205 ms
269,632 KB |
testcase_24 | AC | 1,194 ms
270,904 KB |
testcase_25 | AC | 1,177 ms
269,924 KB |
testcase_26 | AC | 1,158 ms
269,908 KB |
testcase_27 | AC | 1,154 ms
269,848 KB |
testcase_28 | AC | 1,175 ms
270,516 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)] nc = set() 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]) nc.add(qr[i][1]) 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(): if s not in nc: continue 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) if s not in nc: continue 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) if s not in nc: continue sd[s].renew(idx2[s][l], 1) sd[s].renew(idx2[s][r]+1, -1)