結果

問題 No.1890 Many Sequences Sum Queries
ユーザー matcharate12matcharate12
提出日時 2022-03-28 15:16:02
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 196 ms / 2,000 ms
コード長 764 bytes
コンパイル時間 1,645 ms
コンパイル使用メモリ 166,304 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-05-04 05:04:43
合計ジャッジ時間 4,702 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 189 ms
6,812 KB
testcase_01 AC 196 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 3 ms
6,944 KB
testcase_07 AC 66 ms
6,940 KB
testcase_08 AC 14 ms
6,940 KB
testcase_09 AC 18 ms
6,944 KB
testcase_10 AC 181 ms
6,944 KB
testcase_11 AC 94 ms
6,944 KB
testcase_12 AC 126 ms
6,944 KB
testcase_13 AC 137 ms
6,940 KB
testcase_14 AC 71 ms
6,940 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 2 ms
6,940 KB
testcase_17 AC 2 ms
6,944 KB
testcase_18 AC 1 ms
6,940 KB
testcase_19 AC 1 ms
6,940 KB
testcase_20 AC 2 ms
6,944 KB
testcase_21 AC 2 ms
6,940 KB
testcase_22 AC 1 ms
6,940 KB
testcase_23 AC 2 ms
6,944 KB
testcase_24 AC 2 ms
6,944 KB
testcase_25 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <iostream>
#include <string.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define srep(i,a,b) for(int i = a; i < b; i++)
#define all(A) (A).begin(),A.end()
#define MOD 1000000007
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using Graph = vector<vector<int>>;
int siz(string s){return (int)s.size();}

ll B[101010],S[101010];
int main(void){
	int n,q; cin >> n >> q;
	int nn = 0;
	int p = 0;
	rep(i,n){
		int a; cin >> a;
		nn += a;
		rep(j,a) B[p] = j+1,p++;
	}
	rep(i,nn+1) S[i+1] = S[i]+B[i];

	rep(i,q){
		ll s; cin >> s;
		int ok = nn+1,ng = -1;
		while(abs(ok-ng) > 1){
			int mid = (ok+ng)/2;
			if(S[mid] >= s) ok = mid;
			else ng = mid;
		}
		cout << (ok == nn+1 ? -1 : ok) << endl;
	}
	return 0;
}
0