Explanation
Let's consider when we've added two equations to it, .
From this, we can make two observations.
- In the expanded equation, is just multiplied by all of its coefficients.
- Any constant is multiplied by all future coefficients.
We can calculate all of this on the fly as we process "add" and "compute" queries, but how do we deal with "removal" queries under a modulus?
Handling Removal Queries
Implementation
Time Complexity:
C++
#include <bits/stdc++.h>using namespace std;using ll = long long;const ll MOD = 998244353;// source: https://usaco.guide/gold/modular#solution---exponentiationll bin_exp(ll x, ll n) {assert(n >= 0);
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!