QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#446305 | #8527. Power Divisions | ucup-team3215 | TL | 0ms | 0kb | C++20 | 1.8kb | 2024-06-17 07:03:45 | 2024-06-17 07:03:46 |
answer
#include <bits/stdc++.h>
using namespace std;
constexpr int N = 3e5 + 1, exps[]{61, 13, 12, 11, 10};
using E = array<uint64_t, size(exps)>;
constexpr uint64_t mod = -49ull / 2;
template <int i>
struct um: conditional_t<i == size(exps), vector<int>, unordered_map<uint64_t, um<i + 1>>> { };
um<0> m;
vector<int> ls[N];
template <int i = 0>
auto& mget(const E& e, auto& m) {
if constexpr (i == size(exps)) return m;
else return mget<i + 1>(e, m[e[i]]);
}
template <int i = 0>
void walk(const E& e, auto& m, uint64_t k, uint64_t pr, auto f) {
if constexpr (i == size(exps)) f(m, k, pr);
else {
uint64_t step = pr;
while (step % exps[i] != 1) step += pr;
while (k % exps[i]) k += pr;
pr *= exps[i];
for (int j = 0; j < exps[i]; ++j) {
auto it = m.find((e[i] + (1ull << exps[i]) - 1 - (1ull << j)) % ((1ull << exps[i]) - 1));
if (it != m.end()) walk<i + 1>(e, it->second, k, pr, f);
k = (k + step) % pr;
}
}
}
int dp[N];
uint64_t pw[(int)1.1e6];
uint64_t pss[N];
int main() {
cin.tie(0)->sync_with_stdio(0);
pw[0] = 1;
for (uint64_t i = 1, p = 2; i < size(pw); ++i) pw[i] = p, p = (p + p) % mod;
int n; cin >> n;
E ps{};
uint64_t psm{};
for (int i = 0; ; ++i) {
mget(ps, m).push_back(i);
walk(ps, m, 0, 1, [&](auto& v, auto k, auto p) { for (auto& j: v) if (pss[j] == (psm + mod - pw[k]) % mod) ls[i].push_back(j); });
pss[i] = psm;
if (i == n) break;
int v; cin >> v;
for (int j = 0; j < size(exps); ++j) ps[j] = (ps[j] + (1ull << v % exps[j])) % ((1ull << exps[j]) - 1);
psm = (psm + pw[v]) % mod;
}
dp[0] = 1;
for (int i = 1; i <= n; ++i)
for (auto j: ls[i]) dp[i] = (dp[i] + dp[j]) % ((int)1e9 + 7);
cout << dp[n];
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Time Limit Exceeded
input:
5 2 0 0 1 1