Submission

Status:
PPPPPPPPPPPPPPPPPPPP

Score: 100

User: Dormon

Problemset: ผลบวก (กลาง)

Language: cpp

Time: 0.041 second

Submitted On: 2024-11-15 22:03:49

#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <functional>

#define debug(...) Debug(#__VA_ARGS__, __VA_ARGS__)
using namespace std;

template<typename T>
typename std::enable_if<std::is_integral<T>::value>::type
Debug(const char* name, T value) {
    std::cout << name << " : " << value << '\n';
}

template<typename T, typename... Args>
typename std::enable_if<std::is_integral<T>::value>::type
Debug(const char* names, T value, Args... args) {
    const char* comma = strchr(names, ',');
    std::cout.write(names, comma - names) << " : " << value << " | ";
    Debug(comma + 1, args...);
}

void solve(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n, pre = 0; cin >> n;
    vector<int> a(n, 0);
    for (auto &e:a){
        cin >> e;
        e += pre;
        pre = e;
    }
    //for (auto e:a) debug(e);
    int q; cin >> q;
    while (q--){
        int l, r; cin >> l >> r;
        if (l == 0) cout << a[r] << '\n';
        else cout << a[r] - a[l-1] << '\n';
    }
}

int main()
{
    int q = 1; 
    //scanf("%d", &q);
    while (q--){
        solve();
    }
}