Submit Info #67041

Problem Lang User Status Time Memory
Static Range Sum cpp-acl (anonymous) AC 927 ms 13.59 MiB

ケース詳細
Name Status Time Memory
example_00 AC 1 ms 0.45 MiB
max_random_00 AC 927 ms 13.57 MiB
max_random_01 AC 892 ms 13.47 MiB
max_random_02 AC 866 ms 13.53 MiB
max_random_03 AC 864 ms 13.59 MiB
max_random_04 AC 862 ms 13.48 MiB
random_00 AC 675 ms 10.87 MiB
random_01 AC 808 ms 11.79 MiB
random_02 AC 156 ms 6.34 MiB
random_03 AC 782 ms 8.64 MiB
random_04 AC 445 ms 5.77 MiB

#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<vi> vvi; typedef vector<vl> vvl; typedef pair<int, int> pii; typedef pair<double, double> pdd; typedef pair<ll, ll> pll; typedef vector<pii> vii; typedef vector<pll> vll; typedef double dl; #define PB push_back #define F first #define S second #define MP make_pair #define endl '\n' #define all(a) (a).begin(), (a).end() #define sz(x) (int)x.size() #define mid(l, r) ((r + l) / 2) #define left(node) (node * 2) #define right(node) (node * 2 + 1) #define mx_int_prime 999999937 const double PI = acos(-1); const double eps = 1e-9; const int inf = 2000000000; const ll infLL = 9000000000000000000; #define MOD 1000000007 #define mem(a, b) memset(a, b, sizeof(a)) #define gcd(a, b) __gcd(a, b) #define sqr(a) ((a) * (a)) #define BeatMeScanf \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define fraction() \ cout.unsetf(ios::floatfield); \ cout.precision(10); \ cout.setf(ios::fixed, ios::floatfield); #define file() \ freopen("input.txt", "r", stdin); \ freopen("output.txt", "w", stdout); #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; /// change ll to any data type /// less_equal for multiset increasing order /// less for set increasing order /// greater_equal for multiset decreasing order /// greater for set decreasing order /// cout<<*X.find_by_order(1)<<endl; // iterator to the k-th element /// cout<<X.order_of_key(-5)<<endl; // number of items in a set that are strictly smaller than our item typedef vector<int>::iterator vit; typedef set<int>::iterator sit; int dx[] = {0, 0, +1, -1}; int dy[] = {+1, -1, 0, 0}; //int dx[] = {+1, 0, -1, 0, +1, +1, -1, -1}; //int dy[] = {0, +1, 0, -1, +1, -1, +1, -1}; template <typename F, typename S> ostream &operator<<(ostream &os, const pair<F, S> &p) { return os << "(" << p.first << ", " << p.second << ")"; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { os << "{"; for (auto it = v.begin(); it != v.end(); ++it) { if (it != v.begin()) os << ", "; os << *it; } return os << "}"; } template <typename T> ostream &operator<<(ostream &os, const set<T> &v) { os << "["; for (auto it = v.begin(); it != v.end(); ++it) { if (it != v.begin()) os << ", "; os << *it; } return os << "]"; } template <typename T> ostream &operator<<(ostream &os, const multiset<T> &v) { os << "["; for (auto it = v.begin(); it != v.end(); ++it) { if (it != v.begin()) os << ", "; os << *it; } return os << "]"; } template <typename F, typename S> ostream &operator<<(ostream &os, const map<F, S> &v) { os << "["; for (auto it = v.begin(); it != v.end(); ++it) { if (it != v.begin()) os << ", "; os << it->first << " = " << it->second; } return os << "]"; } #define dbg(args...) \ do \ { \ cerr << #args << " : "; \ faltu(args); \ } while (0) void faltu() { cerr << endl; } template <typename T> void faltu(T a[], int n) { for (int i = 0; i < n; ++i) cerr << a[i] << ' '; cerr << endl; } template <typename T, typename... hello> void faltu(T arg, const hello &...rest) { cerr << arg << ' '; faltu(rest...); } /**********************Code starts here*********************************/ int main() { BeatMeScanf ; int n , q ; cin >> n >> q ; vi v(n) ; vl sumv ; ll summ = 0 ; for ( int i = 0 ; i < n ; i++ ) { cin >> v[i] ; summ += v[i] ; sumv.PB( summ ) ; } dbg ( sumv ) ; while ( q-- ) { ll sum = 0 ; int l , r ; cin >> l >> r ; r-- ; if ( l == 0 ) cout << sumv[r] << endl ; else if ( r == l ) cout << v[r] << endl ; else cout << sumv[r] - sumv[l-1] << endl ; } return 0; }