QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#454981 | #8527. Power Divisions | arnold518 | WA | 9ms | 20324kb | C++17 | 3.4kb | 2024-06-25 17:17:59 | 2024-06-25 17:17:59 |
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];
struct Hash
{
bitset<MAXM> V;
vector<int> V2;
mint val;
int msb, lsb;
Hash() { init(); }
void push(int x)
{
for(; V[x]; x++)
{
V[x]=0;
if(x==lsb) lsb++;
val-=ppow[x];
}
V[x]=1;
val+=ppow[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;
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<pii> V;
for(int i=mid; i>=l; i--)
{
H2.push(A[i]);
V.push_back({H2.val, 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);
for(auto it=lower_bound(V.begin(), V.end(), pii(t, 0)); it->first==t; it++) adj[i].push_back(it->second-1);
}
}
{
H1.init(); H2.init();
vector<pii> V;
for(int i=mid+1; i<=r; i++)
{
H2.push(A[i]);
V.push_back({H2.val, 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);
for(auto it=lower_bound(V.begin(), V.end(), pii(t, 0)); it->first==t; 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]*2;
ppow2[0]=1;
for(int i=1; i<=MAXM; i++) ppow2[i]=ppow2[i-1]+ppow[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]);
}
詳細信息
Test #1:
score: 100
Accepted
time: 9ms
memory: 18888kb
input:
5 2 0 0 1 1
output:
6
result:
ok 1 number(s): "6"
Test #2:
score: 0
Accepted
time: 4ms
memory: 20168kb
input:
1 0
output:
1
result:
ok 1 number(s): "1"
Test #3:
score: 0
Accepted
time: 6ms
memory: 20152kb
input:
2 1 1
output:
2
result:
ok 1 number(s): "2"
Test #4:
score: 0
Accepted
time: 6ms
memory: 18776kb
input:
3 2 1 1
output:
3
result:
ok 1 number(s): "3"
Test #5:
score: 0
Accepted
time: 3ms
memory: 18768kb
input:
4 3 2 2 3
output:
4
result:
ok 1 number(s): "4"
Test #6:
score: 0
Accepted
time: 8ms
memory: 18876kb
input:
5 3 4 4 2 4
output:
2
result:
ok 1 number(s): "2"
Test #7:
score: 0
Accepted
time: 4ms
memory: 18776kb
input:
7 3 4 3 5 6 3 4
output:
6
result:
ok 1 number(s): "6"
Test #8:
score: 0
Accepted
time: 4ms
memory: 18876kb
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: 20096kb
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: 3ms
memory: 20168kb
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: 7ms
memory: 20324kb
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'