首页 > 其他分享 >acwing 前缀和练习

acwing 前缀和练习

时间:2023-02-12 17:14:28浏览次数:58  
标签:tmp 前缀 int 练习 back num push include acwing

原题链接

image

题解

#include "iostream"
#include "vector"
using namespace std;
int main(){
    int n,m,tmp,l,r;
    cin>>n>>m;
    vector<int>num;
    num.push_back(0);
    for(int i=1;i<=n;i++){
        cin>>tmp;
        num.push_back(tmp);
        if(i!=1){
            num[i]+=num[i-1];
        }
    }
    for(int i=0;i<m;i++){
        cin>>l>>r;
        cout<<num[r]-num[l-1]<<endl;
    }
}

标签:tmp,前缀,int,练习,back,num,push,include,acwing
From: https://www.cnblogs.com/ChengMao/p/17114129.html

相关文章