QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#444812 | #8527. Power Divisions | ucup-team1198# | WA | 1130ms | 74224kb | C++20 | 4.9kb | 2024-06-15 21:28:56 | 2024-06-15 21:28:57 |
Judging History
answer
#include <map>
#include <set>
#include <array>
#include <cmath>
#include <deque>
#include <bitset>
#include <random>
#include <string>
#include <vector>
#include <cassert>
#include <complex>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
using namespace std;
const int MOD = 1e9 + 7;
int add(int a, int b) {
if (a + b < MOD)
return a + b;
return a + b - MOD;
}
int sub(int a, int b) {
if (a >= b)
return a - b;
return a + MOD - b;
}
int mul(int a, int b) {
return a * 1ll * b % MOD;
}
const int BASE = 2;
const int MAXN = (1 << 20) + 228;
int BASEPOW[MAXN];
int POWSUM[MAXN];
vector<int> from[MAXN];
int vals[MAXN];
int cur_hash = 0;
int cur_mn = -1;
int cur_mx = -1;
int inv_hash = 0;
vector<int> upds;
void add_bit(int i) {
//cerr << "add_bit " << i << ' ';
if (cur_mn == -1) {
upds.emplace_back(i);
vals[i] = 1;
cur_mn = i;
cur_mx = i;
cur_hash = BASEPOW[i];
inv_hash = BASEPOW[i];
} else {
inv_hash = sub(inv_hash, BASEPOW[cur_mn]);
int l = i;
while (vals[l] != 0) {
upds.emplace_back(l);
vals[l] ^= 1;
cur_hash = sub(cur_hash, BASEPOW[l]);
if (i != cur_mn)
inv_hash = add(inv_hash, BASEPOW[l]);
++l;
}
vals[l] ^= 1;
upds.emplace_back(l);
cur_hash = add(cur_hash, BASEPOW[l]);
if (l > cur_mx) {
if (l == i) {
inv_hash = add(inv_hash, sub(POWSUM[i], POWSUM[cur_mx + 1]));
}
cur_mx = l;
} else {
inv_hash = sub(inv_hash, BASEPOW[l]);
}
if (i == cur_mn) {
cur_mn = l;
} else if (i < cur_mn) {
inv_hash = add(inv_hash, sub(POWSUM[cur_mn], POWSUM[i]));
cur_mn = i;
}
inv_hash = add(inv_hash, BASEPOW[cur_mn]);
}
/*cerr << "\nhave: ";
for (int j = 0; j < 15; ++j)
cerr << ((cur_hash >> j) & 1);
cerr << "\nneed: ";
for (int j = 0; j < 15; ++j)
cerr << ((inv_hash >> j) & 1);
cerr << '\n';*/
}
void clear() {
for (int i : upds)
vals[i] = 0;
upds.clear();
cur_mn = -1;
cur_mx = -1;
cur_hash = 0;
inv_hash = 0;
//cerr << "cleared\n";
}
int A[MAXN];
void go_down(int left, int right) {
if (left + 1 == right)
return;
int mid = (left + right) / 2;
go_down(left, mid);
go_down(mid, right);
vector<pair<int, int>> hashes(right - left);
clear();
for (int i = mid - 1; i >= left; --i) {
add_bit(A[i]);
hashes[i - left] = make_pair(cur_hash, inv_hash);
}
clear();
map<int, int> id;
for (int i = mid; i < right; ++i) {
add_bit(A[i]);
hashes[i - left] = make_pair(cur_hash, inv_hash);
id[cur_hash] = i;
}
for (int i = mid - 1; i >= left; --i) {
int need = hashes[i - left].second;
if (id.count(need)) {
//cout << left << ' ' << mid << ' ' << right << ' ' << i << " - " << id[need] << ' ' << hashes[i - left].second << ',' << hashes[i - left].first << '\n';
from[id[need] + 1].emplace_back(i);
}
}
id.clear();
for (int i = mid - 1; i >= left; --i) {
id[hashes[i - left].first] = i;
}
for (int i = mid; i < right; ++i) {
int need = hashes[i - left].second;
if (id.count(need)) {
//cout << left << ' ' << mid << ' ' << right << ' ' << id[need] << " - " << i << ' ' << hashes[i - left].second << ',' << hashes[i - left].first << '\n';
from[i + 1].emplace_back(id[need]);
}
}
}
bool is_2pow(long long x) {
while (x != 1) {
if (x & 1)
return false;
x >>= 1;
}
return x == 1;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
BASEPOW[0] = 1;
for (int i = 1; i < MAXN; ++i)
BASEPOW[i] = mul(BASEPOW[i - 1], BASE);
POWSUM[0] = 0;
for (int i = 1; i < MAXN; ++i)
POWSUM[i] = add(POWSUM[i - 1], BASEPOW[i - 1]);
int n;
cin >> n;
for (int i = 0; i < n; ++i)
cin >> A[i];
go_down(0, n);
for (int i = 0; i < n; ++i) {
from[i + 1].emplace_back(i);
}
vector<int> dp(n + 1);
dp[0] = 1;
for (int i = 1; i <= n; ++i) {
sort(from[i].begin(), from[i].end());
from[i].resize(unique(from[i].begin(), from[i].end()) - from[i].begin());
for (int j : from[i]) {
//cout << j << ',' << i << '\n';
dp[i] = add(dp[i], dp[j]);
}
/*vector<int> should;
long long sum = 0;
for (int j = i - 1; j >= 0; --j) {
sum += 1ll << A[j];
if (is_2pow(sum))
should.emplace_back(j);
}
reverse(should.begin(), should.end());
if (from[i] != should) {
cerr << i << '\n';
for (int x : from[i])
cerr << x << ' ';
cerr << '\n';
for (int x : should)
cerr << x << ' ';
cerr << '\n';
for (int j = should[0]; j < i; ++j)
cerr << A[j] << ' ';
cerr << '\n';
}
assert(should == from[i]);*/
}
cout << dp[n] << '\n';
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 5ms
memory: 12416kb
input:
5 2 0 0 1 1
output:
6
result:
ok 1 number(s): "6"
Test #2:
score: 0
Accepted
time: 8ms
memory: 13116kb
input:
1 0
output:
1
result:
ok 1 number(s): "1"
Test #3:
score: 0
Accepted
time: 8ms
memory: 12552kb
input:
2 1 1
output:
2
result:
ok 1 number(s): "2"
Test #4:
score: 0
Accepted
time: 0ms
memory: 12708kb
input:
3 2 1 1
output:
3
result:
ok 1 number(s): "3"
Test #5:
score: 0
Accepted
time: 2ms
memory: 12092kb
input:
4 3 2 2 3
output:
4
result:
ok 1 number(s): "4"
Test #6:
score: 0
Accepted
time: 5ms
memory: 12928kb
input:
5 3 4 4 2 4
output:
2
result:
ok 1 number(s): "2"
Test #7:
score: 0
Accepted
time: 5ms
memory: 12412kb
input:
7 3 4 3 5 6 3 4
output:
6
result:
ok 1 number(s): "6"
Test #8:
score: 0
Accepted
time: 8ms
memory: 13300kb
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: 8ms
memory: 12188kb
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: 9ms
memory: 13232kb
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: 10ms
memory: 12604kb
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: 13660kb
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: 106ms
memory: 20532kb
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: 629ms
memory: 39628kb
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: 801ms
memory: 74008kb
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: 1130ms
memory: 74224kb
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: 853ms
memory: 54744kb
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: 545ms
memory: 34812kb
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: -100
Wrong Answer
time: 1033ms
memory: 34352kb
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:
91752677
result:
wrong answer 1st numbers differ - expected: '799664563', found: '91752677'