首页 > 代码库 > NYOJ108

NYOJ108

// 思路就是:数组第i项存储的是前i个(包括第i个)士兵的杀敌数


#include <stdio.h>

#include <stdlib.h>

#include <string.h>


int main()

{

int num_of_soldiers, num_of_asks, from, to;

int total_kills[100001];

int i, num_of_kills;


memset(total_kills, 0, sizeof(total_kills));

        scanf("%d %d", &num_of_soldiers, &num_of_asks);

for (i = 1; i <= num_of_soldiers; i++)

{

scanf("%d", &num_of_kills);

total_kills[i] = total_kills[i - 1] + num_of_kills;

}


while (num_of_asks--)

{

scanf("%d %d", &from, &to);

printf("%d\n", total_kills[to] - total_kills[from - 1]);

}

        

        return EXIT_SUCCESS;

}


NYOJ108