QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#701823 | #8527. Power Divisions | cyl001 | WA | 65ms | 272144kb | C++14 | 2.3kb | 2024-11-02 14:46:19 | 2024-11-02 14:46:19 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 105,p = 1e7 + 19,mod = 1e9 + 7;
int n,a[N],val1[N],val2[N],f[N];
vector <int> v[N];
struct Hash
{
int step,vis[p];
vector <pair <int,int>> v[p];
void clear(){step++;}
void insert(int s1,int s2,int c)
{
if(vis[s1] != step) vis[s1] = step,v[s1].clear();
v[s1].push_back(make_pair(s2,c));
}
int query(int s1,int s2)
{
if(vis[s1] != step) vis[s1] = step,v[s1].clear();
if(!v[s1].size()) return 0;
for(pair <int,int> pr : v[s1]) if(pr.first == s2) return pr.second;
return 0;
}
} hs;
struct Num
{
int u,cnt;
bool f[N];
void add_(int x)
{
while(f[x]) cnt--,f[x++] = false;
u = max(u,x),cnt++,f[x] = true;
}
void sub_(int x)
{
while(!f[x]) f[x++] = true;
f[x] = false;
}
} num;
void solve(int l,int r)
{
if(l == r)
{
v[l].push_back(l);
return ;
}
int mid = (l + r) / 2;
solve(l,mid),solve(mid + 1,r);
hs.clear(),num.u = num.cnt = 0;
for(int i = mid + 1,s1 = 0,s2 = 0;i <= r;i++)
{
s1 = (s1 + val1[a[i]]) % p,s2 = (s2 + val2[a[i]]) % mod;
hs.insert(s1,s2,i);
}
for(int i = mid,s1 = 0,s2 = 0,h1,h2,pos;i >= l;i--)
{
s1 = (s1 + val1[a[i]]) % p,s2 = (s2 + val2[a[i]]) % mod;
num.add_(a[i]),h1 = (val1[num.u + 1] - s1 + p) % p,h2 = (val2[num.u + 1] - s2 + mod) % mod;
if(pos = hs.query(h1,h2)) v[pos].push_back(i);
}
for(int i = mid;i >= l;i--) num.sub_(a[i]);
hs.clear(),num.u = num.cnt = 0;
for(int i = l,s1 = 0,s2 = 0;i <= mid;i++)
{
s1 = (s1 + val1[a[i]]) % p,s2 = (s2 + val2[a[i]]) % mod;
hs.insert(s1,s2,i);
}
for(int i = mid + 1,s1 = 0,s2 = 0,h1,h2,pos;i <= r;i++)
{
s1 = (s1 + val1[a[i]]) % p,s2 = (s2 + val2[a[i]]) % mod;
num.add_(a[i]);
if(num.cnt > 1)
{
h1 = (val1[num.u + 1] - s1 + p) % p,h2 = (val2[num.u + 1] - s2 + mod) % mod;
if(pos = hs.query(h1,h2)) v[i].push_back(pos);
}
}
for(int i = mid + 1;i <= r;i++) num.sub_(a[i]);
}
int main()
{
scanf("%d",&n);
for(int i = 1;i <= n;i++) scanf("%d",&a[i]);
val1[0] = val2[0] = 1;
for(int i = 1;i <= 1000100;i++)
{
val1[i] = 2 * val1[i - 1] % p;
val2[i] = 2 * val2[i - 1] % mod;
}
solve(1,n);
f[0] = 1;
for(int i = 1;i <= n;i++)
for(int j : v[i]) f[i] = (f[i] + f[j - 1]) % mod;
printf("%d\n",f[n]);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 49ms
memory: 271848kb
input:
5 2 0 0 1 1
output:
6
result:
ok 1 number(s): "6"
Test #2:
score: 0
Accepted
time: 32ms
memory: 271852kb
input:
1 0
output:
1
result:
ok 1 number(s): "1"
Test #3:
score: 0
Accepted
time: 40ms
memory: 271896kb
input:
2 1 1
output:
2
result:
ok 1 number(s): "2"
Test #4:
score: 0
Accepted
time: 65ms
memory: 271712kb
input:
3 2 1 1
output:
3
result:
ok 1 number(s): "3"
Test #5:
score: -100
Wrong Answer
time: 59ms
memory: 272144kb
input:
4 3 2 2 3
output:
3
result:
wrong answer 1st numbers differ - expected: '4', found: '3'