[Algorithms] KamaCoder 58. 区间和(第九期模拟笔试)
Categories Algorithms Array
Tags
来源:代码随想录
前缀和的思想。
#include <bits/stdc++.h>
using namespace std;
int main(void) {
int n;
cin >> n;
vector<int> v(n);
for (int i = 0; i < n; i++) {
cin >> v[i];
}
for (int i = 1; i < n; i++) {
v[i] += v[i - 1];
}
int a, b;
while (cin >> a >> b) {
if (a == 0) {
cout << v[b] << endl;
} else {
cout << v[b] - v[a - 1] << endl;
}
}
}
Page views: Loading... · Visitors: Loading...
Except where otherwise noted, original content on this site is dedicated to the public domain under CC0 1.0.
Powered by Hexo & Theme mdsuper
沪ICP备2026040813号