結果

問題 No.1890 Many Sequences Sum Queries
ユーザー roarisroaris
提出日時 2022-04-05 18:34:02
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 121 ms / 2,000 ms
コード長 558 bytes
コンパイル時間 1,151 ms
コンパイル使用メモリ 82,224 KB
実行使用メモリ 76,504 KB
最終ジャッジ日時 2024-05-05 04:37:49
合計ジャッジ時間 4,385 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 115 ms
76,192 KB
testcase_01 AC 121 ms
76,004 KB
testcase_02 AC 39 ms
52,796 KB
testcase_03 AC 39 ms
52,204 KB
testcase_04 AC 38 ms
52,664 KB
testcase_05 AC 39 ms
53,812 KB
testcase_06 AC 38 ms
53,028 KB
testcase_07 AC 85 ms
75,804 KB
testcase_08 AC 64 ms
73,088 KB
testcase_09 AC 71 ms
76,312 KB
testcase_10 AC 115 ms
75,820 KB
testcase_11 AC 92 ms
75,952 KB
testcase_12 AC 108 ms
76,196 KB
testcase_13 AC 109 ms
76,504 KB
testcase_14 AC 86 ms
76,076 KB
testcase_15 AC 40 ms
52,516 KB
testcase_16 AC 39 ms
52,580 KB
testcase_17 AC 39 ms
53,844 KB
testcase_18 AC 38 ms
53,492 KB
testcase_19 AC 39 ms
53,352 KB
testcase_20 AC 39 ms
53,136 KB
testcase_21 AC 39 ms
53,728 KB
testcase_22 AC 39 ms
52,540 KB
testcase_23 AC 40 ms
52,708 KB
testcase_24 AC 39 ms
52,896 KB
testcase_25 AC 39 ms
53,816 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
from bisect import *

N, Q = map(int, input().split())
A = list(map(int, input().split()))
acc = [0]
s_acc = [0]

for Ai in A:
    acc.append(acc[-1]+Ai)
    s_acc.append(s_acc[-1]+Ai*(Ai+1)//2)

for _ in range(Q):
    S = int(input())
    
    if s_acc[-1]<S:
        print(-1)
        continue
    
    i = bisect_left(s_acc, S)
    l, r = 1, A[i-1]
    
    while l<=r:
        m = (l+r)//2
        
        if m*(m+1)//2>=S-s_acc[i-1]:
            r = m-1
        else:
            l = m+1
    
    print(acc[i-1]+l)
0