A More Complicated Example of Prefix Sums
What if we want to quickly answer the following type of query?
Find .
In addition to taking prefix sums over , we'll also need to take prefix sums over .
First, define the following:
Then, we have:
And so,
Which is what we were looking for!
Problem Solution
This problem requires slight extensions of the above approach. See the Official Analysis for more information.
#include <bits/stdc++.h>using namespace std;const int maxN = 2e5 + 5;int n, q;int ar[maxN];vector<long long> ipsEven(maxN), ipsOdd(maxN), psEven(maxN), psOdd(maxN);
Join the USACO Forum!
Stuck on a problem, or don't understand a module? Join the USACO Forum and get help from other competitive programmers!