結果

問題 No.1890 Many Sequences Sum Queries
ユーザー trineutron
提出日時 2022-04-04 21:18:02
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 196 ms / 2,000 ms
コード長 604 bytes
コンパイル時間 1,868 ms
コンパイル使用メモリ 197,424 KB
最終ジャッジ日時 2025-01-28 15:03:57
ジャッジサーバーID
(参考情報)
judge5 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

int main() {
	int n, q, len = 0;
	std::cin >> n >> q;
	std::vector<int> a(n);
	for (int i = 0; i < n; i++) {
	    std::cin >> a.at(i);
		len += a.at(i);
	}
	std::vector<int64_t> c(len + 1);
	int idx = 1;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < a.at(i); j++) {
			c.at(idx) = j + 1;
			idx++;
		}
	}
	for (auto &&x : c) {
		if (x) x += *(&x - 1);
	}
	for (int i = 0; i < q; i++) {
		int s;
		std::cin >> s;
		auto it = lower_bound(c.begin(), c.end(), s);
		if (it == c.end()) {
			std::cout << -1 << '\n';
		} else {
			std::cout << it - c.begin() << '\n';
		}
	}
}
0