QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#442395 | #8526. Polygon II | ucup-team2279# | WA | 3ms | 18364kb | C++14 | 2.0kb | 2024-06-15 11:36:48 | 2024-06-15 11:36:48 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ull unsigned long long
const int M1=1e9+7,M2=998244353;
const int N=3e5+10,M=1e6+100,mod=1e9+7;
bool vis[M];
int n,a[N],f[N],mx[N],lg[N];
struct Hash
{
int w1,w2;
inline void init(int x,int y){w1=x;w2=y;}
Hash operator+(const Hash x)const{return {(w1+x.w1)%M1,(w2+x.w2)%M2};}
Hash operator*(const Hash x)const{return {1ll*w1*x.w1%M1,1ll*w2*x.w2%M2};}
Hash operator-(const Hash x)const{return {(w1+M1-x.w1)%M1,(w2+M2-x.w2)%M2};}
}pw[M],pre[N];
inline int read()
{
int x=0;char ch=getchar();
while(ch<'0'||ch>'9') ch=getchar();
while(ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
return x;
}
inline ull val(Hash x){return (1ull<<32)*x.w1+x.w2;}
inline void add(int &x,int y){x+=y;if(x>=mod) x-=mod;}
inline void solve(int l,int r)
{
int mid=(l+r)>>1;
if(l==r) return add(f[l],f[l-1]);
solve(l,mid);
for(int i=mid+1,w=0;i<=r;i++)
{
int x=a[i];
while(vis[x]) vis[x]=false,++x;
vis[x]=true;w=max(w,x);mx[i]=w+1;
}
for(int i=mid+1;i<=r;i++) for(int j=0;j<=lg[r-mid];j++) vis[a[i]+j]=false;
for(int i=mid,w=0;i>=l;i--)
{
int x=a[i];
while(vis[x]) vis[x]=false,++x;
vis[x]=true;w=max(w,x);mx[i]=w+1;
}
for(int i=mid;i>=l;i--) for(int j=0;j<=lg[mid-l+1];j++) vis[a[i]+j]=false;
unordered_map<ull,int> mp;
for(int i=mid+1,j=mid+1;i<=r;i++)
{
while(j>l&&mx[j-1]<=mx[i]) --j,add(mp[val(pre[mid]-pre[j-1])],f[j-1]);
add(f[i],mp[val(pw[mx[i]]-(pre[i]-pre[mid]))]);
}
mp.clear();
for(int i=mid;i>=l;i--) add(mp[val(pw[mx[i]]-(pre[mid]-pre[i-1]))],f[i-1]);
for(int i=mid+1,j=mid+1;i<=r;i++)
{
while(j>l&&mx[j-1]<=mx[i])
{
--j;
add(mp[val(pw[mx[j]]-(pre[mid]-pre[j-1]))],mod-f[j-1]);
}
add(f[i],mp[val(pre[i]-pre[mid])]);
}
solve(mid+1,r);
}
int main()
{
n=read();lg[0]=-1;
for(int i=1;i<=n;i++) a[i]=read(),lg[i]=lg[i>>1]+1;
f[0]=1;pw[0].init(1,1);
for(int i=1;i<M;i++) pw[i]=pw[i-1]+pw[i-1];
for(int i=1;i<=n;i++) pre[i]=pre[i-1]+pw[a[i]];
solve(1,n);printf("%d",f[n]);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 3ms
memory: 18364kb
input:
3 0 2 0
output:
1
result:
wrong answer 1st numbers differ - expected: '166666668', found: '1'