用它求中间三个数的和
同一张表,求下标 1 到 3 的和。运行下面这段程序:
#include <iostream>
#include <string>
#include <vector>
using namespace std;
vector<long long> build_prefix(const vector<int>& a) {
vector<long long> p;
long long s = 0;
for (int x : a) {
s += x;
p.push_back(s);
}
return p;
}
int main() {
vector<long long> p = build_prefix({17, 24, 15, 13, 23});
cout << p[3] - p[0] << endl;
}
(本题用 g++ -std=c++17 -O0 编译。)