Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <tuple>
- #include <random>
- using std::pair;
- using std::cin;
- using std::cout;
- using std::vector;
- using int64 = int64_t;
- using std::max;
- using std::min;
- int main() {
- std::ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- int n, m;
- cin >> n >> m;
- vector<int64> val(n);
- for (size_t i = 0; i < n; ++i) {
- cin >> val[i];
- }
- vector<int64> pref(n);
- pref[0] = val[0];
- for (int i = 1; i < pref.size(); ++i){
- pref[i] = val[i] + pref[i-1];
- }
- for (size_t i = 0; i < m; ++i){
- int l, r;
- cin >> l >> r, --l, --r;
- if (l == 0){
- cout << pref[r] << '\n';
- } else {
- cout << pref[r] - pref[l-1] << '\n';
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement