DMOJ - Bob Equilibrium
Author: Benjamin Qi
Appears In
Time Complexity:
Using centroid decomposition, we can
- Update the value at some vertex in time
- Query the sum of the values of all vertices that are distance exactly away from some vertex in time.
You can check the second approach for USACO At Large for an explanation of how to do this.
What we need for this problem is slightly different; first we need to process some number of updates of the following form:
- Add 1 to the values of all vertices at most away from some vertex .
And then output the values at all vertices at the end. We can use prefix sums for this.
(Note: quite close to TL ...)
#include <bits/stdc++.h>using namespace std;using ll = long long;using ld = long double;using db = double;using str = string; // yay python!using pi = pair<int,int>;using pl = pair<ll,ll>;
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!