QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#447050 | #8527. Power Divisions | ucup-team3215 | WA | 3ms | 15872kb | C++20 | 3.0kb | 2024-06-17 20:45:35 | 2024-06-17 20:45:37 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
constexpr int N = 3e5 + 1, exps[]{37, 11, 9, 8, 7, 5};
using E = array<uint64_t, size(exps)>;
constexpr uint64_t mod = -49ull / 2;
uint64_t splitmix(uint64_t x) {
(x ^= x >> 27) *= 0x94d049bb133111eb;
return x ^ (x >> 31);
}
template <typename V>
struct umap {
vector<uint64_t> keys;
vector<V> vals;
vector<uint32_t> nx;
vector<uint32_t> head;
int cap{};
umap() { reserve(); }
int find(uint64_t k) { for (int i = head[splitmix(k) & cap]; ~i; i = nx[i]) if (keys[i] == k) return i; return -1; }
int insert(uint64_t k) {
auto kk = splitmix(k) & cap;
for (int i = head[kk]; ~i; i = nx[i]) if (keys[i] == k) return i;
reserve();
nx.push_back(head[kk]);
head[kk] = keys.size();
keys.push_back(k);
vals.push_back({});
return vals.size() - 1;
}
void reserve() {
if (keys.size() * 4 < cap) return;
cap = max(cap * 2 + 1, 7);
head.assign(cap + 1, -1);
nx.clear();
for (int i = 0; i < keys.size(); ++i) {
nx.push_back(head[splitmix(keys[i]) & cap]);
head[keys[i] & cap] = i;
}
}
};
template <int i>
struct um: conditional_t<i == size(exps), vector<int>, umap<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.vals[m.insert(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];
if (m.vals.size() != 1)
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) walk<i + 1>(e, m.vals[it], k, pr, f);
k = (k + step) % pr;
}
else if (auto& ke = m.keys[0]; 1) if (auto& v = m.vals[0]; 1)
for (int j = 0; j < exps[i]; ++j) {
if ((e[i] + (1ull << exps[i]) - 1 - (1ull << j)) % ((1ull << exps[i]) - 1) == ke) walk<i + 1>(e, v, 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];
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 3ms
memory: 15872kb
input:
5 2 0 0 1 1
output:
3
result:
wrong answer 1st numbers differ - expected: '6', found: '3'