#include <cstdio>
#include <cctype>
#include <vector>
#include <algorithm>
const int ioSize = 1 << 21 | 1;
char iBuf[ioSize], *iS, *iE, oBuf[ioSize], *oS(oBuf), *oE(oBuf + ioSize);
inline char getc() { return iS == iE ? iE = iBuf + fread(iS = iBuf, 1, ioSize, stdin), iS == iE ? EOF : *iS++ : *iS++; }
void readi(int &x)
{
char c;
for (c = getc(); !isdigit(c); c = getc())
;
x = c ^ '0';
for (c = getc(); isdigit(c); c = getc())
(x *= 10) += c ^ '0';
}
void reads(char *s)
{
char c;
for (c = getc(); !isdigit(c); c = getc())
;
*s++ = c;
for (c = getc(); isdigit(c); c = getc())
*s++ = c;
*s = '\0';
}
inline void flush()
{
fwrite(oBuf, 1, oS - oBuf, stdout);
oS = oBuf;
}
inline void putc(char c)
{
*oS++ = c;
if (oS == oE)
flush();
}
void puti(int x)
{
char qu[20], *qr = qu;
do
*qr++ = x % 10 ^ '0';
while (x /= 10);
while (qr != qu)
putc(*--qr);
putc('\n');
}
typedef unsigned long long ull;
typedef unsigned int uint;
const int maxN = 200005, maxK = 50, maxL = 10000005;
const uint mod = 100057, base = 31;
const int Mod = 998244353;
int N, M, A[maxN];
int Pre[maxN], Next[maxN];
ull Pow1[maxN];
int Pow2[maxN];
char S[maxL];
ull Key[maxN * maxK + 1];
int Val[maxN * maxK + 1], _Next[maxN * maxK + 1], tot;
struct hashtable
{
int Head[mod];
void insert(ull v, uint t)
{
for (int i = Head[t]; i; i = _Next[i])
if (Key[i] == v)
{
++Val[i];
return;
}
++tot;
Key[tot] = v, Val[tot] = 1, _Next[tot] = Head[t];
Head[t] = tot;
}
void erase(ull v, uint t)
{
for (int i = Head[t]; i; i = _Next[i])
if (Key[i] == v)
{
--Val[i];
return;
}
}
int query(ull v, uint t)
{
for (int i = Head[t]; i; i = _Next[i])
if (Key[i] == v)
return Val[i];
return 0;
}
} Hash[maxK + 1];
int main()
{
readi(N), readi(M);
for (int i = 1; i <= N; ++i)
{
readi(A[i]);
Hash[1].insert(A[i], A[i]);
}
Pow1[0] = 1;
for (int i = 1; i <= N; ++i)
Pow1[i] = Pow1[i - 1] * base;
Pow2[0] = 1;
for (int i = 1; i <= N; ++i)
Pow2[i] = Pow2[i - 1] * base % mod;
for (int o, i, j, k; M--;)
{
readi(o);
static int buffer1[maxK + 1], buffer2[maxK + 1];
static ull h1[maxK + 1];
static uint h2[maxK + 1];
int cnt1 = 0, cnt2 = 0;
if (o == 1)
{
readi(i), readi(j);
for (int x = i; x && cnt1 < maxK; x = Pre[x])
buffer1[++cnt1] = A[x];
for (int x = j; x && cnt2 < maxK; x = Next[x])
buffer2[++cnt2] = A[x];
for (int x = 1; x <= cnt1; ++x)
{
h1[x] = h1[x - 1] + buffer1[x] * Pow1[x - 1];
h2[x] = (h2[x - 1] + buffer1[x] * Pow2[x - 1]) % mod;
}
ull hash1 = 0;
uint hash2 = 0;
for (int x = 1; x <= cnt2; ++x)
{
hash1 = hash1 * base + buffer2[x];
hash2 = (hash2 * base + buffer2[x]) % mod;
for (int y = 1; y <= cnt1 && x + y <= maxK; ++y)
{
ull t1 = h1[y] * Pow1[x] + hash1;
uint t2 = ((ull)h2[y] * Pow2[x] + hash2) % mod;
Hash[x + y].insert(t1, t2);
}
}
Pre[j] = i, Next[i] = j;
}
else if (o == 2)
{
readi(i);
for (int x = i; x && cnt1 < maxK; x = Pre[x])
buffer1[++cnt1] = A[x];
for (int x = Next[i]; x && cnt2 < maxK; x = Next[x])
buffer2[++cnt2] = A[x];
for (int x = 1; x <= cnt1; ++x)
{
h1[x] = h1[x - 1] + buffer1[x] * Pow1[x - 1];
h2[x] = (h2[x - 1] + buffer1[x] * Pow2[x - 1]) % mod;
}
ull hash1 = 0;
uint hash2 = 0;
for (int x = 1; x <= cnt2; ++x)
{
hash1 = hash1 * base + buffer2[x];
hash2 = (hash2 * base + buffer2[x]) % mod;
for (int y = 1; y <= cnt1 && x + y <= maxK; ++y)
{
ull t1 = h1[y] * Pow1[x] + hash1;
uint t2 = ((ull)h2[y] * Pow2[x] + hash2) % mod;
Hash[x + y].erase(t1, t2);
}
}
Pre[Next[i]] = 0;
Next[i] = 0;
}
else
{
reads(S + 1), readi(k);
ull hash1 = 0;
uint hash2 = 0;
int ans = 1;
for (i = 1; i < k; ++i)
{
hash1 = hash1 * base + (S[i] ^ '0');
hash2 = (hash2 * base + (S[i] ^ '0')) % mod;
}
for (i = k; S[i] && ans; ++i)
{
hash1 = hash1 * base + (S[i] ^ '0');
hash2 = (hash2 * base + (S[i] ^ '0')) % mod;
ans = (ull)ans * Hash[k].query(hash1, hash2) % Mod;
hash1 = hash1 - (S[i - k + 1] ^ '0') * Pow1[k - 1];
hash2 = (hash2 + mod - (S[i - k + 1] ^ '0') * Pow2[k - 1] % mod) % mod;
}
puti(ans);
}
// puts("---------------------");
}
flush();
return 0;
}
Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
Testcase #1 | 29.74 us | 64 KB | Accepted | Score: 4 | 显示更多 |
Testcase #2 | 52.23 us | 328 KB | Accepted | Score: 4 | 显示更多 |
Testcase #3 | 7.225 ms | 5 MB + 184 KB | Accepted | Score: 4 | 显示更多 |
Testcase #4 | 1.113 ms | 8 MB + 680 KB | Accepted | Score: 4 | 显示更多 |
Testcase #5 | 5.704 ms | 8 MB + 788 KB | Accepted | Score: 4 | 显示更多 |
Testcase #6 | 99.465 ms | 38 MB + 284 KB | Accepted | Score: 4 | 显示更多 |
Testcase #7 | 16.008 ms | 2 MB + 212 KB | Accepted | Score: 4 | 显示更多 |
Testcase #8 | 62.43 ms | 35 MB + 244 KB | Accepted | Score: 4 | 显示更多 |
Testcase #9 | 103.97 ms | 39 MB + 168 KB | Accepted | Score: 4 | 显示更多 |
Testcase #10 | 128.631 ms | 37 MB + 668 KB | Accepted | Score: 4 | 显示更多 |
Testcase #11 | 231.898 ms | 45 MB + 404 KB | Accepted | Score: 4 | 显示更多 |
Testcase #12 | 116.609 ms | 42 MB + 720 KB | Accepted | Score: 4 | 显示更多 |
Testcase #13 | 33.002 ms | 4 MB + 176 KB | Accepted | Score: 4 | 显示更多 |
Testcase #14 | 142.097 ms | 50 MB + 500 KB | Accepted | Score: 4 | 显示更多 |
Testcase #15 | 179.274 ms | 53 MB + 20 KB | Accepted | Score: 4 | 显示更多 |
Testcase #16 | 318.453 ms | 53 MB + 584 KB | Accepted | Score: 4 | 显示更多 |
Testcase #17 | 451.429 ms | 60 MB + 516 KB | Accepted | Score: 4 | 显示更多 |
Testcase #18 | 451.106 ms | 85 MB + 16 KB | Accepted | Score: 4 | 显示更多 |
Testcase #19 | 550.19 ms | 91 MB + 104 KB | Accepted | Score: 4 | 显示更多 |
Testcase #20 | 113.427 ms | 38 MB + 568 KB | Accepted | Score: 4 | 显示更多 |
Testcase #21 | 68.163 ms | 6 MB + 868 KB | Accepted | Score: 4 | 显示更多 |
Testcase #22 | 345.459 ms | 77 MB + 600 KB | Accepted | Score: 4 | 显示更多 |
Testcase #23 | 371.696 ms | 78 MB + 668 KB | Accepted | Score: 4 | 显示更多 |
Testcase #24 | 811.46 ms | 82 MB + 800 KB | Accepted | Score: 4 | 显示更多 |
Testcase #25 | 982.092 ms | 89 MB + 304 KB | Accepted | Score: 4 | 显示更多 |