結果
問題 | No.2223 Merged Med |
ユーザー | Shirotsume |
提出日時 | 2023-02-17 17:23:30 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 6,452 ms / 7,000 ms |
コード長 | 6,732 bytes |
コンパイル時間 | 377 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 283,692 KB |
最終ジャッジ日時 | 2024-07-19 12:04:21 |
合計ジャッジ時間 | 95,788 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 43 ms
56,064 KB |
testcase_01 | AC | 42 ms
56,448 KB |
testcase_02 | AC | 60 ms
67,712 KB |
testcase_03 | AC | 43 ms
56,448 KB |
testcase_04 | AC | 50 ms
63,232 KB |
testcase_05 | AC | 78 ms
76,288 KB |
testcase_06 | AC | 44 ms
57,344 KB |
testcase_07 | AC | 81 ms
76,288 KB |
testcase_08 | AC | 76 ms
76,288 KB |
testcase_09 | AC | 80 ms
76,288 KB |
testcase_10 | AC | 83 ms
76,288 KB |
testcase_11 | AC | 43 ms
56,704 KB |
testcase_12 | AC | 60 ms
69,120 KB |
testcase_13 | AC | 2,315 ms
175,384 KB |
testcase_14 | AC | 1,372 ms
102,752 KB |
testcase_15 | AC | 3,720 ms
280,396 KB |
testcase_16 | AC | 5,234 ms
283,692 KB |
testcase_17 | AC | 2,654 ms
271,104 KB |
testcase_18 | AC | 1,288 ms
99,996 KB |
testcase_19 | AC | 2,224 ms
163,080 KB |
testcase_20 | AC | 6,059 ms
272,432 KB |
testcase_21 | AC | 6,085 ms
281,948 KB |
testcase_22 | AC | 6,115 ms
269,844 KB |
testcase_23 | AC | 5,918 ms
278,316 KB |
testcase_24 | AC | 5,973 ms
270,316 KB |
testcase_25 | AC | 5,958 ms
271,356 KB |
testcase_26 | AC | 5,882 ms
271,220 KB |
testcase_27 | AC | 6,039 ms
270,008 KB |
testcase_28 | AC | 6,434 ms
270,668 KB |
testcase_29 | AC | 6,452 ms
283,184 KB |
testcase_30 | AC | 1,821 ms
276,544 KB |
testcase_31 | AC | 1,821 ms
276,936 KB |
testcase_32 | AC | 100 ms
82,816 KB |
testcase_33 | AC | 4,878 ms
279,076 KB |
testcase_34 | AC | 2,262 ms
265,580 KB |
testcase_35 | AC | 2,267 ms
266,052 KB |
ソースコード
import sys from collections import deque, Counter import time input = lambda: sys.stdin.readline().rstrip() ii = lambda: int(input()) mi = lambda: map(int, input().split()) li = lambda: list(mi()) inf = 2 ** 32 - 1 mod = 998244353 class lazy_segtree(): def update(self,k):self.d[k]=self.op(self.d[2*k],self.d[2*k+1]) def all_apply(self,k,f): self.d[k]=self.mapping(f,self.d[k]) if (k<self.size):self.lz[k]=self.composition(f,self.lz[k]) def push(self,k): self.all_apply(2*k,self.lz[k]) self.all_apply(2*k+1,self.lz[k]) self.lz[k]=self.identity def __init__(self,V,OP,E,MAPPING,COMPOSITION,ID): self.n=len(V) self.log=(self.n-1).bit_length() self.size=1<<self.log self.d=[E for i in range(2*self.size)] self.lz=[ID for i in range(self.size)] self.e=E self.op=OP self.mapping=MAPPING self.composition=COMPOSITION self.identity=ID for i in range(self.n):self.d[self.size+i]=V[i] for i in range(self.size-1,0,-1):self.update(i) def set(self,p,x): assert 0<=p and p<self.n p+=self.size for i in range(self.log,0,-1):self.push(p>>i) self.d[p]=x for i in range(1,self.log+1):self.update(p>>i) def get(self,p): assert 0<=p and p<self.n p+=self.size for i in range(self.log,0,-1):self.push(p>>i) return self.d[p] def prod(self,l,r): assert 0<=l and l<=r and r<=self.n if l==r:return self.e l+=self.size r+=self.size for i in range(self.log,0,-1): if (((l>>i)<<i)!=l):self.push(l>>i) if (((r>>i)<<i)!=r):self.push(r>>i) sml,smr=self.e,self.e while(l<r): if l&1: sml=self.op(sml,self.d[l]) l+=1 if r&1: r-=1 smr=self.op(self.d[r],smr) l>>=1 r>>=1 return self.op(sml,smr) def all_prod(self):return self.d[1] def apply_point(self,p,f): assert 0<=p and p<self.n p+=self.size for i in range(self.log,0,-1):self.push(p>>i) self.d[p]=self.mapping(f,self.d[p]) for i in range(1,self.log+1):self.update(p>>i) def apply(self,l,r,f): assert 0<=l and l<=r and r<=self.n if l==r:return l+=self.size r+=self.size for i in range(self.log,0,-1): if (((l>>i)<<i)!=l):self.push(l>>i) if (((r>>i)<<i)!=r):self.push((r-1)>>i) l2,r2=l,r while(l<r): if (l&1): self.all_apply(l,f) l+=1 if (r&1): r-=1 self.all_apply(r,f) l>>=1 r>>=1 l,r=l2,r2 for i in range(1,self.log+1): if (((l>>i)<<i)!=l):self.update(l>>i) if (((r>>i)<<i)!=r):self.update((r-1)>>i) def max_right(self,l,g): assert 0<=l and l<=self.n assert g(self.e) if l==self.n:return self.n l+=self.size for i in range(self.log,0,-1):self.push(l>>i) sm=self.e while(1): while(l%2==0):l>>=1 if not(g(self.op(sm,self.d[l]))): while(l<self.size): self.push(l) l=(2*l) if (g(self.op(sm,self.d[l]))): sm=self.op(sm,self.d[l]) l+=1 return l-self.size sm=self.op(sm,self.d[l]) l+=1 if (l&-l)==l:break return self.n def min_left(self,r,g): assert (0<=r and r<=self.n) assert g(self.e) if r==0:return 0 r+=self.size for i in range(self.log,0,-1):self.push((r-1)>>i) sm=self.e while(1): r-=1 while(r>1 and (r%2)):r>>=1 if not(g(self.op(self.d[r],sm))): while(r<self.size): self.push(r) r=(2*r+1) if g(self.op(self.d[r],sm)): sm=self.op(self.d[r],sm) r-=1 return r+1-self.size sm=self.op(self.d[r],sm) if (r&-r)==r:break return 0 def __str__(self): return str([self.get(i) for i in range(self.n)]) class segtree(): n=1 size=1 log=2 d=[0] op=None e=10**15 def __init__(self,V,OP,E): self.n=len(V) self.op=OP self.e=E self.log=(self.n-1).bit_length() self.size=1<<self.log self.d=[E for i in range(2*self.size)] for i in range(self.n): self.d[self.size+i]=V[i] for i in range(self.size-1,0,-1): self.update(i) def set(self,p,x): assert 0<=p and p<self.n p+=self.size self.d[p]=x for i in range(1,self.log+1): self.update(p>>i) def get(self,p): assert 0<=p and p<self.n return self.d[p+self.size] def __setitem__(self, p, x): self.set(p, x) def __getitem__(self, p): if isinstance(p, int): return self.get(p) else: return self.prod(p.start, p.stop) def prod(self,l,r): assert 0<=l and l<=r and r<=self.n sml=self.e smr=self.e l+=self.size r+=self.size while(l<r): if (l&1): sml=self.op(sml,self.d[l]) l+=1 if (r&1): smr=self.op(self.d[r-1],smr) r-=1 l>>=1 r>>=1 return self.op(sml,smr) def all_prod(self): return self.d[1] def update(self,k): self.d[k]=self.op(self.d[2*k],self.d[2*k+1]) def __str__(self): return str([self.get(i) for i in range(self.n)]) n, q = mi() a = li() LR = [li() for _ in range(q)] ok = [n - 1] * q ng = [-1] * q soa = list(range(n)) soa.sort(key = lambda x: a[x]) def op(s, t): return (max(s[0], s[3] + t[0]), max(t[1], s[1] + t[3]),max(s[2], t[2], s[1] + t[0]), s[3] + t[3]) for _ in range(16): mididx = [[] for _ in range(n)] for i in range(q): if ok[i] - ng[i] > 1: mid = (ok[i] + ng[i]) // 2 mididx[mid].append(i) S = segtree([(1, 1, 1, 1) for _ in range(n)], op, (0,0,0,0)) for x, i in enumerate(soa): S.set(i, (-1, -1, -1, -1)) for v in mididx[x]: P = S.prod(LR[v][0] - 1, LR[v][1]) if P[3] < 0 or P[3] - P[2] + 1 < 0: ok[v] = x else: ng[v] = x soa = sorted(a) for i, v in enumerate(ok): print(soa[v])