Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <assert.h>
- #include <bits/stdc++.h>
- using namespace std;
- template <class T> using mpq = priority_queue<T, vector<T>, greater<T>>;
- using ll = long long;
- using pii = pair<int, int>;
- using pll = pair<ll, ll>;
- using vl = vector<ll>;
- using vi = vector<int>;
- using ul = unsigned long;
- using vul = vector<ul>;
- vi layer;
- pii get_rc(int a)
- {
- int r = upper_bound(layer.begin(), layer.end(), a) - layer.begin() - 1;
- int c = a - layer[r] + 1;
- return {r, c};
- }
- int main(int argc, char **argv)
- {
- int t;
- cin >> t;
- vector<vul> dp(1 << 11, vul(1 << 11));
- for (int i = 2023; i > 0; --i) {
- for (int j = 1; j <= i; ++j) {
- ul curr = i * (i - 1) / 2 + j;
- dp[i][j] = dp[i + 1][j] + dp[i + 1][j + 1] - dp[i + 2][j + 1] + curr * curr;
- }
- }
- // cerr << dp[1][1] << endl;
- // assert(dp[1][1] == 286'0278'0236'2646'4826ul);
- layer = vi(1 << 11);
- for (int i = 1; i <= 2023; ++i)
- layer[i] = i * (i - 1) / 2 + 1;
- while (t--) {
- int n;
- cin >> n;
- auto [r, c] = get_rc(n);
- int r1 = r, c1 = c - 1;
- int r2 = r, c2 = c + 1;
- if (c1 >= 1)
- r1 -= c1 - 1, c1 = 1;
- else
- c1 = c, r1 = r + 1;
- if (c2 <= r2)
- r2 = c2;
- else
- r2 = r + 1;
- ll ans = dp[1][1] - dp[r1][c1] - dp[r2][c2] + dp[r + 2][c + 1];
- cout << ans << endl;
- }
- return 0;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement