QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#445688 | #8527. Power Divisions | ucup-team1231# | WA | 6ms | 14464kb | C++20 | 2.5kb | 2024-06-16 08:20:10 | 2024-06-16 08:20:10 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
typedef long long int LLI;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define MOD 1000000007
#define MOD2 998244353
int power[1001000],power2[1001000];
int a[300000];
vi vv[300001];
bitset<1001000> bs;
int getAll(int l,int r) {
if (l == r) {
vv[r+1].pb(l);
return 0;
}
int i,mid = (l+r) / 2;
getAll(l,mid),getAll(mid+1,r);
vi all;
int mx = 0;
int sum1 = 0,sum2 = 0;
map<pii,int> M1,M2;
for (i = mid; i >= l; i--) {
int u = a[i];
while (bs[u]) bs[u] = 0,u++;
bs[u] = 1,all.pb(u),mx = max(mx,u);
sum1 += power[a[i]],sum1 %= MOD;
sum2 += power2[a[i]],sum2 %= MOD2;
int h1 = (power[mx+1]-sum1+MOD) % MOD;
int h2 = (power2[mx+1]-sum2+MOD2) % MOD2;
M1[mp(h1,h2)] = i;
}
sum1 = sum2 = 0;
for (i = mid+1; i <= r; i++) {
sum1 += power[a[i]],sum1 %= MOD;
sum2 += power2[a[i]],sum2 %= MOD2;
if (M1.count(mp(sum1,sum2))) vv[i+1].pb(M1[mp(sum1,sum2)]);
}
for (int u: all) bs[u] = 0;
all.clear();
mx = 0,sum1 = 0,sum2 = 0;
for (i = mid+1; i <= r; i++) {
int u = a[i];
while (bs[u]) bs[u] = 0,u++;
bs[u] = 1,all.pb(u),mx = max(mx,u);
sum1 += power[a[i]],sum1 %= MOD;
sum2 += power2[a[i]],sum2 %= MOD2;
int h1 = (power[mx+1]-sum1+MOD) % MOD;
int h2 = (power2[mx+1]-sum2+MOD2) % MOD2;
M2[mp(h1,h2)] = i;
}
sum1 = sum2 = 0;
for (i = mid; i >= l; i--) {
sum1 += power[a[i]],sum1 %= MOD;
sum2 += power2[a[i]],sum2 %= MOD2;
if (M2.count(mp(sum1,sum2))) vv[M2[mp(sum1,sum2)]+1].pb(i);
}
for (int u: all) bs[u] = 0;
all.clear();
return 0;
}
int dp[300001];
int main() {
int i;
power[0] = power2[0] = 1;
for (i = 1; i < 1001000; i++) {
power[i] = (2*power[i-1]) % MOD;
power2[i] = (2*power2[i-1]) % MOD2;
}
int n;
scanf("%d",&n);
for (i = 0; i < n; i++) scanf("%d",&a[i]);
dp[0] = 1;
getAll(0,n-1);
for (i = 0; i < n; i++) {
sort(vv[i+1].begin(),vv[i+1].end());
vv[i+1].resize(unique(vv[i+1].begin(),vv[i+1].end())-vv[i+1].begin());
for (int u: vv[i+1]) {
dp[i+1] += dp[u];
if (dp[i+1] >= MOD) dp[i+1] -= MOD;
}
}
printf("%d\n",dp[n]);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 6ms
memory: 13336kb
input:
5 2 0 0 1 1
output:
6
result:
ok 1 number(s): "6"
Test #2:
score: 0
Accepted
time: 5ms
memory: 14464kb
input:
1 0
output:
1
result:
ok 1 number(s): "1"
Test #3:
score: 0
Accepted
time: 2ms
memory: 13640kb
input:
2 1 1
output:
2
result:
ok 1 number(s): "2"
Test #4:
score: 0
Accepted
time: 0ms
memory: 13692kb
input:
3 2 1 1
output:
3
result:
ok 1 number(s): "3"
Test #5:
score: -100
Wrong Answer
time: 2ms
memory: 13972kb
input:
4 3 2 2 3
output:
3
result:
wrong answer 1st numbers differ - expected: '4', found: '3'