結果

問題 No.489 株に挑戦
ユーザー convexineqconvexineq
提出日時 2021-02-09 03:59:26
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 239 ms / 1,000 ms
コード長 1,630 bytes
コンパイル時間 280 ms
コンパイル使用メモリ 87,176 KB
実行使用メモリ 98,764 KB
最終ジャッジ日時 2023-09-20 12:58:54
合計ジャッジ時間 7,409 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 174 ms
93,872 KB
testcase_01 AC 195 ms
87,224 KB
testcase_02 AC 73 ms
71,284 KB
testcase_03 AC 73 ms
71,488 KB
testcase_04 AC 74 ms
71,264 KB
testcase_05 AC 74 ms
71,284 KB
testcase_06 AC 73 ms
71,140 KB
testcase_07 AC 73 ms
71,260 KB
testcase_08 AC 73 ms
71,188 KB
testcase_09 AC 73 ms
71,364 KB
testcase_10 AC 75 ms
71,376 KB
testcase_11 AC 74 ms
71,192 KB
testcase_12 AC 73 ms
71,200 KB
testcase_13 AC 74 ms
71,284 KB
testcase_14 AC 74 ms
71,324 KB
testcase_15 AC 112 ms
77,660 KB
testcase_16 AC 232 ms
95,476 KB
testcase_17 AC 107 ms
77,592 KB
testcase_18 AC 189 ms
86,720 KB
testcase_19 AC 187 ms
84,664 KB
testcase_20 AC 226 ms
96,008 KB
testcase_21 AC 179 ms
80,600 KB
testcase_22 AC 134 ms
78,460 KB
testcase_23 AC 152 ms
87,728 KB
testcase_24 AC 232 ms
98,764 KB
testcase_25 AC 74 ms
71,320 KB
testcase_26 AC 179 ms
98,520 KB
testcase_27 AC 178 ms
98,400 KB
testcase_28 AC 74 ms
70,980 KB
testcase_29 AC 73 ms
71,212 KB
testcase_30 AC 208 ms
98,516 KB
testcase_31 AC 166 ms
98,432 KB
testcase_32 AC 184 ms
87,604 KB
testcase_33 AC 239 ms
98,480 KB
testcase_34 AC 219 ms
95,564 KB
testcase_35 AC 173 ms
83,908 KB
testcase_36 AC 157 ms
78,232 KB
testcase_37 AC 201 ms
87,552 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class segment_tree:
    __slots__ = ["op_M", "e_M","N","N0","dat"]
    def __init__(self, N, operator_M, e_M):
        self.op_M = operator_M
        self.e_M = e_M
        self.N = N
        self.N0 = 1<<(N-1).bit_length()
        self.dat = [self.e_M]*(2*self.N0)
    
    # 長さNの配列 initial で初期化
    def build(self, initial):
        assert self.N == len(initial)
        self.dat[self.N0:self.N0+len(initial)] = initial[:]
        for k in range(self.N0-1,0,-1):
            self.dat[k] = self.op_M(self.dat[2*k], self.dat[2*k+1])

    # a_k の値を x に更新
    def update(self,k,x):
        k += self.N0
        self.dat[k] = x
        k >>= 1
        while k:
            self.dat[k] = self.op_M(self.dat[2*k], self.dat[2*k+1])
            k >>= 1

    # 区間[L,R]をopでまとめる
    def query(self,L,R):
        L += self.N0; R += self.N0 + 1 
        sl = sr = self.e_M
        while L < R:
            if R & 1:
                R -= 1
                sr = self.op_M(self.dat[R],sr)
            if L & 1:
                sl = self.op_M(sl,self.dat[L])
                L += 1
            L >>= 1; R >>= 1
        return self.op_M(sl,sr)

    def get(self, k): #k番目の値を取得。query[k,k]と同じ
        return self.dat[k+self.N0]

def f(i,j):
    if a[i] >= a[j]:
        return i
    else:
        return j

n,d,k,*a = map(int,open(0).read().split())
a += [0]
seg = segment_tree(n+1,f,n)
seg.build(range(n+1))
ma = 0
res = None
for i in range(n-1):
    v = seg.query(i+1,min(i+d,n-1))
    if ma < a[v]-a[i]:
        ma = a[v]-a[i]
        res = (i,v)

print(ma*k)
if ma: print(*res)
0