結果

問題 No.2697 Range LIS Query
ユーザー hato336hato336
提出日時 2024-03-22 22:18:30
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 6,596 bytes
コンパイル時間 601 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 284,288 KB
最終ジャッジ日時 2024-03-22 22:20:01
合計ジャッジ時間 83,384 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 142 ms
88,060 KB
testcase_01 AC 142 ms
88,052 KB
testcase_02 AC 155 ms
88,828 KB
testcase_03 AC 1,000 ms
108,360 KB
testcase_04 AC 976 ms
107,084 KB
testcase_05 AC 1,009 ms
108,648 KB
testcase_06 AC 9,582 ms
276,224 KB
testcase_07 AC 9,345 ms
274,908 KB
testcase_08 AC 9,584 ms
276,996 KB
testcase_09 AC 5,141 ms
169,644 KB
testcase_10 AC 5,261 ms
169,008 KB
testcase_11 AC 5,025 ms
169,648 KB
testcase_12 AC 6,221 ms
277,036 KB
testcase_13 AC 7,174 ms
277,584 KB
testcase_14 AC 9,229 ms
277,400 KB
testcase_15 TLE -
testcase_16 -- -
testcase_17 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import collections,sys,math,functools,operator,itertools,bisect,heapq,decimal,string,time,random
#sys.setrecursionlimit(10**9)
#sys.set_int_max_str_digits(0)
input = sys.stdin.readline
#https://github.com/shakayami/ACL-for-python/blob/master/lazysegtree.py
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
mod = 998244353
#区間加算・区間最小値取得 lst = lazy_segtree([],min,10**18,operator.add,operator.add,0)
#区間加算・区間最大値取得 lst = lazy_segtree([],max,-10**18,operator.add,operator.add,0)
#区間加算・区間和取得 lst = lazy_segtree([(alist[i],1) for i in range(n)],lambda x,y:((x[0]+y[0])%mod,x[1]+y[1]),(0,0),lambda x,y:((y[0]+x*y[1])%mod,y[1]),operator.add,0)
#区間変更・区間最小値取得 lst = lazy_segtree([],min,10**18,lambda x,y:y if x == 10**18 else x,lambda x,y:y if x == 10**18 else x,10**18)
#区間変更・区間最大値取得 lst = lazy_segtree([],max,-10**18,lambda x,y:y if x == -10**18 else x,lambda x,y:y if x == -10**18 else x,-10**18)
#区間変更・区間和取得 lst = lazy_segtree([(alist[i],1) for i in range(n)],lambda x,y:((x[0]+y[0])%mod,x[1]+y[1]),(0,0),lambda x,y:(y[1]*x,y[1]) if x != 10**18 else y,lambda x,y:y if x == 10**18 else x,10**18)

def mapping(x,y):
    if x == 10**18:
        return y
    z = [0 for i in range(17)]
    z[-1] = y[-1]
    x -= 1
    z[x*4+x] = z[-1]
    return tuple(z)

#yが作用してからxが作用する
def composition(x,y):
    return
def op(x,y):
    z = [max(x[i],y[i]) for i in range(16)]
    z.append(x[-1]+y[-1])
    #print(x,y,z)
    for i in range(4):
        for j in range(i,4):
            for k in range(j,4):
                for l in range(k,4):
                    if x[i*4+j] == 0 or y[k*4+l] == 0:
                        continue
                    z[i*4+l] = max(z[i*4+l],x[i*4+j] + y[k*4+l])
    #z[-1] = x[-1] + y[-1]
    #print(x,y,z)
    return tuple(z)

#n = int(input())
#alist = list(map(int,input().split()))
#alist = []
#s = input()
n = int(input())
a = list(map(int,input().split()))
v = []
for i in range(n):
    z = [0 for j in range(17)]
    z[-1] = 1
    a[i] -= 1
    z[a[i]*4+a[i]] = 1
    v.append(tuple(z))
e = tuple([0 for i in range(17)])
st = lazy_segtree(v,op,e,mapping,lambda x,y:y if x == 10**18 else x,10**18)
q = int(input())
#print(st.prod(0,2))
for i in range(q):
    query = list(map(int,input().split()))
    if query[0] == 1:
        t,l,r = query
        l -= 1
        r -= 1
        print(max(st.prod(l,r+1)[:16]))
    else:
        t,l,r,x = query
        l -= 1
        r -= 1
        st.apply(l,r+1,x)
0