Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- using namespace std;
- ifstream cin("qtsume.in");
- ofstream cout("qtsume.out");
- const int nax = 100005;
- long long a[nax], pre[nax], pre2[nax];
- int main() {
- ios_base::sync_with_stdio(false);
- cin.tie(0);
- int n;
- cin >> n;
- for (int i = 1; i <= n; ++i) {
- cin >> a[i];
- }
- for (int i = 1; i <= n; ++i) {
- pre[i] = pre[i - 1] + a[i];
- }
- for (int i = 1; i <= n; ++i) {
- pre2[i] = pre2[i - 1] + pre[i];
- }
- int q;
- cin >> q;
- while (q--) {
- int x, y;
- cin >> x >> y;
- int len = y - x + 1;
- cout << len * pre[y] - pre2[y - 1] + ((x - 2 >= 0) ? pre2[x - 2] : 0) << '\n';
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment