結果

問題 No.1890 Many Sequences Sum Queries
ユーザー erbowlerbowl
提出日時 2022-07-24 14:48:17
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 183 ms / 2,000 ms
コード長 680 bytes
コンパイル時間 1,979 ms
コンパイル使用メモリ 202,500 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-20 14:02:26
合計ジャッジ時間 4,451 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 179 ms
4,376 KB
testcase_01 AC 183 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 67 ms
4,380 KB
testcase_08 AC 15 ms
4,376 KB
testcase_09 AC 20 ms
4,380 KB
testcase_10 AC 174 ms
4,376 KB
testcase_11 AC 85 ms
4,384 KB
testcase_12 AC 122 ms
4,380 KB
testcase_13 AC 130 ms
4,376 KB
testcase_14 AC 67 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 1 ms
4,384 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 2 ms
4,384 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

typedef long long ll;
typedef long double ld;
#include <bits/stdc++.h>
using namespace std;
#define int long long

signed main(){
    ll n,q;
    std::cin >> n>>q;
    vector<ll> a(n);
    vector<ll> v;
    ll cur = 0;
    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
        for (int j = 1; j <= a[i]; j++) {
            cur += j;
            v.push_back(cur);
        }
    }
    for (int iii = 0; iii < q; iii++) {
        ll s;
        std::cin >> s;
        
        auto it = lower_bound(v.begin(),v.end(),s);
        if(it==v.end()){
            std::cout << -1 << std::endl;
        }else{
            std::cout << it-v.begin()+1 << std::endl;
        }
    }
}
0