cses

My solution for the coding challenges of cses.fi
git clone https://git.tronto.net/cses
Download | Log | Files | Refs | README

static_range_sum_queries_1646.cpp (293B)


      1 #include <iostream>
      2 #include <vector>
      3 
      4 int main() {
      5 	int n, q, x, y;
      6 	std::cin >> n >> q;
      7 	std::vector<long long> a(n+1, 0);
      8 	for (int i = 1; i <= n; i++) {
      9 		std::cin >> a[i];
     10 		a[i] += a[i-1];
     11 	}
     12 
     13 	for (int i = 0; i < q; i++) {
     14 		std::cin >> x >> y;
     15 		std::cout << a[y]-a[x-1] << "\n";
     16 	}
     17 }