結果

問題 No.1890 Many Sequences Sum Queries
ユーザー trineutrontrineutron
提出日時 2022-04-04 21:15:12
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 172 ms / 2,000 ms
コード長 545 bytes
コンパイル時間 2,407 ms
コンパイル使用メモリ 205,372 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-05-04 06:25:04
合計ジャッジ時間 4,699 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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