题目链接:http://codeforces.com/problemset/problem/1189/C

Codeforces 1189C Candies!

Codeforces 1189C Candies!


思路:前缀和。

AC代码:

#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5 +5;
int a[maxn];
int n, m;
int ask(int x,int y)
{
    return (a[y] - a[x-1])/10;
}
int main()
{
    cin >> n;
    int x , y;
    for(int i = 1;i <= n;i++)
    {
        cin >> a[i];
        a[i] += a[i-1];
    }
    cin >> m;
    while(m--)
    {
        cin >> x >> y;
        cout << ask(x,y) << endl;
    }
    return 0;
}

 

相关文章: