結果

問題 No.1084 積の積
ユーザー kohei2019kohei2019
提出日時 2022-08-02 01:38:08
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,071 ms / 2,000 ms
コード長 3,504 bytes
コンパイル時間 325 ms
コンパイル使用メモリ 86,960 KB
実行使用メモリ 98,924 KB
最終ジャッジ日時 2023-09-29 23:14:18
合計ジャッジ時間 12,953 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,184 KB
testcase_01 AC 71 ms
71,184 KB
testcase_02 AC 76 ms
71,136 KB
testcase_03 AC 73 ms
71,216 KB
testcase_04 AC 1,022 ms
97,024 KB
testcase_05 AC 91 ms
89,876 KB
testcase_06 AC 1,071 ms
97,360 KB
testcase_07 AC 74 ms
71,268 KB
testcase_08 AC 75 ms
71,224 KB
testcase_09 AC 97 ms
91,788 KB
testcase_10 AC 77 ms
71,052 KB
testcase_11 AC 165 ms
79,104 KB
testcase_12 AC 247 ms
86,128 KB
testcase_13 AC 371 ms
97,008 KB
testcase_14 AC 221 ms
82,596 KB
testcase_15 AC 211 ms
82,724 KB
testcase_16 AC 400 ms
98,924 KB
testcase_17 AC 234 ms
85,180 KB
testcase_18 AC 296 ms
90,452 KB
testcase_19 AC 364 ms
96,984 KB
testcase_20 AC 191 ms
80,604 KB
testcase_21 AC 217 ms
82,576 KB
testcase_22 AC 204 ms
81,268 KB
testcase_23 AC 267 ms
87,740 KB
testcase_24 AC 258 ms
86,628 KB
testcase_25 AC 369 ms
96,884 KB
testcase_26 AC 486 ms
97,656 KB
testcase_27 AC 472 ms
97,432 KB
testcase_28 AC 478 ms
97,404 KB
testcase_29 AC 459 ms
97,520 KB
testcase_30 AC 490 ms
97,516 KB
testcase_31 AC 466 ms
97,440 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class LazySegTree():
    #区間和のセグメント木、要素ls
    def __init__(self,ls):
        self.default = 0
        self.func = (lambda x, y: x + y)
        self.N = len(ls)
        self.K = (self.N-1).bit_length()
        self.N0 = 1 << self.K 
        self.dat = [self.default]*(2**(self.K+1))
        self.lazy = [0]*(2**(self.K+1)) #遅延評価
        for i in range(self.N): #葉の構築
            self.dat[2**self.K+i] = ls[i]
        self.build()

    def build(self):
        for j in range(self.N0-1,0,-1):
            self.dat[j] = self.func(self.dat[j<<1],self.dat[j<<1|1]) #親が持つ条件

    def leafvalue(self,x): #x番目の値を出力
        return self.query(x,x+1)

    def update_add(self,x,y): #x番目にyを足す
        return self.updatel_add(x,x+1,y)

    def gindex(self,l, r): #伝播するインデックス列挙
        L = l + self.N0; R = r + self.N0
        lm = (L // (L & -L)) >> 1
        rm = (R // (R & -R)) >> 1
        lsindex = []
        while L < R:
            if R <= rm:
                lsindex.append(R)
            if L <= lm:
                lsindex.append(L)
            L >>= 1; R >>= 1
        while L:
            lsindex.append(L)
            L >>= 1
        return lsindex

    def propagates(self,ids):
        for i in reversed(ids):
            v = self.lazy[i]
            if not v:
                continue
            self.lazy[i<<1] += v//2; self.lazy[i<<1|1] += v//2
            self.dat[i<<1] += v//2; self.dat[i<<1|1] += v//2
            self.lazy[i] = 0

    def updatel_add(self,l, r, x):#区間にyを足す
        self.propagates(self.gindex(l, r))
        L = self.N0 + l
        R = self.N0 + r
        ii = 0
        while L < R:
            if L & 1:
                self.lazy[L] += x*(2**ii)
                self.dat[L] += x*(2**ii)
                L += 1
            if R & 1:
                R -= 1
                self.lazy[R] += x*(2**ii)
                self.dat[R] += x*(2**ii)
            L >>= 1
            R >>= 1
            ii += 1
        for i in self.gindex(l, r):
            self.dat[i] = self.func(self.dat[i<<1],self.dat[i<<1|1])+self.lazy[i]

    def query(self,l, r):
        self.propagates(self.gindex(l, r))
        L = self.N0 + l
        R = self.N0 + r
        vL = self.default
        vR = self.default
        while L < R:
            if L & 1:
                vL = self.func(vL,self.dat[L])
                L += 1
            if R & 1:
                R -= 1
                vR = self.func(self.dat[R],vR)
            L >>= 1
            R >>= 1
        return self.func(vL,vR)

def modPow(a,n,mod):#繰り返し二乗法 a**n % mod
    if n==0:
        return 1
    if n==1:
        return a%mod
    if n & 1:
        return (a*modPow(a,n-1,mod)) % mod
    t = modPow(a,n>>1,mod)
    return (t*t)%mod

N = int(input())
lsA = list(map(int,input().split()))+[1]
mod = 10**9+7
if 0 in lsA:
    print(0)
    exit()
rh = [0]*(N)
l = 0
r = 0
val = 1
while l < N:
    while val < 10**9 and r < N:
        val *= lsA[r]
        if val >= 10**9:
            val //= lsA[r]
            break
        if r == N:
            break
        r += 1
    rh[l] = r
    val //= lsA[l] 
    l += 1
LSG = LazySegTree([0]*(N+1))
for i in range(N):
    LSG.update_add(i, rh[i]-i)
    LSG.updatel_add(i+1, rh[i]+1, -1)
ll = [LSG.leafvalue(i) for i in range(N+1)]
for i in range(1,N+1):
    ll[i] += ll[i-1]
ans = 1
for i in range(N):
    ans *= modPow(lsA[i],ll[i],mod)
    ans %= mod
print(ans)
0