QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#559494 | #8527. Power Divisions | FDUdululu | WA | 9ms | 28204kb | C++14 | 2.9kb | 2024-09-11 22:28:30 | 2024-09-11 22:28:34 |
Judging History
answer
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <unordered_map>
#include <vector>
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
const ll seed = 31;
const int N = 3e5 + 50;
const ll P = (1ll << 61) - 1;
int n, a[N];
ll coef[N << 1], sum[N << 1];
int pre[N], suf[N];
unordered_map<ll, int> vis;
int sta[N << 1], top;
vector<int> seq[N];
ll f[N];
int flag[N];
void calc(int l, int r, int d) {
if (l == r) {
seq[r].push_back(l);
return;
}
int mid = (l + r) >> 1;
calc(l, mid, d);
calc(mid + 1, r, d);
ll sufhash = 0;
for (int i = mid; i >= l; i--) {
int cur = a[i];
while (suf[cur]) {
suf[cur] = 0;
sufhash = (sufhash - coef[cur] + P) % P;
cur++;
}
suf[cur] = 1;
sufhash = (sufhash + coef[cur]) % P;
sta[++top] = cur;
vis[sufhash] = i;
}
while (top)
suf[sta[top--]] = 0;
ll prehash = 0;
int minn = N, maxn = 0;
for (int i = mid + 1; i <= r; i++) {
int cur = a[i];
while (pre[cur]) {
pre[cur] = 0;
prehash = (prehash - coef[cur] + P) % P;
cur++;
}
pre[cur] = 1;
maxn = max(maxn, cur);
minn = min(minn, cur);
while (!pre[minn])
minn++;
prehash = (prehash + coef[cur]) % P;
sta[++top] = cur;
ll val = sum[maxn];
if (minn)
val = (val - sum[minn - 1] + P) % P;
val = (val + coef[minn]) % P;
val = (val - prehash + P) % P;
if (vis.count(val)) {
if (d)
seq[n - vis[val] + 1].push_back(n - i + 1);
else
seq[i].push_back(vis[val]);
}
}
while (top)
pre[sta[top--]] = 0;
vis.clear();
}
void solve() {
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
ll mul = 1;
for (int i = 0; i < (N << 1); i++)
coef[i] = i;
random_shuffle(coef + 1, coef + N);
for (int i = 0; i < (N << 1); i++) {
coef[i] = coef[i] * mul % mod;
sum[i] = coef[i];
if (i)
sum[i] = (sum[i] + sum[i - 1]) % mod;
mul = mul * seed % mod;
}
calc(1, n, 0);
reverse(a + 1, a + n + 1);
calc(1, n, 1);
f[0] = 1;
for (int i = 1; i <= n; i++) {
for (auto j : seq[i]) {
if (flag[j])
continue;
f[i] = (f[i] + f[j - 1]) % mod;
flag[j] = 1;
}
for (auto j : seq[i])
flag[j] = 0;
}
cout << f[n] << "\n";
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int T = 1;
// cin >> T;
while (T--) {
solve();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 7ms
memory: 26572kb
input:
5 2 0 0 1 1
output:
6
result:
ok 1 number(s): "6"
Test #2:
score: 0
Accepted
time: 5ms
memory: 28204kb
input:
1 0
output:
1
result:
ok 1 number(s): "1"
Test #3:
score: 0
Accepted
time: 7ms
memory: 26136kb
input:
2 1 1
output:
2
result:
ok 1 number(s): "2"
Test #4:
score: 0
Accepted
time: 9ms
memory: 24764kb
input:
3 2 1 1
output:
3
result:
ok 1 number(s): "3"
Test #5:
score: 0
Accepted
time: 9ms
memory: 26156kb
input:
4 3 2 2 3
output:
4
result:
ok 1 number(s): "4"
Test #6:
score: -100
Wrong Answer
time: 9ms
memory: 26348kb
input:
5 3 4 4 2 4
output:
1
result:
wrong answer 1st numbers differ - expected: '2', found: '1'