- C++
哪位大佬可以帮我一下???急!!!
- 2023-1-7 14:25:53 @
【深进1.例1】求区间和怎么做?
2 条评论
-
hejinming LV 6 @ 2023-5-15 17:58:38
#include <bits/stdc++.h> using namespace std; inline int read() { int x=0,f=1;char ch=getchar(); while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();} while (isdigit(ch)){x=x10+ch-48;ch=getchar();} return xf; } int n,m,a[100050],s[100050]; int main() { n=read(); for (int i=1;i<=n;i++) s[i]=s[i-1]+(a[i]=read()); m=read(); for (int i=1;i<=m;i++) { int l=read(),r=read(); cout << s[r]-s[l-1] << endl; } return 0; }
-
2023-1-29 15:27:36@
前缀和
- 1