結果

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

ソースコード

diff #

#include <bits/stdc++.h>

int main() {
	int n, q;
	std::cin >> n >> q;
	std::vector<int> a(n);
	for (int i = 0; i < n; i++) {
		std::cin >> a.at(i);
	}
	std::vector<int64_t> c(1);
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < a.at(i); j++) {
			c.push_back(j + 1);
		}
	}
	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