#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
typedef long long i64;
typedef unsigned long long u64;
const int MAXN = 2e5, MAXK = 50, MAX_S_LEN = 1e7;
const u64 HASH_POW = 131, MUL_MOD = 998244353;
#ifdef WIN32
#define fread_unlocked fread
#define fwrite_unlocked fwrite
#endif
struct FastIO {
char bufin[1<<27], bufout[1<<24];
char *pin, *pout;
FastIO() {
fseek(stdin, 0, SEEK_END);
int len = ftell(stdin);
fseek(stdin, 0, SEEK_SET);
fread_unlocked(bufin, sizeof(char), len, stdin);
pin = bufin; pout = bufout;
}
inline char readch() { return *pin++; }
inline void readstr(char *str) {
char c=readch(); int p=0;
while(!isalnum(c) && !ispunct(c)) c=readch();
while(isalnum(c) || ispunct(c)) {
str[p++]=c;
c=readch();
}
str[p++]='\0';
}
template<typename T>
inline void readint(T& x) {
T f=1, r=0;
while(!isdigit(*pin)) { if(*pin=='-')f=-1; pin++; }
while(isdigit(*pin)) { r=r*10+*pin-'0'; pin++; }
x = f*r;
}
template<typename T>
inline void writeint(T x) {
static char t[25], *pt; pt = t;
if(x<0) { *pout++ = '-'; x = -x; }
do {
*pt++ = x%10 + '0'; x /= 10;
} while(x);
pt--;
while(pt>=t) *pout++ = *pt--;
*pout++ = '\n';
}
~FastIO() {
fwrite_unlocked(bufout, sizeof(char), pout - bufout, stdout);
}
} fio;
#define readint fio.readint
#define writeint fio.writeint
#define readstr fio.readstr
struct Node {
int ch;
Node *prv, *nxt;
};
int n, m;
__gnu_pbds::gp_hash_table<u64, i64> cnt;
u64 hval[MAX_S_LEN + 10], powbase[MAX_S_LEN + 10];
int len;
char buf[MAX_S_LEN + 10];
Node nd[MAXN+10];
inline u64 calc_hash(u64 hval[], int l, int r) {
return hval[r] - hval[l-1] * powbase[r-l+1];
}
void link(Node *x, Node *y) {
int sz = 1, bnd = 1;
static Node pit[MAXN+10];
static u64 hval[MAXN+10];
Node *p = x;
x->nxt = y, y->prv = x;
for(sz = 1; p->prv != NULL && sz <= MAXK-2; p = p->prv, sz++)
;
for(int i = 1; p != NULL && i <= sz+MAXK-1; i++, bnd++, p = p->nxt) {
pit[i] = *p;
hval[i] = (hval[i-1] * HASH_POW + pit[i].ch);
}
--bnd;
for(int i = 1; i <= sz; i++)
for(int j = sz + 1; j <= min(bnd, i+MAXK-1); j++) {
++cnt[calc_hash(hval, i, j)];
cnt[calc_hash(hval, i, j)] %= MUL_MOD;
}
}
void split(Node *x, Node *y) {
int sz = 1, bnd = 1;
static Node pit[MAXN+10];
static u64 hval[MAXN+10];
Node *p = x;
x->nxt = y, y->prv = x;
for(sz = 1; p->prv != NULL && sz <= MAXK-2; p = p->prv, sz++)
;
for(int i = 1; p != NULL && i <= sz+MAXK-1; i++, bnd++, p = p->nxt) {
pit[i] = *p;
hval[i] = (hval[i-1] * HASH_POW + pit[i].ch);
}
--bnd;
for(int i = 1; i <= sz; i++)
for(int j = sz + 1; j <= min(bnd, i+MAXK-1); j++) {
--cnt[calc_hash(hval, i, j)];
cnt[calc_hash(hval, i, j)] += MUL_MOD;
cnt[calc_hash(hval, i, j)] %= MUL_MOD;
}
x->nxt = y->prv = NULL;
}
void init_hash() {
powbase[0] = 1;
for(int i = 1; i <= MAX_S_LEN; i++)
powbase[i] = powbase[i-1] * HASH_POW;
}
int main() {
init_hash();
readint(n); readint(m);
for(int i = 1; i <= n; i++) {
readint(nd[i].ch);
++cnt[nd[i].ch];
}
while(m--) {
int op, i, j, k;
i64 ans = 1;
readint(op);
switch(op) {
case 1:
readint(i);
readint(j);
link(&nd[i], &nd[j]);
break;
case 2:
readint(i);
split(&nd[i], nd[i].nxt);
break;
case 3:
readstr(buf+1);
len = strlen(buf+1);
readint(k);
for(int i = 1; i <= len; i++)
hval[i] = (hval[i-1] * HASH_POW + (buf[i]-'0'));
for(int i = 1; i <= len-k+1; i++)
ans = (ans * cnt[calc_hash(hval, i, i+k-1)]) % MUL_MOD;
writeint(ans);
break;
}
}
return 0;
}
| Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
| Testcase #1 | 11.888 ms | 76 MB + 364 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #2 | 11.999 ms | 76 MB + 384 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #3 | 23.088 ms | 76 MB + 600 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #4 | 12.172 ms | 76 MB + 780 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #5 | 18.97 ms | 77 MB + 176 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #6 | 210.214 ms | 270 MB + 360 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #7 | 28.731 ms | 78 MB + 328 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #8 | 130.718 ms | 174 MB + 312 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #9 | 214.589 ms | 270 MB + 340 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #10 | 220.145 ms | 272 MB + 968 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #11 | 308.552 ms | 272 MB + 992 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #12 | 227.886 ms | 272 MB + 316 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #13 | 46.305 ms | 80 MB + 292 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #14 | 258.421 ms | 272 MB + 276 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #15 | 293.539 ms | 272 MB + 304 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #16 | 378.204 ms | 277 MB + 572 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #17 | 535.612 ms | 469 MB + 600 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #18 | 629.603 ms | 482 MB + 416 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #19 | 706.799 ms | 482 MB + 448 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #20 | 180.066 ms | 180 MB + 356 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #21 | 81.927 ms | 84 MB + 404 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #22 | 521.237 ms | 468 MB + 388 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #23 | 545.648 ms | 468 MB + 416 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #24 | 759.706 ms | 479 MB + 24 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #25 | 784.989 ms | 478 MB + 636 KB | Runtime Error | Score: 0 | 显示更多 |