QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#454929 | #8527. Power Divisions | arnold518 | WA | 14ms | 28788kb | C++17 | 4.0kb | 2024-06-25 16:49:46 | 2024-06-25 16:49:46 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 3e5;
const int MAXM = 1e6+30;
int N, A[MAXN+10];
const int MOD = 1e9+7;
struct mint
{
int x;
mint() : x(0) {}
mint(int _x) : x(_x) {}
mint operator + (int ot) const { return x+ot >=MOD ? x+ot-MOD : x+ot; }
mint operator - (int ot) const { return x<ot ? x+MOD-ot : x-ot; }
mint operator - () const { return x ? MOD-x : 0; }
mint operator * (int ot) const { return 1ll*ot*x%MOD; }
mint operator += (int ot) { return *this = *this + ot; }
mint operator -= (int ot) { return *this = *this - ot; }
mint operator *= (int ot) { return *this = *this * ot; }
operator int() const { return x; }
};
mint mpow(mint x, int a)
{
mint ret=1;
while(a)
{
if(a&1) ret*=x;
x=x*x; a>>=1;
}
return ret;
}
mint inv(mint x) { return mpow(x, MOD-2); }
mint ppow[MAXM+10], ppow2[MAXM+10];
mint ppow3[MAXM+10], ppow4[MAXM+10];
struct Hash
{
bitset<MAXM> V;
vector<int> V2;
mint val, val2;
int msb, lsb;
Hash() { init(); }
void push(int x)
{
for(; V[x]; x++)
{
V[x]=0;
if(x==lsb) lsb++;
val-=ppow[x];
val2-=ppow3[x];
}
V[x]=1;
val+=ppow[x];
val2+=ppow3[x];
msb=max(msb, x);
lsb=min(lsb, x);
V2.push_back(x);
}
void init()
{
for(auto it : V2) V[it]=0;
V2.clear(); val=0; val2=0;
msb=-1; lsb=MAXM+1;
}
} H1, H2;
vector<int> adj[MAXN+10];
void solve(int l, int r)
{
if(l==r)
{
adj[r].push_back(r-1);
return;
}
int mid=l+r>>1;
solve(l, mid);
solve(mid+1, r);
{
H1.init(); H2.init();
vector<pair<pii, int>> V;
for(int i=mid; i>=l; i--)
{
H2.push(A[i]);
V.push_back({{H2.val, H2.val2}, i});
}
sort(V.begin(), V.end());
V.erase(unique(V.begin(), V.end()), V.end());
for(int i=mid+1; i<=r; i++)
{
H1.push(A[i]);
int t=(int)(ppow2[H1.msb]-(H1.lsb>0 ? ppow2[H1.lsb-1] : mint(0))+ppow[H1.lsb]-H1.val);
int t2=(int)(ppow4[H1.msb]-(H1.lsb>0 ? ppow4[H1.lsb-1] : mint(0))+ppow3[H1.lsb]-H1.val2);
for(auto it=lower_bound(V.begin(), V.end(), pair<pii, int>(pii(t, t2), 0)); it->first==pii(t, t2); it++) adj[i].push_back(it->second-1);
}
}
{
H1.init(); H2.init();
vector<pair<pii, int>> V;
for(int i=mid+1; i<=r; i++)
{
H2.push(A[i]);
V.push_back({{H2.val, H2.val2}, i});
}
sort(V.begin(), V.end());
V.erase(unique(V.begin(), V.end()), V.end());
for(int i=mid; i>=l; i--)
{
H1.push(A[i]);
int t=(int)(ppow2[H1.msb]-(H1.lsb>0 ? ppow2[H1.lsb-1] : mint(0))+ppow[H1.lsb]-H1.val);
int t2=(int)(ppow4[H1.msb]-(H1.lsb>0 ? ppow4[H1.lsb-1] : mint(0))+ppow3[H1.lsb]-H1.val2);
for(auto it=lower_bound(V.begin(), V.end(), pair<pii, int>(pii(t, t2), 0)); it->first==pii(t, t2); it++) adj[it->second].push_back(i-1);
}
}
}
int dp[MAXN+10];
int main()
{
scanf("%d", &N);
for(int i=1; i<=N; i++) scanf("%d", &A[i]);
ppow[0]=1;
for(int i=1; i<=MAXM; i++) ppow[i]=ppow[i-1]*3;
ppow2[0]=1;
for(int i=1; i<=MAXM; i++) ppow2[i]=ppow2[i-1]+ppow[i];
ppow3[0]=1;
for(int i=1; i<=MAXM; i++) ppow3[i]=ppow3[i-1]*7;
ppow4[0]=1;
for(int i=1; i<=MAXM; i++) ppow4[i]=ppow4[i-1]+ppow3[i];
solve(1, N);
dp[0]=1;
for(int i=1; i<=N; i++)
{
sort(adj[i].begin(), adj[i].end());
adj[i].erase(unique(adj[i].begin(), adj[i].end()), adj[i].end());
for(auto j : adj[i]) dp[i]=(dp[i]+dp[j])%MOD;
}
printf("%d\n", dp[N]);
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 11ms
memory: 26872kb
input:
5 2 0 0 1 1
output:
6
result:
ok 1 number(s): "6"
Test #2:
score: 0
Accepted
time: 14ms
memory: 27400kb
input:
1 0
output:
1
result:
ok 1 number(s): "1"
Test #3:
score: 0
Accepted
time: 13ms
memory: 28376kb
input:
2 1 1
output:
2
result:
ok 1 number(s): "2"
Test #4:
score: 0
Accepted
time: 9ms
memory: 26900kb
input:
3 2 1 1
output:
3
result:
ok 1 number(s): "3"
Test #5:
score: 0
Accepted
time: 13ms
memory: 27080kb
input:
4 3 2 2 3
output:
4
result:
ok 1 number(s): "4"
Test #6:
score: 0
Accepted
time: 13ms
memory: 27200kb
input:
5 3 4 4 2 4
output:
2
result:
ok 1 number(s): "2"
Test #7:
score: 0
Accepted
time: 13ms
memory: 26744kb
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: 28608kb
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: 9ms
memory: 27068kb
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: 14ms
memory: 27164kb
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: -100
Wrong Answer
time: 11ms
memory: 28788kb
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:
662533695
result:
wrong answer 1st numbers differ - expected: '586570528', found: '662533695'