QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#454511 | #8527. Power Divisions | ucup-team1525 | WA | 12ms | 32288kb | C++14 | 2.5kb | 2024-06-25 00:04:13 | 2024-06-25 00:04:13 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int N=3e5,M=1.1e6;
const int m1=998244353,m2=1e9+7;
const int b1=19491001,b2=19260817;
int add(int x,int y,int m){ return (x+=y)>=m?x-m:x; }
int sub(int x,int y,int m){ return (x-=y)<0?x+m:x; }
int kp1[M+5],kp2[M+5];
int s1[M+5],s2[M+5];
void prep(){
kp1[0]=kp2[0]=1;
s1[0]=s2[0]=1;
for(int i=1;i<=M;i++){
kp1[i]=1ll*kp1[i-1]*b1%m1;
s1[i]=add(s1[i-1],kp1[i],m1);
kp2[i]=1ll*kp2[i-1]*b2%m2;
s2[i]=add(s2[i-1],kp2[i],m2);
}
}
int n;
int a[N+5];
struct Num{
int h1,h2;
int s[M+5];
set<int> pos;
void addn(int p){
while(s[p]){
h1=sub(h1,kp1[p],m1);
h2=sub(h2,kp2[p],m2);
pos.erase(p);
s[p]=0; p++;
}
pos.insert(p);
s[p]=1;
h1=add(h1,kp1[p],m1);
h2=add(h2,kp2[p],m2);
}
void subn(int p){
while(!s[p]){
h1=add(h1,kp1[p],m1);
h2=add(h2,kp2[p],m2);
pos.insert(p);
s[p]=1; p++;
}
pos.erase(p);
s[p]=0;
h1=sub(h1,kp1[p],m1);
h2=sub(h2,kp2[p],m2);
}
void print(){
for(int i=0;i<=10;i++)
printf("%d ",s[i]);
puts("");
}
ll qy1(){
return 1ll*h1*m2+h2;
}
ll qy2(){
int l=*pos.begin(),r=*pos.rbegin();
int x1=((0ll+s1[r]-s1[l]-h1+2*kp1[l])%m1+m1)%m1;
int x2=((0ll+s2[r]-s2[l]-h2+2*kp2[l])%m2+m2)%m2;
// printf("%d %d\n",x1,x2);
return 1ll*x1*m2+x2;
}
}X;
vector<int> posl[N+5];
int f[N+5];
void solve(int l,int r){
if(l==r){
posl[r].push_back(l);
return;
}
int mid=l+r>>1;
unordered_map<ll,int> map1,map2;
// printf("work %d %d %d:\n",l,mid,r);
// printf("clear: %lld %lld\n",X.qy1(),X.qy1());
for(int i=mid;i>=l;i--){
X.addn(a[i]);
map1[X.qy1()]=i;
map2[X.qy2()]=i;
// X.print();
// printf("ins %lld %lld\n",X.qy1(),X.qy2());
}
for(int i=l;i<=mid;i++){
// X.print();
// printf("clear: %lld %lld\n",X.qy1(),X.qy2());
X.subn(a[i]);
}
// X.print();
// printf("clear: %lld %lld\n",X.qy1(),X.qy1());
for(int i=mid+1;i<=r;i++){
X.addn(a[i]);
// printf("query %lld %lld\n",X.qy1(),X.qy2());
int l1=map1[X.qy2()],l2=map2[X.qy1()];
if(l1>0) posl[i].push_back(l1);
if(l2>0&&l2!=l1) posl[i].push_back(l2);
}
for(int i=r;i>mid;i--) X.subn(a[i]);
// printf("%lld %lld\n",X.qy1(),X.qy1());
solve(l,mid);
solve(mid+1,r);
}
int main(){
prep();
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
solve(1,n);
f[0]=1;
for(int i=1;i<=n;i++){
for(auto j:posl[i]){
f[i]=add(f[i],f[j-1],m2);
// printf("%d ",j);
}
// puts("");
}
printf("%d\n",f[n]);
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 3ms
memory: 31268kb
input:
5 2 0 0 1 1
output:
6
result:
ok 1 number(s): "6"
Test #2:
score: 0
Accepted
time: 4ms
memory: 31384kb
input:
1 0
output:
1
result:
ok 1 number(s): "1"
Test #3:
score: 0
Accepted
time: 8ms
memory: 31400kb
input:
2 1 1
output:
2
result:
ok 1 number(s): "2"
Test #4:
score: 0
Accepted
time: 8ms
memory: 30724kb
input:
3 2 1 1
output:
3
result:
ok 1 number(s): "3"
Test #5:
score: 0
Accepted
time: 12ms
memory: 31648kb
input:
4 3 2 2 3
output:
4
result:
ok 1 number(s): "4"
Test #6:
score: 0
Accepted
time: 11ms
memory: 31340kb
input:
5 3 4 4 2 4
output:
2
result:
ok 1 number(s): "2"
Test #7:
score: 0
Accepted
time: 3ms
memory: 31328kb
input:
7 3 4 3 5 6 3 4
output:
6
result:
ok 1 number(s): "6"
Test #8:
score: 0
Accepted
time: 12ms
memory: 31688kb
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: 8ms
memory: 32288kb
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: -100
Wrong Answer
time: 8ms
memory: 31876kb
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:
670796921
result:
wrong answer 1st numbers differ - expected: '506782981', found: '670796921'