15 条题解
-
2涂星哲 (xingcode) LV 6 @ 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!!! *****************************/
-
22023-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; }
-
12023-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; }
-
12021-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; }
-
02024-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元,违者必究
-
02024-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; }
-
02024-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; }
-
02024-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; } }
-
02023-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; } }
-
02023-5-31 19:39:05@
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<iomanip> #include<algorithm> #include<string> #include<stack> using namespace std; const int N=1e6+10; const int INF=0x3f3f3f3f; int n,m,a[N],s[N],x,y,ans; 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; }
-
02023-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; }
-
02023-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;
}``
-
02023-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; }
-
02022-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; }
-
02022-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
信息
- ID
- 1284
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 7
- 标签
- 递交数
- 888
- 已通过
- 237
- 上传者