QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#611778 | #8527. Power Divisions | zhouyuhang | WA | 499ms | 68704kb | C++14 | 1.6kb | 2024-10-04 22:40:45 | 2024-10-04 22:40:45 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 3e5 + 10, M = 1e6 + 30, P = 1e9 + 7;
const ll mod = 1e18 + 3;
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]]) % mod) mp[s] = i;
clear();
for (ll i = mid, s = pw[a[i]]; i >= l; s = (s + pw[a[--i]]) % mod) {
add(a[i]); ll v = (pw[hb + 1] + mod - s) % mod;
if (mp.count(v)) vec[mp[v]].push_back(i);
}
mp.clear();
for (ll i = mid, s = pw[a[i]]; i >= l; s = (s + pw[a[--i]]) % mod) mp[s] = i;
clear();
for (ll i = mid + 1, s = pw[a[i]]; i <= r; s = (s + pw[a[++i]]) % mod) {
add(a[i]); ll v = (pw[hb + 1] + mod - s) % mod;
if (mp.count(v)) vec[i].push_back(mp[v]);
}
}
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 + 20; ++i) pw[i] = 2 * pw[i - 1] % mod;
solve(1, n);
dp[0] = 1;
for (int i = 1; i <= n; ++i) {
sort(vec[i].begin(), vec[i].end());
vec[i].erase(unique(vec[i].begin(), vec[i].end()), vec[i].end());
for (auto &p: vec[i]) dp[i] = (dp[i] + dp[p - 1]) % P; // cerr << p << ' ' << i << endl;
}
cout << dp[n] << endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 19944kb
input:
5 2 0 0 1 1
output:
6
result:
ok 1 number(s): "6"
Test #2:
score: 0
Accepted
time: 3ms
memory: 20112kb
input:
1 0
output:
1
result:
ok 1 number(s): "1"
Test #3:
score: 0
Accepted
time: 3ms
memory: 19992kb
input:
2 1 1
output:
2
result:
ok 1 number(s): "2"
Test #4:
score: 0
Accepted
time: 3ms
memory: 20564kb
input:
3 2 1 1
output:
3
result:
ok 1 number(s): "3"
Test #5:
score: 0
Accepted
time: 7ms
memory: 20144kb
input:
4 3 2 2 3
output:
4
result:
ok 1 number(s): "4"
Test #6:
score: 0
Accepted
time: 6ms
memory: 19992kb
input:
5 3 4 4 2 4
output:
2
result:
ok 1 number(s): "2"
Test #7:
score: 0
Accepted
time: 3ms
memory: 19968kb
input:
7 3 4 3 5 6 3 4
output:
6
result:
ok 1 number(s): "6"
Test #8:
score: 0
Accepted
time: 3ms
memory: 20008kb
input:
10 8 6 5 6 7 8 6 8 9 9
output:
4
result:
ok 1 number(s): "4"
Test #9:
score: 0
Accepted
time: 3ms
memory: 20016kb
input:
96 5 1 0 2 5 5 2 4 2 4 4 2 3 4 0 2 1 4 3 1 2 0 2 2 3 2 4 5 3 5 2 0 2 2 5 3 0 4 5 3 5 4 4 3 1 2 0 5 4 5 0 2 3 2 4 0 0 4 2 0 2 5 3 3 1 5 5 1 1 1 0 5 0 3 0 2 1 1 0 5 0 3 3 4 4 5 3 0 2 2 0 5 4 5 0 5
output:
11332014
result:
ok 1 number(s): "11332014"
Test #10:
score: 0
Accepted
time: 3ms
memory: 20820kb
input:
480 2 0 4 4 1 0 0 3 1 1 4 2 5 5 4 2 1 2 4 4 1 3 4 3 0 5 2 0 2 5 1 0 5 0 0 5 5 0 2 5 2 2 3 1 4 3 5 4 5 2 4 4 4 4 1 4 0 3 4 3 4 1 0 4 3 4 5 4 3 5 0 2 2 0 1 5 4 4 2 0 3 3 3 4 3 0 5 5 3 1 5 1 0 1 0 4 3 0 5 1 4 1 4 3 0 1 3 5 0 3 3 1 0 4 1 1 2 0 1 2 0 3 5 2 0 5 5 5 5 3 5 1 0 2 5 2 2 0 2 0 2 3 5 1 2 1 5 4 ...
output:
506782981
result:
ok 1 number(s): "506782981"
Test #11:
score: 0
Accepted
time: 6ms
memory: 20668kb
input:
2400 0 2 2 0 5 4 3 2 3 2 5 4 5 4 4 5 2 2 4 2 2 0 1 0 5 0 4 4 0 0 5 0 4 0 1 3 4 5 0 3 1 0 4 0 2 5 0 3 3 3 3 1 0 5 5 3 1 3 5 2 4 0 5 0 4 5 4 2 2 1 5 2 2 4 1 0 5 1 5 0 1 2 0 0 3 5 4 0 0 1 1 1 4 2 0 5 1 3 3 5 0 4 4 1 5 5 3 4 4 4 0 2 4 0 5 1 3 1 5 0 5 5 1 3 0 3 1 2 0 1 1 3 5 2 3 4 0 3 0 5 4 0 4 3 5 0 5 2...
output:
586570528
result:
ok 1 number(s): "586570528"
Test #12:
score: 0
Accepted
time: 20ms
memory: 20732kb
input:
12000 2 2 1 2 0 2 5 3 2 0 1 3 2 5 4 0 0 5 3 2 0 2 3 4 3 2 1 4 3 0 3 5 4 1 0 2 4 1 3 2 3 5 0 3 0 0 4 0 4 5 1 0 4 1 1 1 5 4 3 0 3 5 4 5 2 5 0 1 2 3 5 5 2 5 4 2 0 4 4 3 0 0 2 5 0 3 4 2 5 4 2 1 4 5 1 1 2 3 0 3 3 3 3 4 0 5 3 4 0 3 0 2 0 0 2 0 3 4 2 2 0 1 0 5 3 0 2 0 2 2 1 0 5 3 5 4 5 5 0 4 0 4 1 4 4 3 2 ...
output:
201653965
result:
ok 1 number(s): "201653965"
Test #13:
score: 0
Accepted
time: 81ms
memory: 24260kb
input:
60000 2 5 0 3 2 3 5 3 5 5 4 1 1 5 3 0 1 1 2 5 5 5 0 3 2 0 3 2 3 3 0 0 1 4 3 1 4 2 3 3 0 5 1 0 1 1 5 5 4 0 5 4 1 3 1 3 5 3 2 4 4 4 5 4 3 2 3 2 4 5 2 0 4 5 1 2 0 4 0 5 1 3 4 1 2 4 1 1 3 3 0 1 1 3 0 0 2 3 3 2 1 4 1 2 4 3 3 5 2 5 3 4 3 0 2 1 1 1 5 1 2 4 2 3 1 2 1 0 2 0 1 1 5 5 3 4 2 5 2 4 5 3 0 5 1 4 2 ...
output:
592751350
result:
ok 1 number(s): "592751350"
Test #14:
score: 0
Accepted
time: 472ms
memory: 38356kb
input:
300000 0 5 1 5 5 4 5 3 0 5 0 5 1 4 1 2 2 2 3 0 1 5 4 0 3 1 4 5 2 1 0 3 2 1 2 5 0 2 4 5 0 1 2 1 1 0 0 5 3 0 0 3 4 5 0 2 1 1 1 2 5 1 4 3 1 0 2 0 0 4 3 3 2 5 3 3 1 5 2 0 2 4 3 1 0 3 4 1 3 3 1 0 0 1 1 1 3 1 2 3 5 3 3 2 0 3 0 0 5 5 0 0 0 0 1 4 3 3 4 3 4 5 3 3 5 1 1 4 2 2 1 3 2 1 1 0 0 5 5 0 0 3 2 4 5 5 2...
output:
842503795
result:
ok 1 number(s): "842503795"
Test #15:
score: 0
Accepted
time: 378ms
memory: 68704kb
input:
300000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
output:
432100269
result:
ok 1 number(s): "432100269"
Test #16:
score: 0
Accepted
time: 459ms
memory: 68704kb
input:
300000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 10000...
output:
432100269
result:
ok 1 number(s): "432100269"
Test #17:
score: 0
Accepted
time: 499ms
memory: 53176kb
input:
299995 1 1 0 0 0 1 0 0 1 1 0 1 0 1 0 0 1 1 0 0 1 1 1 0 1 1 0 0 1 0 0 1 1 0 1 0 1 0 0 1 1 1 1 1 1 1 1 1 0 0 0 0 1 1 1 1 1 1 0 0 1 0 1 1 1 0 0 1 1 0 1 0 1 1 0 1 0 1 0 1 0 1 1 0 1 0 0 0 0 0 0 1 0 1 1 0 1 1 1 1 0 1 1 1 1 0 0 0 0 0 1 0 1 1 0 0 0 1 0 0 1 1 0 0 1 1 1 1 1 1 0 1 1 0 0 1 0 0 1 0 1 0 1 1 0 0 0...
output:
261818019
result:
ok 1 number(s): "261818019"
Test #18:
score: 0
Accepted
time: 446ms
memory: 37504kb
input:
299997 2 2 0 9 4 4 2 3 8 9 3 9 1 6 4 0 1 5 1 0 7 9 3 3 8 9 3 8 3 6 9 3 9 5 9 1 4 4 7 5 9 0 7 3 7 2 0 3 3 8 2 1 7 6 8 1 6 1 8 4 7 6 3 6 1 6 8 9 3 8 1 5 0 8 1 10 0 3 4 5 8 5 6 9 2 4 5 0 9 0 9 5 1 0 3 7 5 8 8 10 10 3 3 10 5 8 9 9 7 4 4 1 1 6 5 7 2 5 8 3 3 9 6 4 1 0 2 6 2 8 7 7 10 5 7 8 3 8 5 1 6 6 6 1 ...
output:
999738318
result:
ok 1 number(s): "999738318"
Test #19:
score: 0
Accepted
time: 441ms
memory: 37628kb
input:
299999 97 34 33 30 15 73 31 69 60 63 79 87 78 13 49 58 23 38 91 28 70 70 14 98 56 59 81 66 29 21 10 51 94 32 41 98 16 48 67 62 55 5 17 81 30 91 39 93 73 74 46 74 41 99 19 10 0 16 72 95 84 40 97 17 76 10 42 50 66 97 4 30 71 74 46 5 75 87 55 82 38 94 14 82 49 10 23 21 19 99 52 100 71 29 64 73 54 88 2 ...
output:
799664563
result:
ok 1 number(s): "799664563"
Test #20:
score: 0
Accepted
time: 429ms
memory: 37428kb
input:
299997 97 181 693 569 34 770 725 1 82 951 965 962 962 532 803 824 669 686 529 339 434 430 439 478 553 354 443 632 725 139 56 709 797 847 617 100 837 94 80 527 644 861 8 455 710 599 473 818 685 886 645 722 239 634 450 16 825 337 156 708 827 790 462 716 67 557 535 466 820 465 567 140 633 112 85 691 16...
output:
152812109
result:
ok 1 number(s): "152812109"
Test #21:
score: 0
Accepted
time: 424ms
memory: 37408kb
input:
300000 7938 3542 362 8246 5914 9327 9031 9802 6879 5983 1052 8554 8571 187 3412 4806 1991 9465 7940 8741 5792 7136 6654 7716 2896 4212 3357 6278 3398 5631 4759 6295 7385 5487 699 3015 422 4849 4933 3169 3194 7014 7605 9619 8126 4673 5020 842 9477 2925 857 1263 3326 729 4638 3383 7716 887 7821 2009 7...
output:
294967268
result:
ok 1 number(s): "294967268"
Test #22:
score: 0
Accepted
time: 428ms
memory: 37520kb
input:
300000 68003 20603 19535 98755 78166 31928 28492 76831 77102 95079 32154 12348 91482 11514 67510 4208 30189 31364 77353 60045 60124 58954 32468 38599 70247 18763 32984 76656 86646 79971 63986 68195 33578 90458 79520 92707 17642 7744 26043 12273 28374 63264 97058 36502 6212 70591 51401 76682 41512 18...
output:
32
result:
ok 1 number(s): "32"
Test #23:
score: -100
Wrong Answer
time: 380ms
memory: 35260kb
input:
299995 704135 597658 946639 146393 887400 976091 33440 872707 692148 819088 785763 285388 604527 830260 851525 558807 997790 380755 251183 328941 129356 741341 530638 817968 603319 899844 731899 356842 867124 825330 645685 373685 70290 726706 995759 161401 398693 132928 535725 831104 643517 149954 7...
output:
537950553
result:
wrong answer 1st numbers differ - expected: '1', found: '537950553'