結果

問題 No.919 You Are A Project Manager
ユーザー mkawa2mkawa2
提出日時 2022-04-06 23:24:22
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 300 ms / 3,000 ms
コード長 3,254 bytes
コンパイル時間 1,278 ms
コンパイル使用メモリ 87,136 KB
実行使用メモリ 81,636 KB
最終ジャッジ日時 2023-08-18 14:59:20
合計ジャッジ時間 15,300 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 181 ms
78,876 KB
testcase_01 AC 74 ms
71,428 KB
testcase_02 AC 74 ms
71,280 KB
testcase_03 AC 74 ms
71,100 KB
testcase_04 AC 139 ms
78,992 KB
testcase_05 AC 139 ms
78,928 KB
testcase_06 AC 105 ms
78,052 KB
testcase_07 AC 186 ms
79,380 KB
testcase_08 AC 136 ms
78,492 KB
testcase_09 AC 135 ms
78,456 KB
testcase_10 AC 152 ms
78,872 KB
testcase_11 AC 146 ms
78,224 KB
testcase_12 AC 87 ms
75,988 KB
testcase_13 AC 163 ms
78,880 KB
testcase_14 AC 92 ms
76,328 KB
testcase_15 AC 112 ms
78,044 KB
testcase_16 AC 175 ms
79,580 KB
testcase_17 AC 192 ms
79,304 KB
testcase_18 AC 188 ms
79,644 KB
testcase_19 AC 192 ms
79,532 KB
testcase_20 AC 275 ms
81,184 KB
testcase_21 AC 187 ms
79,268 KB
testcase_22 AC 212 ms
79,924 KB
testcase_23 AC 201 ms
79,752 KB
testcase_24 AC 206 ms
79,928 KB
testcase_25 AC 199 ms
79,940 KB
testcase_26 AC 282 ms
81,636 KB
testcase_27 AC 290 ms
81,224 KB
testcase_28 AC 294 ms
81,052 KB
testcase_29 AC 192 ms
79,580 KB
testcase_30 AC 196 ms
79,644 KB
testcase_31 AC 190 ms
79,012 KB
testcase_32 AC 196 ms
79,388 KB
testcase_33 AC 219 ms
80,756 KB
testcase_34 AC 215 ms
79,744 KB
testcase_35 AC 294 ms
80,780 KB
testcase_36 AC 295 ms
80,828 KB
testcase_37 AC 295 ms
80,768 KB
testcase_38 AC 300 ms
81,600 KB
testcase_39 AC 92 ms
75,944 KB
testcase_40 AC 117 ms
78,012 KB
testcase_41 AC 102 ms
76,660 KB
testcase_42 AC 116 ms
77,816 KB
testcase_43 AC 116 ms
77,960 KB
testcase_44 AC 147 ms
78,232 KB
testcase_45 AC 117 ms
78,120 KB
testcase_46 AC 127 ms
78,252 KB
testcase_47 AC 209 ms
79,652 KB
testcase_48 AC 211 ms
79,584 KB
testcase_49 AC 221 ms
79,828 KB
testcase_50 AC 217 ms
80,048 KB
testcase_51 AC 194 ms
79,700 KB
testcase_52 AC 211 ms
80,048 KB
testcase_53 AC 195 ms
79,496 KB
testcase_54 AC 121 ms
78,236 KB
testcase_55 AC 77 ms
71,352 KB
testcase_56 AC 79 ms
71,168 KB
testcase_57 AC 78 ms
71,436 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

# sys.setrecursionlimit(200005)
int1 = lambda x: int(x)-1
pDB = lambda *x: print(*x, end="\n", file=sys.stderr)
p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr)
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()
dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
inf = (1 << 63)-1
# inf = (1 << 31)-1
# md = 10**9+7
md = 998244353

class WaveletMatrix:
    def __init__(self, aa):
        self.dec = sorted(set(aa))
        self.enc = {a: i for i, a in enumerate(self.dec)}
        aa = [self.enc[a] for a in aa]
        self.log = len(self.dec).bit_length()
        self.n = len(aa)
        self.bb = [[0] for _ in range(self.log)]
        for i in range(self.log)[::-1]:
            naa = [[], []]
            for a in aa:
                d = a >> i & 1
                naa[d].append(a)
                self.bb[i].append(self.bb[i][-1]+d)
            aa = naa[0]+naa[1]
        self.fi = {}
        for i in range(self.n)[::-1]: self.fi[aa[i]] = i
        self.aa = aa

    def _move(self, i, idx, d):
        if d: return self.n-self.bb[i][-1]+self.bb[i][idx]
        return idx-self.bb[i][idx]

    def __getitem__(self, idx):
        res = 0
        for i in range(self.log)[::-1]:
            d = self.bb[i][idx+1]-self.bb[i][idx]
            res |= d << i
            idx = self._move(i, idx, d)
        return self.dec[res]

    # count a in [0,r)
    def rank(self, a, r):
        a = self.enc[a]
        if a not in self.fi: return 0
        for i in range(self.log)[::-1]: r = self._move(i, r, a >> i & 1)
        return r-self.fi[a]

    # index of ith(0-indexed) a
    def select(self, a, ith):
        a = self.enc[a]
        if a not in self.fi: return -1
        idx = self.fi[a]+ith
        for i in range(self.log-1):
            d = a >> i & 1
            l, r = -1, self.n-1
            while l+1 < r:
                m = (l+r)//2
                nxt = self.n-self.bb[i][-1]+self.bb[i][m+1] if d else m+1-self.bb[i][m+1]
                if nxt < idx+1: l = m
                else: r = m
            idx = r
        return idx

    # ith value in sorted [l,r)
    def quantile(self, l, r, ith):
        for i in range(self.log)[::-1]:
            c0 = r-l-(self.bb[i][r]-self.bb[i][l])
            if c0 > ith:
                l, r = self._move(i, l, 0), self._move(i, r, 0)
            else:
                l, r = self._move(i, l, 1), self._move(i, r, 1)
                ith -= c0
        return self.dec[self.aa[l+ith]]

n = II()
aa = LI()

wm = WaveletMatrix(aa)

ans = -inf
for k in range(1, n+1):
    m = (k-1)//2
    st = [0]
    t = 0
    for r in range(n, k-1, -k):
        t += wm.quantile(r-k, r, m)*k
        st.append(max(t, st[-1]))
    ans = max(ans, st[-1])
    s = 0
    for l in range(0, n-k+1, k):
        s += wm.quantile(l, l+k, m)*k
        st.pop()
        ans = max(ans, s+st[-1])
        # pDB(k, ans, st)

print(ans)
0