12125 - Tired janitor
raw download clone
C
views 24
,
size 695 b
#include <stdio.h>

int main(void)
{
    int n, q, i, j, k, l;
    unsigned long long t[1000000];
    char ch;

    scanf("%d%d", &n, &q);
    i = 1;
    t[0] = 0;
    ch = getchar();
    while ((ch = getchar()) != '\n')
    {
        if (ch >= '0' && ch <= '9')
        {
            t[i] = ch - '0';
            while((ch = getchar()) >= '0' && ch <= '9')
            {
                t[i] = 10 * t[i];
                t[i] += ch - '0';
            }
            t[i] += t[i-1];
            i++;
        }
    }
    l = 1;
    while (l <= q)
    {
        scanf("%d%d", &j, &k);
        printf("%lld\n", t[k] - t[j-1]);
        l++;
    }

    return 0;
}
close fullscreen
Login or Register to edit or fork this paste. It's free.