結果
問題 | No.2697 Range LIS Query |
ユーザー | mymelochan |
提出日時 | 2024-03-22 22:45:08 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 6,897 ms / 10,000 ms |
コード長 | 5,219 bytes |
コンパイル時間 | 326 ms |
コンパイル使用メモリ | 82,760 KB |
実行使用メモリ | 273,680 KB |
最終ジャッジ日時 | 2024-09-30 12:10:45 |
合計ジャッジ時間 | 60,474 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 42 ms
55,920 KB |
testcase_01 | AC | 43 ms
57,080 KB |
testcase_02 | AC | 62 ms
68,984 KB |
testcase_03 | AC | 532 ms
89,100 KB |
testcase_04 | AC | 548 ms
88,424 KB |
testcase_05 | AC | 544 ms
89,168 KB |
testcase_06 | AC | 5,428 ms
271,856 KB |
testcase_07 | AC | 5,631 ms
272,148 KB |
testcase_08 | AC | 5,244 ms
271,108 KB |
testcase_09 | AC | 2,883 ms
149,272 KB |
testcase_10 | AC | 3,154 ms
150,016 KB |
testcase_11 | AC | 3,252 ms
150,036 KB |
testcase_12 | AC | 3,828 ms
273,268 KB |
testcase_13 | AC | 3,706 ms
272,780 KB |
testcase_14 | AC | 4,908 ms
272,852 KB |
testcase_15 | AC | 6,040 ms
273,436 KB |
testcase_16 | AC | 6,897 ms
273,680 KB |
testcase_17 | AC | 6,201 ms
273,308 KB |
ソースコード
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 import sys from collections import defaultdict input = sys.stdin.readline inf = 1<<30 N = int(input()) A = list(map(int,input().split())) A = [a-1 for a in A] Q = int(input()) query = [list(map(int,input().split())) for _ in range(Q)] T = [0]*16 LT = len(T) R = {t:i for i,t in enumerate(T)} def operate(a,b): ret = [0]*(LT+1) ret[-1] = a[-1]+b[-1] for i in range(4): for j in range(i,4): for k in range(j,4): for m in range(k,4): ret[i*4+m] = max(ret[i*4+m],a[i*4+j]+b[k*4+m]) return ret def mapping(f,x): if f == -1: return x ret = [0]*(LT+1) ret[-1] = x[-1] ret[f*4+f] = ret[-1] return ret def composition(f,g): if f == -1: return g return f init = [[0]*(LT+1) for _ in range(N)] for i in range(N): init[i][A[i]*4+A[i]] = 1 init[i][-1] = 1 sgt = lazy_segtree( init, operate, [0 for _ in range(LT+1)], mapping, composition, -1 ) for q in query: if q[0] == 1: l,r = q[1:] print(max(sgt.prod(l-1,r)[:-1])) else: l,r,x = q[1:] sgt.apply(l-1,r,x-1)