QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#445840 | #8527. Power Divisions | PhantomThreshold | WA | 9ms | 20692kb | C++20 | 2.3kb | 2024-06-16 15:40:27 | 2024-06-16 15:40:27 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int MODA=1e9+7;
const int MOD1=1000000009,MOD2=993244853;
struct hs
{
int h1,h2;
long long operator()()const{return 1ll*h1*MOD2+h2;}
hs operator+(const hs &h)const{return (hs){(h1+h.h1)%MOD1,(h2+h.h2)%MOD2};}
hs operator-(const hs &h)const{return (hs){(h1-h.h1+MOD1)%MOD1,(h2-h.h2+MOD2)%MOD2};}
bool operator<(const hs &h)const{return h1==h.h1?h2<h.h2:h1<h.h1;}
};
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
vector<hs> pw(1111111);
pw[0]=(hs){1,1};
for(int i=1;i<=1000100;i++)
pw[i]=pw[i-1]+pw[i-1];
vector<hs> S(1111111);
unordered_map<long long,int> mp;
mp[S[0]()]=0;
int n;
cin>>n;
vector<int> dp(n+5);
dp[0]=1;
// int lgn=19;
vector<pair<int,int>> stk;//pos,val
vector<int> a(n+5);
vector<int> L(n+5),R(n+5);
for(int i=1;i<=n;i++)
{
cin>>a[i];
S[i]=S[i-1]+pw[a[i]];
// int last=0;
while(not stk.empty() and stk.back().second<=a[i])
{
L[i]=stk.back().first;
stk.pop_back();
}
if(not stk.empty())R[stk.back().first]=i;
stk.emplace_back(i,a[i]);
/*
int minv=1e9,prep=0;
for(auto [p,v]:stk)
{
int lgl=31-__builtin_clz(i-prep);
for(int t=v;t<=min(v+lgl,minv-1);t++)
{
hs preS=S[i]-pw[t];
auto it=mp.find(preS());
if(it!=mp.end())
{
dp[i]+=dp[it->second];
dp[i]%=MODA;
}
}
minv=v;
prep=p;
}
*/
mp[S[i]()]=i;
}
vector<vector<int>> G(n+5);
function<void(int,int,int)> solve=[&](int l,int r,int pos)
{
if(pos-l<r-pos)
{
for(int i=l;i<=pos;i++)
{
int lgn=19,v=a[pos];
for(int t=v;t<=v+lgn;t++)
{
hs preS=S[i-1]+pw[t];
auto it=mp.find(preS());
if(it!=mp.end() and it->second<=r)
{
G[it->second].push_back(i-1);
}
}
}
}
else
{
for(int i=pos;i<=r;i++)
{
int lgn=19,v=a[pos];
for(int t=v;t<=v+lgn;t++)
{
hs preS=S[i]-pw[t];
auto it=mp.find(preS());
if(it!=mp.end() and it->second>=l-1)
{
G[i].push_back(it->second);
}
}
}
}
if(L[pos])solve(l,pos-1,L[pos]);
if(R[pos])solve(pos+1,r,R[pos]);
};
solve(1,n,stk[0].first);
for(int i=1;i<=n;i++)
{
for(auto v:G[i])
{
// cerr<<"found "<<v<<' '<<i<<endl;
dp[i]=(dp[i]+dp[v])%MODA;
}
}
cout<<dp[n]<<endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 20684kb
input:
5 2 0 0 1 1
output:
6
result:
ok 1 number(s): "6"
Test #2:
score: 0
Accepted
time: 8ms
memory: 20688kb
input:
1 0
output:
1
result:
ok 1 number(s): "1"
Test #3:
score: 0
Accepted
time: 4ms
memory: 20476kb
input:
2 1 1
output:
2
result:
ok 1 number(s): "2"
Test #4:
score: 0
Accepted
time: 4ms
memory: 20692kb
input:
3 2 1 1
output:
3
result:
ok 1 number(s): "3"
Test #5:
score: 0
Accepted
time: 5ms
memory: 20688kb
input:
4 3 2 2 3
output:
4
result:
ok 1 number(s): "4"
Test #6:
score: 0
Accepted
time: 8ms
memory: 20388kb
input:
5 3 4 4 2 4
output:
2
result:
ok 1 number(s): "2"
Test #7:
score: 0
Accepted
time: 4ms
memory: 20532kb
input:
7 3 4 3 5 6 3 4
output:
6
result:
ok 1 number(s): "6"
Test #8:
score: 0
Accepted
time: 9ms
memory: 20500kb
input:
10 8 6 5 6 7 8 6 8 9 9
output:
4
result:
ok 1 number(s): "4"
Test #9:
score: -100
Wrong Answer
time: 4ms
memory: 20548kb
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:
106660708
result:
wrong answer 1st numbers differ - expected: '11332014', found: '106660708'