士兵杀敌(一) n 108

来源:互联网 发布:sql truncate table 编辑:程序博客网 时间:2024/05/04 06:40

尽量采用存前n项和的方法存储,可能其他方法会超时(我没有试),,,看到此篇推荐看士兵杀敌(二)可怜可怜

#include<stdio.h>int a[1000010];int main(){    int N, M, num, i, from, to;    scanf("%d%d", &N, &M);    a[0] = 0;    for(i=1;i<=N;i++)    {         scanf("%d", &num);         a[i] = a[i-1] + num;    }    while(M--)    {         scanf("%d%d", &from, &to);         printf("%d\n", a[to]-a[from-1]);    }    return 0;}


 

原创粉丝点击