#include<iostream>usingnamespace std;constint N =100010;int n, m;int s[N];int a, b;intmain(){
cin >> n >> m;for(int i =1; i <= n; i++){
cin >> s[i];
s[i]+= s[i-1];}while(m--){
cin >> a >> b;
cout << s[b]- s[a-1]<< endl;}return0;}
代码数组下标从1开始#include <iostream>using namespace std;const int N = 100010;int n, m;int s[N];int a, b;int main(){ cin >> n >> m; for(int i = 1; i <= n; i++){ cin >> s[i]; s[i] += s[i-1]; }