3 solutions

  • 0
    @ 2025-11-21 15:11:11

    解题报告

    撰写人: 钟世博

    难度等级

    ★★☆☆☆

    参考程序

    #include<bits/stdc++.h>
    using namespace std;
    int n,m;
    int main()
    {
        cin>>n>>m;
    	int a[n+1],b[n+41];
    	b[0]=0;
    	for(int i=1;i<=n;i++)
    	{
            cin>>a[i];
    		b[i]=b[i-1]+a[i];
    	}
    	for(int i=1;i<=m;i++)
    	{
    		int x,y;
    		cin>>x>>y;
    		cout<<b[y]-b[x-1]<<endl;
    	}
    	return 0;
    }
    
    
    • 0
      @ 2025-11-21 14:39:03

      解题报告

      撰写人: 陈斯伟

      题意分析

      一共输出 m 行,每行一个整数,对应妈妈每个疑问的答案(也就是第 l 天到第 r 天的存钱总数)。

      难度等级

      ★☆☆☆☆

      解题思路

      第一行有两个整数 n 和 m,分别表示宝贝存钱的总天数,以及妈妈的疑问个数。第二行有 n 个正整数,按顺序表示宝贝第 1 天到第 n 天,每天往储钱罐里存的钱数。接下来 m 行,每行有两个整数 l 和 r,表示妈妈的一个疑问:想知道第 l 天到第 r 天的存钱总数。

      解题反思

      : )

      参考程序

      #include<bits/stdc++.h>
      using namespace std;
      const int N=1e6+10;
      long long n,m,l,r,na[N],mb[N];
      int main(){
          cin>>n>>m;
          for(int i = 1; i <= n; i++) {
              cin>>na[i];
              mb[i]=mb[i-1]+na[i];
          }
          for(int i=1;i<=m;i++){
              cin>>l>>r;
              long long s=mb[r]-m[l-1];
              cout<<s<<endl;
          }
          return 0;
      }
      
      • 0
        @ 2025-11-21 14:37:44

        解题报告

        撰写人: 许苡键

        难度等级

        ★★☆☆☆

        参考程序

        #include <bits/stdc++.h>
        using namespace std;
        int main(){
        	int n,m;
        	cin>>n>>m;
        	int a[n+1],b[n+1];
        	b[0]=0;
        	for(int i=1;i<=n;i++){
        		cin>>a[i];
        		b[i]=b[i-1]+a[i];
        	}
        	for(int i=1;i<=m;i++){
        		int x,y;
        		cin>>x>>y;
        		cout<<b[y]-b[x-1]<<endl;
        	}
        }
        
        • 1

        Information

        ID
        614
        Time
        1000ms
        Memory
        128MiB
        Difficulty
        6
        Tags
        # Submissions
        82
        Accepted
        24
        Uploaded By