#include<bits/stdc++.h>
#define mp make_pair
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N=200010,M=10000010;
const ll mod=998244353;
const ull K=1000000007;
int n,m,nxt[N],pre[N],a[N],la,lb,ls; ll ans;
int s[M];
ull sa[M],sb[55],b[55];
namespace HASH {
const int mod=10000007;
int hed[mod],cnt=0; struct P { int l,to;ll w;ull s; }; P e[M];
void Add(int l,ull s,int v) {
int u=s%(ull)mod;
for(int i=hed[u];i;i=e[i].to)
if(e[i].l==l&&e[i].s==s) { e[i].w=(e[i].w+v)%mod;return; }
e[++cnt]=(P){l,hed[u],v,s},hed[u]=cnt;
}
ll Ask(int l,ull s) {
int u=s%(ull)mod;
for(int i=hed[u];i;i=e[i].to)
if(e[i].l==l&&e[i].s==s) return e[i].w;
return 0;
}
};
inline int Max(int x,int y) { return x>y? x:y; }
inline int Min(int x,int y) { return x<y? x:y; }
int read() {
register int x=0;register char c=getchar();
for(;c<'0'||c>'9';c=getchar());
for(;c>='0'&&c<='9';x=(x<<1)+(x<<3)+(c^48),c=getchar());
return x;
}
void reads() {
register char c=getchar(); for(;c<'1'||c>'6';);
for(ls=0;c>='1'&&c<='6';s[++ls]=(c^48),c=getchar());
}
void print(ll x) { if(x>9) print(x/10); putchar(x%10+'0'); }
void merge(int x,int y) {
ull ww;
la=0; for(int i=x;i&&la<=50;i=pre[i]) sa[++la]=a[i];
lb=0; for(int i=y;i&&lb<=50;i=nxt[i]) sb[++lb]=a[i];
for(int i=1;i+i<=la;i++) swap(sa[i],sa[la-i+1]);
for(int i=1;i<=la;i++) sa[i]=sa[i-1]*K+sa[i];
for(int i=1;i<=lb;i++) sb[i]=sb[i-1]*K+sb[i];
for(int l=2;l<=50;l++)
for(int i=Max(1,l-la),ed=Min(l-1,lb);i<=ed;i++) {
ww=(sa[la]-sa[la-l+i]*b[l-i])*b[i]+sb[i];
HASH::Add(l,ww,1);
}
nxt[x]=y,pre[y]=x;
}
void split(int x) {
ull ww;int y=nxt[x];
la=0; for(int i=x;i&&la<=50;i=pre[i]) sa[++la]=a[i];
lb=0; for(int i=y;i&&lb<=50;i=nxt[i]) sb[++lb]=a[i];
for(int i=1;i+i<=la;i++) swap(sa[i],sa[la-i+1]);
for(int i=1;i<=la;i++) sa[i]=sa[i-1]*K+sa[i];
for(int i=1;i<=lb;i++) sb[i]=sb[i-1]*K+sb[i];
for(int l=2;l<=50;l++)
for(int i=Max(1,l-la),ed=Min(l-1,lb);i<=ed;i++) {
ww=(sa[la]-sa[la-l+i]*b[l-i])*b[i]+sb[i];
HASH::Add(l,ww,-1);
}
nxt[x]=pre[y]=0;
}
int main() {
n=read(),m=read();
for(int i=1;i<=n;i++) a[i]=read(),HASH::Add(1,a[i],1);
b[0]=1; for(int i=1;i<=50;i++) b[i]=b[i-1]*K;
for(int opt,ta,tb,k;m;--m) {
opt=read(); if(opt==1) ta=read(),tb=read(),merge(ta,tb);
else if(opt==2) ta=read(),split(ta);
else {
reads(),ans=1,k=read(); ull ww;
for(int i=1;i<=ls;i++) sa[i]=sa[i-1]*K+(ull)s[i];
for(int l=1,r;l+k-1<=ls;l++) {
r=l+k-1,ww=sa[r]-sa[l-1]*b[r-l+1];
ans=ans*HASH::Ask(k,ww)%mod;
}
print(ans),putchar(10);
}
}
return 0;
}
Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
Testcase #1 | 134.81 us | 56 KB | Accepted | Score: 4 | 显示更多 |
Testcase #2 | 87.01 us | 332 KB | Accepted | Score: 4 | 显示更多 |
Testcase #3 | 12.327 ms | 5 MB + 616 KB | Accepted | Score: 4 | 显示更多 |
Testcase #4 | 1.44 ms | 10 MB + 792 KB | Accepted | Score: 4 | 显示更多 |
Testcase #5 | 9.8 ms | 14 MB + 640 KB | Accepted | Score: 4 | 显示更多 |
Testcase #6 | 141.231 ms | 66 MB + 916 KB | Accepted | Score: 4 | 显示更多 |
Testcase #7 | 23.498 ms | 852 KB | Accepted | Score: 4 | 显示更多 |
Testcase #8 | 84.019 ms | 62 MB + 424 KB | Accepted | Score: 4 | 显示更多 |
Testcase #9 | 145.827 ms | 68 MB + 236 KB | Accepted | Score: 4 | 显示更多 |
Testcase #10 | 134.051 ms | 63 MB + 992 KB | Accepted | Score: 4 | 显示更多 |
Testcase #11 | 265.629 ms | 75 MB + 548 KB | Accepted | Score: 4 | 显示更多 |
Testcase #12 | 155.599 ms | 71 MB + 52 KB | Accepted | Score: 4 | 显示更多 |
Testcase #13 | 47.741 ms | 1 MB + 416 KB | Accepted | Score: 4 | 显示更多 |
Testcase #14 | 183.225 ms | 82 MB + 848 KB | Accepted | Score: 4 | 显示更多 |
Testcase #15 | 235.313 ms | 86 MB + 568 KB | Accepted | Score: 4 | 显示更多 |
Testcase #16 | 300.972 ms | 86 MB + 444 KB | Accepted | Score: 4 | 显示更多 |
Testcase #17 | 457.333 ms | 96 MB + 852 KB | Accepted | Score: 4 | 显示更多 |
Testcase #18 | 575.688 ms | 127 MB + 944 KB | Accepted | Score: 4 | 显示更多 |
Testcase #19 | 707.439 ms | 137 MB + 12 KB | Accepted | Score: 4 | 显示更多 |
Testcase #20 | 147.855 ms | 61 MB + 916 KB | Accepted | Score: 4 | 显示更多 |
Testcase #21 | 96.968 ms | 2 MB + 560 KB | Accepted | Score: 4 | 显示更多 |
Testcase #22 | 428.688 ms | 120 MB + 460 KB | Accepted | Score: 4 | 显示更多 |
Testcase #23 | 467.685 ms | 122 MB + 76 KB | Accepted | Score: 4 | 显示更多 |
Testcase #24 | 698.169 ms | 127 MB + 508 KB | Accepted | Score: 4 | 显示更多 |
Testcase #25 | 879.153 ms | 137 MB + 288 KB | Accepted | Score: 4 | 显示更多 |