So I just finished reading Silver > Prefix Sums, and I understand the concept. But I’m a little confused regarding the syntax of c++. Below is the Guide’s code for reference:
#include <bits/stdc++.h>
using namespace std;
#define sz(x) (int)size(x)
using ll = long long;
using vl = vector<ll>;
vl psum(const vl& a) {
vl psum(sz(a)+1);
for (int i = 0; i < sz(a); ++i)
psum[i+1] = psum[i]+a[i];
// or partial_sum(begin(a),end(a),begin(psum)+1);
return psum;
}
int main() {
for (ll i: psum({1,2,3,4,5}))
cout << i << " ";
// 0 1 3 6 10 15
}
- Can you please explain what the “vl” part of “vl psum” method header means. I’m assuming vl is used to state that the method is returning a vector, but not 100% sure.
- Can you please explain why the method input has a & in it. I’ve seen this & before in other c++ code, but I don’t understand why you use the &.
Thanks for your help!