QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#796898 | #2204. Border | shuopihua | AC ✓ | 1866ms | 501636kb | C++14 | 1.0kb | 2024-12-02 09:33:45 | 2024-12-02 09:33:45 |
Judging History
answer
#include <cstdio>
#include <cstring>
#include <algorithm>
#define mod 21788233
#define ll long long
using namespace std;
int n,seed,B=45,cnt;
int c[1000005];
int h[21788233];
struct node{ll x;int v,nxt;}e[30000005];
inline int Find(ll x){
for(int i=h[x%mod];i;i=e[i].nxt)
if(e[i].x==x) return i;
return 0;
}
inline int qry(ll x){return e[Find(x)].v;}
inline void add(ll x){
int i=Find(x);
if(i) e[i].v++;
else{
e[++cnt]={x,1,h[x%mod]};
h[x%mod]=cnt;
}
return ;
}
signed main(){
scanf("%d%d",&n,&seed);
for(int i=1;i<=n;i++) c[i]=(seed=(1ll*seed*13331+23333)%1000000007)&1;
ll ans=0;
for(int i=n;i>=1;i--){
ll f[55]={0},hs=1;
int nxt[55]={0};
for(int j=1;j<=B&&i+j-1<=n;j++) hs=hs*2+c[i+j-1],f[j]=qry(hs),add(hs);
for(int j=2;j<=B&&i+j<=n;j++){
int r=nxt[j-1];
while(r&&c[i+r]!=c[i+j-1]) r=nxt[r];
if(c[i+r]==c[i+j-1]) r++;
nxt[j]=r;
}
for(int j=2;j<=B&&i+j<=n;j++) f[nxt[j]]-=f[j];
for(int j=1;j<=B&&i+j<=n;j++) ans+=f[j]*j;
}
printf("%lld\n",ans);
return 0;
}
Details
Test #1:
score: 100
Accepted
time: 0ms
memory: 3676kb
Test #2:
score: 0
Accepted
time: 0ms
memory: 6260kb
Test #3:
score: 0
Accepted
time: 1ms
memory: 6116kb
Test #4:
score: 0
Accepted
time: 0ms
memory: 43868kb
Test #5:
score: 0
Accepted
time: 8ms
memory: 42060kb
Test #6:
score: 0
Accepted
time: 104ms
memory: 135008kb
Test #7:
score: 0
Accepted
time: 112ms
memory: 134952kb
Test #8:
score: 0
Accepted
time: 136ms
memory: 135256kb
Test #9:
score: 0
Accepted
time: 157ms
memory: 135468kb
Test #10:
score: 0
Accepted
time: 116ms
memory: 135288kb
Test #11:
score: 0
Accepted
time: 133ms
memory: 134744kb
Test #12:
score: 0
Accepted
time: 130ms
memory: 135240kb
Test #13:
score: 0
Accepted
time: 1722ms
memory: 499632kb
Test #14:
score: 0
Accepted
time: 1834ms
memory: 499680kb
Test #15:
score: 0
Accepted
time: 1790ms
memory: 499672kb
Test #16:
score: 0
Accepted
time: 1851ms
memory: 499696kb
Test #17:
score: 0
Accepted
time: 1837ms
memory: 499664kb
Test #18:
score: 0
Accepted
time: 1866ms
memory: 499580kb
Test #19:
score: 0
Accepted
time: 1807ms
memory: 499688kb
Test #20:
score: 0
Accepted
time: 1755ms
memory: 500396kb
Test #21:
score: 0
Accepted
time: 1866ms
memory: 499632kb
Test #22:
score: 0
Accepted
time: 1800ms
memory: 499640kb
Test #23:
score: 0
Accepted
time: 1656ms
memory: 499624kb
Test #24:
score: 0
Accepted
time: 1657ms
memory: 499580kb
Test #25:
score: 0
Accepted
time: 1841ms
memory: 499540kb
Test #26:
score: 0
Accepted
time: 1668ms
memory: 499572kb
Test #27:
score: 0
Accepted
time: 1714ms
memory: 499676kb
Test #28:
score: 0
Accepted
time: 1659ms
memory: 499604kb
Test #29:
score: 0
Accepted
time: 1714ms
memory: 499696kb
Test #30:
score: 0
Accepted
time: 1697ms
memory: 499696kb
Test #31:
score: 0
Accepted
time: 1676ms
memory: 499520kb
Test #32:
score: 0
Accepted
time: 1703ms
memory: 499660kb
Test #33:
score: 0
Accepted
time: 1639ms
memory: 499692kb
Test #34:
score: 0
Accepted
time: 1642ms
memory: 499648kb
Test #35:
score: 0
Accepted
time: 1798ms
memory: 499708kb
Test #36:
score: 0
Accepted
time: 1688ms
memory: 499568kb
Test #37:
score: 0
Accepted
time: 1673ms
memory: 499632kb
Test #38:
score: 0
Accepted
time: 1624ms
memory: 499708kb
Test #39:
score: 0
Accepted
time: 1773ms
memory: 499640kb
Test #40:
score: 0
Accepted
time: 1659ms
memory: 499676kb
Test #41:
score: 0
Accepted
time: 1776ms
memory: 499648kb
Test #42:
score: 0
Accepted
time: 1737ms
memory: 499556kb
Test #43:
score: 0
Accepted
time: 1552ms
memory: 499660kb
Test #44:
score: 0
Accepted
time: 1680ms
memory: 499728kb
Test #45:
score: 0
Accepted
time: 1710ms
memory: 499692kb
Test #46:
score: 0
Accepted
time: 1659ms
memory: 500192kb
Test #47:
score: 0
Accepted
time: 1765ms
memory: 499764kb
Test #48:
score: 0
Accepted
time: 1603ms
memory: 499588kb
Test #49:
score: 0
Accepted
time: 1784ms
memory: 499652kb
Test #50:
score: 0
Accepted
time: 1702ms
memory: 501636kb
Test #51:
score: 0
Accepted
time: 1740ms
memory: 499612kb
Test #52:
score: 0
Accepted
time: 1610ms
memory: 499552kb
Test #53:
score: 0
Accepted
time: 1654ms
memory: 499640kb
Test #54:
score: 0
Accepted
time: 1712ms
memory: 499532kb
Test #55:
score: 0
Accepted
time: 1745ms
memory: 499612kb