結果

問題 No.1890 Many Sequences Sum Queries
ユーザー ace_amuroace_amuro
提出日時 2023-03-30 13:56:06
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 165 ms / 2,000 ms
コード長 789 bytes
コンパイル時間 688 ms
コンパイル使用メモリ 82,092 KB
実行使用メモリ 13,668 KB
最終ジャッジ日時 2023-10-22 00:26:08
合計ジャッジ時間 4,427 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 165 ms
13,668 KB
testcase_01 AC 157 ms
13,668 KB
testcase_02 AC 6 ms
13,668 KB
testcase_03 AC 5 ms
13,668 KB
testcase_04 AC 5 ms
13,668 KB
testcase_05 AC 5 ms
13,668 KB
testcase_06 AC 5 ms
13,668 KB
testcase_07 AC 65 ms
13,668 KB
testcase_08 AC 15 ms
13,668 KB
testcase_09 AC 19 ms
13,668 KB
testcase_10 AC 155 ms
13,668 KB
testcase_11 AC 78 ms
13,668 KB
testcase_12 AC 115 ms
13,668 KB
testcase_13 AC 124 ms
13,668 KB
testcase_14 AC 65 ms
13,668 KB
testcase_15 AC 5 ms
13,668 KB
testcase_16 AC 5 ms
13,668 KB
testcase_17 AC 5 ms
13,668 KB
testcase_18 AC 5 ms
13,668 KB
testcase_19 AC 4 ms
13,668 KB
testcase_20 AC 5 ms
13,668 KB
testcase_21 AC 4 ms
13,668 KB
testcase_22 AC 5 ms
13,668 KB
testcase_23 AC 5 ms
13,668 KB
testcase_24 AC 4 ms
13,668 KB
testcase_25 AC 4 ms
13,668 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
#include<ctime>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<map>
using namespace std;
typedef long long LL;
const int MR=1e6+10;
int n,Q,a[MR];
LL S,sa[MR],sb[MR],sc[MR];
int main(){
    cin>>n>>Q;
    for(int i=1;i<=n;i++) cin>>a[i];
    for(int i=1;i<=n;i++){
        sa[i]=sa[i-1]+a[i];
        sb[i]=sb[i-1]+1ll*a[i]*(a[i]+1)/2;
    }   
    for(int i=1;i<MR;i++){
        sc[i]=sc[i-1]+i;
    }
    while(Q--) {
        cin>>S;
        if(S>sb[n]){
            printf("-1\n");
            continue;
        }
        int i=lower_bound(sb+1,sb+1+n,S)-sb;
        int j=lower_bound(sc+1,sc+MR,S-sb[i-1])-sc;
        printf("%lld\n",sa[i-1]+j);
    }
    return 0;
}
0