Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
465 B
1
Indexable
Never
#include <iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<numeric>
#include <algorithm>

using namespace std;

int main()
{
	int n;
	cin >> n;
	int a[1000001];
	for (int i=1; i <= n; i++)
	{
		cin >> a[i];
	}
	int m;
	cin >> m;
	int l;
	int r;
	for (int i = 0; i < m; i++)
	{
		cin >> l >> r;
		int s[1000001];
		s[0] = 0;
		int k = 0;
		for (int i = 1; i <= n; i++)
		{
			k = k + a[i];
			s[i] = k;
		}
		cout << s[r] - s[l - 1]<<'\n';
	}

}
Leave a Comment