mot bai prefixsum nao do :p

02/02/2023

zuli sent me

Code
#include <bits/stdc++.h>
using namespace std;

int main(){
	int n,q;
	cin >> n >> q;
	long long a[n+1];
	for (int i=1;i<=n;i++) cin >> a[i];
	//init prefixsum
	long long prefix[n+1];
	fill(prefix+1, prefix+n+1,0);
	prefix[0]=0;
	prefix[1]=0;
	for (int i=2;i<= n;i++){
		if (i % 2 == 0) {
			prefix[i]+=prefix[i-1]+a[i];
		} else prefix[i]=prefix[i-1];
	}
	for (int i=1;i<= n;i++) cout << prefix[i] <<' ';
	cout << endl;

	long long l,r;
	while (q--){
		cin >> l >> r;
		cout << prefix[r] - prefix[l-1] << endl;		
	}
	
	return 0;
}