2 条题解

  • 3
    @ 2023-9-4 20:59:11

    前缀和模板题。

    #include <cstdio>
    
    int fore[1000001];
    
    int main(){
        int N, M;
        scanf("%d %d", &N, &M);
        int temp, n, m;
        for(int i = 1; i <= N; i ++){
            scanf("%d", &temp);
            fore[i] = fore[i - 1] + temp;
        }
        for(int i = 1; i <= M; i ++){
            scanf("%d %d", &m, &n);
            printf("%d\n", fore[n] - fore[m - 1]);
        }
        return 0;
    }
    
    • 1
      @ 2023-10-9 21:24:36
      #include<stdio.h>
      
      int a[1000005] = { 0 };
      
      int main()
      {
          int m, n, N, M, c, i;
          scanf("%d%d", &N, &M);
          for (i = 1; i <= N; i++)
          {
              scanf("%d", &c);
              a[i] = a[i - 1] + c;
          }
          while (M--)
          {
              scanf("%d%d", &m, &n);
              printf("%d\n", a[n] - a[m - 1]);
          }
          return 0;
      }
      
      • 1

      信息

      ID
      167
      时间
      1000ms
      内存
      128MiB
      难度
      6
      标签
      (无)
      递交数
      689
      已通过
      200
      上传者