提出 #57742758
ソースコード 拡げる
// #pragma comment(linker, "/stack:200000000")
// #pragma GCC optimize("Ofast,no-stack-protector")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
// #pragma GCC optimize("unroll-loops")
#include <stdio.h>
#include <bits/stdc++.h>
#ifdef PERVEEVM_LOCAL
#define debug(x...) std::cerr << "[DEBUG]\t" << __LINE__ << ":\t" << (#x) << " = "; print_debug(x)
#else
#define debug(x...) 238
#endif
#define fastIO std::ios_base::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(nullptr)
#define NAME "File"
using ll = long long;
using ld = long double;
#ifdef PERVEEVM_LOCAL
std::mt19937 rnd(238);
#else
std::mt19937 rnd(std::chrono::high_resolution_clock::now().time_since_epoch().count());
#endif
template<typename T1, typename T2>
std::ostream& operator<<(std::ostream& out, const std::pair<T1, T2>& p) {
out << "(" << p.first << ", " << p.second << ")";
return out;
}
template<size_t index, typename T>
std::ostream& print_tuple(std::ostream& out, const T& t) {
if constexpr (index == std::tuple_size<T>::value) {
out << ")";
return out;
} else {
if (index > 0) {
out << ", ";
} else {
out << "(";
}
out << std::get<index>(t);
return print_tuple<index + 1, T>(out, t);
}
}
template<typename ...T>
std::ostream& operator<<(std::ostream& out, const std::tuple<T...>& t) {
return print_tuple<0, std::tuple<T...>>(out, t);
}
template<typename Container, typename = decltype(std::begin(std::declval<Container>()))>
typename std::enable_if<!std::is_same<Container, std::string>::value, std::ostream&>::type
operator<<(std::ostream& out, const Container& container) {
out << "{";
for (auto it = container.begin(); it != container.end(); ++it) {
if (it != container.begin()) {
out << ", ";
}
out << *it;
}
out << "}";
return out;
}
void print_debug() {
std::cerr << std::endl;
}
template<typename T, typename... V>
void print_debug(const T& value, const V&... others) {
std::cerr << value;
if (sizeof...(others) != 0) {
std::cerr << ", ";
print_debug(others...);
} else {
std::cerr << std::endl;
}
}
template<typename T>
bool smin(T& a, const T& b) {
if (b < a) {
a = b;
return true;
}
return false;
}
template<typename T>
bool smax(T& a, const T& b) {
if (a < b) {
a = b;
return true;
}
return false;
}
const double PI = atan2(0.0, -1.0);
const int INF = 0x3f3f3f3f;
const ll LINF = (ll)2e18;
void run() {
int n;
scanf("%d", &n);
std::vector<std::pair<int, ll>> a(n);
for (int i = 0; i < n; ++i) {
scanf("%d", &a[i].first);
}
for (int i = 0; i < n; ++i) {
scanf("%lld", &a[i].second);
if (i != 0) {
a[i].second += a[i - 1].second;
}
}
int q;
scanf("%d", &q);
while (q--) {
int l, r;
scanf("%d%d", &l, &r);
int it1 = std::lower_bound(a.begin(), a.end(), std::make_pair(l, -1ll)) - a.begin();
int it2 = std::upper_bound(a.begin(), a.end(), std::make_pair(r, LINF)) - a.begin() - 1;
if (it1 > it2) {
printf("0\n");
} else {
ll ans = a[it2].second;
if (it1 != 0) {
ans -= a[it1 - 1].second;
}
printf("%lld\n", ans);
}
}
}
int main(void) {
// freopen(NAME".in", "r", stdin);
// freopen(NAME".out", "w", stdout);
#ifdef PERVEEVM_LOCAL
auto start = std::chrono::high_resolution_clock::now();
#endif
run();
#ifdef PERVEEVM_LOCAL
auto end = std::chrono::high_resolution_clock::now();
std::cerr << "Execution time: "
<< std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count()
<< " ms" << std::endl;
#endif
return 0;
}
提出情報
| 提出日時 |
|
| 問題 |
D - 1D Country |
| ユーザ |
DishonoredR |
| 言語 |
C++ 20 (gcc 12.2) |
| 得点 |
350 |
| コード長 |
4055 Byte |
| 結果 |
AC |
| 実行時間 |
156 ms |
| メモリ |
6752 KiB |
コンパイルエラー
Main.cpp: In function ‘void run()’:
Main.cpp:107:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
107 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
Main.cpp:111:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
111 | scanf("%d", &a[i].first);
| ~~~~~^~~~~~~~~~~~~~~~~~~
Main.cpp:114:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
114 | scanf("%lld", &a[i].second);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~
Main.cpp:121:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
121 | scanf("%d", &q);
| ~~~~~^~~~~~~~~~
Main.cpp:125:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
125 | scanf("%d%d", &l, &r);
| ~~~~~^~~~~~~~~~~~~~~~
ジャッジ結果
| セット名 |
Sample |
All |
| 得点 / 配点 |
0 / 0 |
350 / 350 |
| 結果 |
|
|
| セット名 |
テストケース |
| Sample |
00_sample_01.txt, 00_sample_02.txt |
| All |
00_sample_01.txt, 00_sample_02.txt, 01_test_01.txt, 01_test_02.txt, 01_test_03.txt, 01_test_04.txt, 01_test_05.txt, 01_test_06.txt, 01_test_07.txt, 01_test_08.txt, 01_test_09.txt, 01_test_10.txt, 01_test_11.txt, 01_test_12.txt, 01_test_13.txt, 01_test_14.txt, 01_test_15.txt, 01_test_16.txt, 01_test_17.txt, 01_test_18.txt, 01_test_19.txt, 01_test_20.txt, 01_test_21.txt, 01_test_22.txt, 01_test_23.txt, 01_test_24.txt |
| ケース名 |
結果 |
実行時間 |
メモリ |
| 00_sample_01.txt |
AC |
1 ms |
3748 KiB |
| 00_sample_02.txt |
AC |
1 ms |
3736 KiB |
| 01_test_01.txt |
AC |
155 ms |
6544 KiB |
| 01_test_02.txt |
AC |
155 ms |
6544 KiB |
| 01_test_03.txt |
AC |
155 ms |
6536 KiB |
| 01_test_04.txt |
AC |
154 ms |
6536 KiB |
| 01_test_05.txt |
AC |
154 ms |
6524 KiB |
| 01_test_06.txt |
AC |
155 ms |
6540 KiB |
| 01_test_07.txt |
AC |
155 ms |
6524 KiB |
| 01_test_08.txt |
AC |
154 ms |
6452 KiB |
| 01_test_09.txt |
AC |
155 ms |
6544 KiB |
| 01_test_10.txt |
AC |
156 ms |
6540 KiB |
| 01_test_11.txt |
AC |
109 ms |
4340 KiB |
| 01_test_12.txt |
AC |
51 ms |
4336 KiB |
| 01_test_13.txt |
AC |
3 ms |
3844 KiB |
| 01_test_14.txt |
AC |
51 ms |
3704 KiB |
| 01_test_15.txt |
AC |
38 ms |
3596 KiB |
| 01_test_16.txt |
AC |
86 ms |
6472 KiB |
| 01_test_17.txt |
AC |
85 ms |
6448 KiB |
| 01_test_18.txt |
AC |
124 ms |
6392 KiB |
| 01_test_19.txt |
AC |
61 ms |
6448 KiB |
| 01_test_20.txt |
AC |
96 ms |
6424 KiB |
| 01_test_21.txt |
AC |
148 ms |
6536 KiB |
| 01_test_22.txt |
AC |
148 ms |
6540 KiB |
| 01_test_23.txt |
AC |
81 ms |
6752 KiB |
| 01_test_24.txt |
AC |
1 ms |
3748 KiB |