来骗

题目 来,骗

image-f96bccf0

思路分析

裸题 直接前缀和

image-d6b9aeda

代码实现

#include<bits/stdc++.h>
using namespace std;
#define endl '\n'

const int N=1000010;
int s[N];
int n,q;

int main()
{
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    cin>>n;
    for(int i=1;i<=n;i++){
        int x;cin>>x;
        s[i]=s[i-1]+x;
    }
    cin>>q;
    while(q--){
        int l,r;cin>>l>>r;
        cout<<s[r]-s[l-1]<<endl;
    }
    return 0;
}

同类题型

视频讲解


⬅️ 最佳牛围栏 🏠 00-刷题理模型 ➡️ 激光炸弹