QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#610352 | #8527. Power Divisions | zhouyuhang | WA | 8ms | 20412kb | C++14 | 1.2kb | 2024-10-04 15:41:11 | 2024-10-04 15:41:12 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 3e5 + 10, M = 1e6 + 20, P = 1e9 + 7;
const ll mod = 1e18 + 9;
int n;
int a[N];
ll pw[M];
int s[N], hb; vector<int> pos;
void add(int p) {
while (s[p]) s[p++] = 0;
s[p] = 1, hb = max(hb, p);
pos.push_back(p);
}
void clear() {
for (auto &p: pos) s[p] = 0;
hb = 0, pos.clear();
}
vector<int> vec[N];
void solve(int l, int r) {
if (l == r) {
vec[r].push_back(l);
return;
}
int mid = (l + r) >> 1;
solve(l, mid), solve(mid + 1, r);
unordered_map<ll, int> mp; mp.reserve(r - mid);
for (ll i = mid + 1, s = pw[a[i]]; i <= r; s = (s + pw[a[++i]]) % P) mp[s] = i;
clear();
for (ll i = mid, s = pw[a[i]]; i >= l; s = (s + pw[a[--i]]) % P) {
add(a[i]); ll v = (pw[hb + 1] + P - s) % P;
if (mp.count(v)) vec[mp[v]].push_back(i);
}
}
int dp[N];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for (int i = 1; i <= n; ++i) cin >> a[i];
pw[0] = 1;
for (int i = 1; i <= 1e6 + 18; ++i) pw[i] = 2 * pw[i - 1] % P;
solve(1, n);
dp[0] = 1;
for (int i = 1; i <= n; ++i) {
for (auto &p: vec[i]) dp[i] = (dp[i] + dp[p - 1]) % P;
}
cout << dp[n] << endl;
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 20300kb
input:
5 2 0 0 1 1
output:
6
result:
ok 1 number(s): "6"
Test #2:
score: 0
Accepted
time: 8ms
memory: 20412kb
input:
1 0
output:
1
result:
ok 1 number(s): "1"
Test #3:
score: 0
Accepted
time: 0ms
memory: 19900kb
input:
2 1 1
output:
2
result:
ok 1 number(s): "2"
Test #4:
score: 0
Accepted
time: 7ms
memory: 20164kb
input:
3 2 1 1
output:
3
result:
ok 1 number(s): "3"
Test #5:
score: -100
Wrong Answer
time: 7ms
memory: 20120kb
input:
4 3 2 2 3
output:
3
result:
wrong answer 1st numbers differ - expected: '4', found: '3'