結果
| 問題 |
No.1890 Many Sequences Sum Queries
|
| ユーザー |
trineutron
|
| 提出日時 | 2022-04-04 21:12:00 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 583 bytes |
| コンパイル時間 | 1,987 ms |
| コンパイル使用メモリ | 196,100 KB |
| 最終ジャッジ日時 | 2025-01-28 15:03:29 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | RE * 1 |
| other | RE * 25 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:24:25: warning: format ‘%d’ expects argument of type ‘int*’, but argument 2 has type ‘int’ [-Wformat=]
24 | scanf("%d", s);
| ~^ ~
| | |
| | int
| int*
main.cpp:29:34: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘__gnu_cxx::__normal_iterator<long int*, std::vector<long int> >::difference_type’ {aka ‘long int’} [-Wformat=]
29 | printf("%d\n", it - c.begin());
| ~^ ~~~~~~~~~~~~~~
| | |
| int __gnu_cxx::__normal_iterator<long int*, std::vector<long int> >::difference_type {aka long int}
| %ld
main.cpp:5:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
5 | scanf("%d%d", &n, &q);
| ~~~~~^~~~~~~~~~~~~~~~
main.cpp:8:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
8 | scanf("%d", &a[i]);
| ~~~~~^~~~~~~~~~~~~
main.cpp:24:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
24 | scanf("%d", s);
| ~~~~~^~~~~~~~~
main.cpp:24:22: warning: ‘s’ may be used uninitialized [-Wmaybe-uninitialized]
24 | scanf("%d", s);
| ~~~~~^~~~~~~~~
main.cpp:23:21: note: ‘s’ was declared here
23 | int s;
| ^
ソースコード
#include <bits/stdc++.h>
int main() {
int n, q, len = 0;
scanf("%d%d", &n, &q);
std::vector<int> a(n);
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
len += a[i];
}
std::vector<int64_t> c(len + 1);
int idx = 1;
for (int i = 0; i < n; i++) {
for (int j = 0; j < a[i]; j++) {
c[idx] = j + 1;
idx++;
}
}
for (int i = 0; i < len; i++) {
c[i + 1] += c[i];
}
for (int i = 0; i < q; i++) {
int s;
scanf("%d", s);
auto it = lower_bound(c.begin(), c.end(), s);
if (it == c.end()) {
puts("-1");
} else {
printf("%d\n", it - c.begin());
}
}
}
trineutron