Submit Info #66462

Problem Lang User Status Time Memory
Static Range Sum cpp kanten4205 AC 678 ms 15.32 MiB

ケース詳細
Name Status Time Memory
example_00 AC 1 ms 0.42 MiB
max_random_00 AC 645 ms 15.26 MiB
max_random_01 AC 663 ms 15.32 MiB
max_random_02 AC 666 ms 15.32 MiB
max_random_03 AC 678 ms 15.26 MiB
max_random_04 AC 654 ms 15.27 MiB
random_00 AC 524 ms 12.25 MiB
random_01 AC 538 ms 13.48 MiB
random_02 AC 375 ms 6.35 MiB
random_03 AC 140 ms 7.32 MiB
random_04 AC 178 ms 6.01 MiB

#include <bits/stdc++.h> using namespace std; const long long MOD1 = 1000000007; const long long MOD2 = 998244353; typedef long long ll; typedef pair<long long, long long> P; const long long INF = 1e16; template <typename T> void input_arr(vector<T>& A, ll N) { for (ll i = 0; i < N; i++) { cin >> A[i]; } } template <typename T, typename Q> void input_arr(vector<pair<T, Q>>& A, ll N) { for (ll i = 0; i < N; i++) { cin >> A[i].first >> A[i].second; } } template <typename T> void input_arr(vector<vector<T>>& A, ll H, ll W) { for (ll i = 0; i < H; i++) { for (ll j = 0; j < W; j++) { cin >> A[i][j]; } } } template <typename T> struct StaticRangeSum { vector<T>A; StaticRangeSum(vector<T>&_A) : A(_A.size() + 1, 0) { ll N = (ll)_A.size(); for (ll i = 1; i <= N; i++) { A[i] = _A[i - 1]; } } void build() { for (ll i = 1; i < A.size(); i++) { A[i] += A[i - 1]; } } T query(ll r) { if (r < 0) return 0; else return A[min(r, (ll)A.size() - 1)]; } T query(ll l, ll r) { return query(r) - query(l); } }; int main() { ll N, Q; cin >> N >> Q; vector<ll>A(N); input_arr(A, N); StaticRangeSum<ll> S(A); S.build(); while (Q--) { ll l, r; cin >> l >> r; cout << S.query(l, r) << endl; } }