21 条题解

  • 7
    @ 2025-1-26 9:56:57
    #include
    using namespace std;
    int n,m,sum[1000005],l,r,a[10000];
    int main()
    {    
        cin>>n>>m;
        for(int i=1;i<=n;i++) {
        	cin>>l;
        	sum[i]=sum[i-1]+a[i];
    	}
    	while(m--) {
    		cin>>l>>r;
    		cout<<sum[r]-sum[l-1]<<"\n";
    	}
        return 0;
    }
    
    • 5
      @ 2021-12-18 19:00:04
      /*****************************************
      备注:
      ******************************************/
      #include <queue>
      #include <math.h>
      #include <stack>
      #include <stdio.h>
      #include <iostream>
      #include <vector>
      #include <iomanip>
      #include <string.h>
      #include <algorithm>
      using namespace std;
      #define LL long long
      const int N = 1e6 + 10;
      const int INF = 0x3f3f3f3f;
      int a[N],sum[N];
      int main()
      {
      	int n , m;
      	cin >> n >> m;
      	for(int i = 1 ; i <= n ; i++)
      	{
      		scanf("%d",&a[i]);
      		a[i] += a[i-1];
      	}
      	// for(int i = 1 ; i <= n ; i++)
      	// 	sum[i]=sum[i-1] + a[i];
      	while(m--)
      	{
      		int l ,r ;
      		scanf("%d%d",&l,&r);
      		printf("%d\n",a[r] - a[l-1]);
      	}
      	return 0;
      }
      
      • 4
        @ 2023-2-19 21:17:31
        #include <bits/stdc++.h>
        using namespace std;
        long long a[100000001],sum[100000001];
        int main(){
        	long long n,m,x,y;
        	cin >> n >> m;
        	for(long long i = 1 ; i <= n ; i++){
        		cin >> a[i];
        		sum[i] = sum[i - 1] + a[i];
        	}
        	for(long long i = 1 ; i <= m ; i++){
        		cin >> x >> y;
        		cout << sum[y] - sum[x - 1] << endl;
        	}
        	return 0;
        }
        • 2
          @ 2025-1-26 10:03:38
          #include<iomanip> 
          #include<cstdio> 
          #include<cmath> 
          #include<cstring> 
          const int N=1e7+10;
          const int INF=0x3f3f3f3f;
          int n,m,l,r,a[N],sum[N];
          using namespace std;
          int main()
          {
          	cin>>n>>m;
          	for(int i=1;i<=n;i++)
          	{
          		cin>>a[i];
          		a[i]+=a[i-1];
          	}
          	for(int i=1;i<=m;i++)
          	{
          		cin>>l>>r;
          		cout<<a[r]-a[l-1]<<endl;
          	}
          	return 0;
          }
          
        • 2
          @ 2023-3-12 15:46:05
          /****************************
             presented by xingcode
          ****************************/
          #include<bits/stdc++.h>
          using namespace std;
          int n,m,f[1000005],x,y;
          int main()
          {    
              cin>>n>>m;
              for(int i=1;i<=n;i++) {
              	cin>>x;
              	f[i]=f[i-1]+x;
          	}
          	while(m--) {
          		cin>>x>>y;
          		cout<<f[y]-f[x-1]<<"\n";
          	}
              return 0;
          }
          /*****************************
                  do not copy!!!
          *****************************/
          
          • 2
            @ 2022-9-26 11:32:22
            #include <iostream>
            using namespace std;
            int a[1000005];
            int main()
            {
            	int n, m, x, l, r;
            	cin >> n >> m;
            	for (int i = 1;i <=  n;i++)
            	{
            		cin >> x;
            		a[i] = a[i - 1] + x;// 覆盖原数组
            	}
            	for (int i = 1;i <= m;i++)
            	{
            		cin >> l >> r;
            		cout << a[r] - a[l - 1] << endl;
                            //直接代
            	}
            	return 0;
            }
            
            • 1
              @ 2025-3-22 20:18:45

              made in CHINA

              using namespace std;
              const int N = 5e4+5;
              struct node{
              	int x,id;
              }a[N];
              int cmp(node a,node b)
              {
              	return a.x<b.x;
              }
              int main()
              {
              	int n,s[N]={},ans=0;
              	cin>>n;
              	for (int i =1;i <=n;i++) 
              	{
                  	cin >> a[i].id>>a[i].x; 
              		if(a[i].id==0)  
              		{
              			a[i].id=-1;
              		}     
              	}
              	sort(a+1,a+n+1,cmp);
              
              	for (int i =1;i <=n;i++) 
              	{
                  	s[i]=s[i-1]+a[i].id;     
              	}
              	for (int i =1;i <=n;i++)
              	{
              		for (int j=i+1;j<=n;j++)
              		{
              			if (s[i-1]==s[j])
              			{
              				ans=max(ans,a[j].x-a[i].x);
              			}
              		}
              	}
              	cout << ans;
              }
              
              
              • 1
                @ 2025-3-8 20:01:56

                made in China

                
                #include<bits/stdc++.h>
                using namespace std;
                const int N=1e5+10;
                const int INF=0x3f3f3f3f;
                int a[N],n,m,l,r,ans;
                int s[N];
                int main(){
                	cin>>n>>m;
                	for(int i=1;i<=n;i++)	
                		cin>>a[i];
                	for(int i=1;i<=n;i++)	
                		s[i]=s[i-1]+a[i];
                	for(int i=1;i<=m;i++){
                		cin>>l>>r;
                		cout<<s[r]-s[l-1]<<endl;
                	}
                }
                
                • 1
                  @ 2025-1-26 10:53:59

                  #include<bits/stdc++.h> using namespace std; const int N= 1e6+10; const int INF=0x3f3f3f3f;

                  int n,m,a[N],l,r;

                  int main() { cin>>n>>m; for(int i=1;i<=n;i++) { cin>>a[i]; a[i]+=a[i-1]; } for(int i=1;i<=m;i++) { cin>>l>>r; cout<<a[r]-a[l-1] <<endl; } }

                  • 1
                    @ 2024-10-22 17:04:39
                    #include<iostream>
                    using namespace std;
                    int a[1114514];
                    int sum[1114514];
                    int main()
                    {
                    	int n, m;
                    	cin >> n >> m;
                    	for(int i = 1; i <= n; i++)
                    	{
                    		cin >> a[i];
                    		sum[i] = sum[i-1] + a[i];
                    	}
                    	
                    	for(int i = 1;i <= m; i++)
                    	{
                    		int l,r;
                    		cin >>l >> r;
                    		cout << sum[r] - sum[l-1] << endl;
                    	}
                    	return 0;
                    	}
                    
                  • 0
                    @ 2025-1-26 10:01:10
                    #include<bits/stdc++.h>
                    using namespace std;
                    int n,m,sum[1000005],l,r,a[10000];
                    int main()
                    {    
                        cin>>n>>m;
                        for(int i=1;i<=n;i++) {
                        	cin>>a[i];
                        	sum[i]=sum[i-1]+a[i];
                    	}
                    	while(m--) {
                    		cin>>l>>r;
                    		cout<<sum[r]-sum[l-1]<<"\n";
                    	}
                        return 0;
                    }
                    
                    • 0
                      @ 2024-10-22 17:03:04

                      最简代码

                      #include<bits/stdc++.h>
                      using namespace std;
                      
                      const int N=1e6+10;
                      long long a,b,c,d;
                      int n[N],s[N];
                      
                      int main(){
                      	cin>>a>>b;
                      	for(long long i=1;i<=a;i++){
                      		cin>>n[i];
                      		s[i]=s[i-1]+n[i];
                      	}
                      	for(long long i=1;i<=b;i++){
                      		cin>>c>>d;
                      		cout<<s[d]-s[c-1]<<endl;
                      	}
                      	return 0;
                      }
                      
                      • 0
                        @ 2024-1-19 10:16:09
                        #include<bits/stdc++.h>
                        #define FOR(x,y) for(int i=x;i<=y;i++)
                        using namespace std;
                        const int mod = 998244353; 
                        const int N = 1e6;
                        int n,m,l,r,a[N],b[N];
                        int main (){
                        	cin >> n >> m;
                        	FOR(1,n){
                        		cin>>a[i];
                        		b[i]=b[i-1]+a[i];
                        	}
                        	FOR(1,m){
                        		cin>>l>>r;
                        		cout<<b[r]-b[l-1]<<endl;
                        	}
                        }
                        
                        • 0
                          @ 2023-9-27 20:10:35

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

                          • 0
                            @ 2023-6-16 22:06:58
                            #include <bits/stdc++.h>//直接使用万能头
                            using namespace std;
                            const int N = 1e6 + 10;
                            int a[N],n,m,qzh[N]; 
                            #define int long long
                            signed main(){
                            	cin >> n >> m;
                            	cin >> a[0];
                            	qzh[0] = a[0];
                            	for(int i = 1;i < n;i++){
                            		cin >> a[i];
                            		qzh[i] = qzh[i - 1] + a[i];
                            	}
                            	for(int i = 1;i <= m;i++){
                            		int l,r;
                            		cin >> l >> r;
                            		if(l == 1) cout << qzh[r - 1];
                            		else{
                            			cout << qzh[r - 1] - qzh[l - 2];
                            		}
                            		cout << endl;
                            	}
                            }
                            
                            • 0
                              @ 2023-5-31 19:35:58
                              #include <bits/stdc++.h>
                              using namespace std;
                              const int N=1e6+10;
                              const int INF=0x3f3f3f3f3f;
                              int n,m,a[N],s[N],x,y;
                              int main()
                              {
                              	cin>>n>>m;
                              	for(int i=1;i<=n;i++)
                              	{
                              		cin>>a[i];
                              		s[i]=s[i-1]+a[i];
                              	}
                              	while(m--)
                              	{
                              		cin>>x>>y;
                              		cout<<s[y]-s[x-1]<<endl;
                              	}
                              	return 0;
                              }
                              
                              • 0
                                @ 2023-5-28 20:05:45

                                #include <bits/stdc++.h>

                                using namespace std;

                                longlonga[1000000],sum[1000000];

                                int main(){

                                int n,m,x,y;

                                cin >> n >> m;

                                for(int i = 1 ; i <= n ; i++){

                                cin >> a[i];

                                sum[i] = sum[i - 1] + a[i];

                                }

                                for(int i = 1 ; i <= m ; i++){

                                cin >> x >> y;

                                cout << sum[y] - sum[x - 1]<<endl;

                                }

                                return 0;

                                }``

                              • 0
                                @ 2023-4-30 14:24:40
                                #include <math.h>
                                #include <stack>
                                #include <stdio.h>
                                #include <iostream>
                                #include <vector>
                                #include <iomanip>
                                #include <string.h>
                                #include <algorithm>
                                using namespace std;
                                #define LL long long
                                const int N = 1e6 + 10;
                                const int INF = 0x3f3f3f3f;
                                int a,sum[N],l,r;
                                int main(){
                                	int n,m;
                                	cin >> n >> m;
                                	for (int i=1; i<=n; i++){
                                		cin >> a;
                                		sum[i]=sum[i-1]+a;
                                	}
                                	while(m--){
                                		cin >> l>>r;
                                		cout << sum[r]-sum[l-1] << " "<<endl;
                                		
                                	}
                                	return 0;
                                }
                                
                                • 0
                                  @ 2022-12-19 12:18:08
                                  #include<iostream>
                                  #include<cstdio>
                                  #include<cstdlib>
                                  #include<cstring>
                                  #include<cmath>
                                  #include<algorithm>
                                  using namespace std;
                                  int n,sum,j,s[1000001],a[1000001];
                                  int main()
                                  {
                                      cin>>n>>j;
                                  	for(int i=1;i<=n;i++){
                                  		cin>>a[i];
                                  		s[i]=s[i-1]+a[i];
                                  	}    
                                      while(j--){
                                      	int l,r;
                                      	scanf("%d%d",&l,&r);
                                      	cout<<s[r]-s[l-1]<<endl;
                                  	}
                                      return 0;
                                  }
                                  
                                  • -1
                                    @ 2024-10-22 17:05:03

                                    little bird little bird

                                    #include<bits/stdc++.h>
                                    using namespace std;
                                    int n,m,f[1000005],x,y;
                                    int main()
                                    {    
                                        cin>>n>>m;
                                        for(int i=1;i<=n;i++) {
                                        	cin>>x;
                                        	f[i]=f[i-1]+x;
                                    	}
                                    	while(m--) {
                                    		cin>>x>>y;
                                    		cout<<f[y]-f[x-1]<<"\n";
                                    	}
                                        return 0;
                                    }
                                    版权费1元,违者必究
                                    

                                  信息

                                  ID
                                  1284
                                  时间
                                  1000ms
                                  内存
                                  256MiB
                                  难度
                                  7
                                  标签
                                  递交数
                                  1158
                                  已通过
                                  298
                                  上传者