結果

問題 No.1890 Many Sequences Sum Queries
ユーザー ああいいああいい
提出日時 2022-04-05 16:51:23
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 714 bytes
コンパイル時間 200 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 77,312 KB
最終ジャッジ日時 2024-05-05 03:04:31
合計ジャッジ時間 4,503 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 AC 36 ms
51,840 KB
testcase_04 AC 36 ms
51,968 KB
testcase_05 WA -
testcase_06 AC 36 ms
52,096 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 RE -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 WA -
testcase_19 WA -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 AC 36 ms
51,968 KB
testcase_24 RE -
testcase_25 AC 36 ms
51,968 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N,Q = map(int,input().split())
A = list(map(int,input().split()))

Sum = [0] * (N+1)
l = [0] * (N + 1)
for i in range(N):
    Sum[i+1] = Sum[i] + A[i] * (A[i] + 1) // 2
    l[i+1] = l[i] + A[i]

def calc(x):
    if Sum[-1] < x:
        return -1
    end = N
    start = -1
    while end - start > 1:
        mid = end + start >> 1
        if Sum[mid] >= x:
            end = mid
        else:
            start = mid
    ans = l[start]
    x -= Sum[start]
    end = A[end]
    start = 0
    while end - start > 1:
        mid = end + start >> 1
        if mid * (mid + 1) // 2 >= x:
            end = mid
        else:
            start = mid
    return ans + end

for _ in range(Q):
    print(calc(int(input())))
0