标准解法
2026-09-15 18:54:16
发布于:吉林
1阅读
0回复
0点赞
题解来源于JTBG
#include <bits/stdc++.h>
#ifdef USE_JTBG_H
#undef JTBG_ALL
#undef _agree_
#define JTBG_ALL
#undef _agree_
#include "jtbg.h"
#endif
using namespace std;
int main()
{
int n,m;
cin>>n>>m;
int pre[n+1],a[n];
pre[0]=0;
memset(pre,0,sizeof pre);
for(int i=1;i<=n;i++)
{
cin>>a[i];
}
for(int i=1;i<=n;i++)
{
pre[i]=pre[i-1]+a[i];
}
while(m--)
{
int l,r;
cin>>l>>r;
cout<<pre[r]-pre[l-1]<<endl;
}
return 0;
}
这里空空如也


有帮助,赞一个