QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#785758#2018. 字符串匹配Link_Cut_Y100 ✓281ms66988kbC++143.7kb2024-11-26 19:06:302024-11-26 19:06:36

Judging History

你现在查看的是最新测评结果

  • [2024-11-26 19:06:36]
  • 评测
  • 测评结果:100
  • 用时:281ms
  • 内存:66988kb
  • [2024-11-26 19:06:30]
  • 提交

answer

#include <unordered_map>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
#include <bitset>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#define int long long
#define rep(i, a, b) for (int i = (a); i <= (b); i ++ )
#define rop(i, a, b) for (int i = (a); i < (b); i ++ )
#define dep(i, a, b) for (int i = (a); i >= (b); i -- )
#define dop(i, a, b) for (int i = (a); i > (b); i -- )

#define Darr(a, L, R) (cerr << #a "[" << L << " ~ " << R << "] = "; rep(x, L, R) cerr << a[x] << " "; cerr << '\n';)
#define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define D(x) (cerr << #x << " = " << x << '\n')
#define vit vector<int>::iterator
#define all(x) x.begin(), x.end()
#define min(a, b) (a < b ? a : b)
#define max(a, b) (a > b ? a : b)
#define chkmin(a, b) (a = min(a, b))
#define chkmax(a, b) (a = max(a, b))
#define sit set<int>::iterator
#define lowbit(x) (x & -x)
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pi acos(-1)
#define gc getchar
#define pc putchar
#define db double
#define y second
#define x first

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef pair<db, db> PDD;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
const int mod = 998244353;
const int eps = 1e-9;

const int N = (1ll << 21); int T = 1;
void print(int x) { dep(i, 20, 0) pc(((x >> i) & 1) ? '1' : '0'); }
int qpow(int a, int b = mod - 2, int s = 1) { for (; b; b >>= 1, a = 1ll * a * a % mod) if (b & 1) s = 1ll * s * a % mod; return s; }
namespace IO {
	void read() { return; }
	void write(char ch) { pc(ch); return; }
	void write() { return; }
	template <typename T> void read(T &x) { x = 0; T w = 0; char ch = gc(); while (ch < '0' || ch > '9') w |= (ch == '-'), ch = gc(); while ('0' <= ch && ch <= '9') x = x * 10 + (ch ^ 48), ch = gc(); x = w ? -x : x; }
	template <typename T> void print(T x) { if (!x) return; print<T>(x / 10), pc((x % 10) ^ '0'); }
	template <typename T> void write(T x) { if (x > 0) print<T>(x); else if (x < 0) pc('-'), print<T>(-x); else pc('0'); }
	template <typename T> void write(T x, char en) { write<T>(x), pc(en); }
	template <typename T, typename ...T2> void read(T &s, T2 &...oth) { read(s); read(oth...); return; }
}; using namespace IO;

const ULL P = 1331;
int g[N], c[300];
int n, tr[N]; char s[N];
ULL h[N], p[N];
bitset<50> pf[N], sf[N];
ULL Hash(int l, int r) { return h[r] - h[l - 1] * p[r - l + 1]; }
void ins(int x) { for (int i = x; i; i -= (i & -i)) tr[i] ++ ; }
int ask(int x, int S = 0) { for (int i = x; i <= 50; i += (i & -i)) S += tr[i]; return S; }
void sub() {
	int ans = 0;
	vector<int> vec;
	scanf("%s", s + 1);
	n = strlen(s + 1);
	rep(i, 0, n + 1) { pf[i] = sf[i] = 0, g[i] = h[i] = p[i] = tr[i] = 0; }
	// Get prefix-F
	memset(c, 0, sizeof c);
	rep(i, 1, n) {
		pf[i] = pf[i - 1]; pf[i].flip(s[i] - 'a');
	}
	// Get suffix-F
	memset(c, 0, sizeof c); sf[n + 1] = 0;
	dep(i, n, 1) {
		sf[i] = sf[i + 1]; sf[i].flip(s[i] - 'a');
	}
	// Get Hash
	rep(i, 1, n) h[i] = h[i - 1] * P + 1ull * s[i];
	p[0] = 1ull; rep(i, 1, n) p[i] = p[i - 1] * P;
	// Get g
	rep(k, 1, n) for (int i = 1; i + k - 1 <= n; i += k)
		if (Hash(1, k) == Hash(i, i + k - 1)) g[k] ++ ;
		else break;
	rep(k, 1, n) if (g[k] * k == n) g[k] -- ;
	rep(k, 2, n - 1) {
		ins(pf[k - 1].count());
		// Even : (g[k] + 1) / 2
		int q = sf[g[k] * k + 1].count();
		int S = g[k] * (k - 1);
		S -= ask(q + 1) * ((g[k] + 1) / 2);
		q = (sf[g[k] * k + 1] ^ pf[k]).count();
		S -= ask(q + 1) * (g[k] / 2); ans += S;
//		D(k); D(S);
	} printf("%lld\n", ans);
}
signed main() {
	read(T);
	while (T -- ) sub();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Pretests


Final Tests

Test #1:

score: 4
Accepted
time: 2ms
memory: 16080kb

input:

5
jjjjjjjjjj
lllllllcyg
mgmgmgmgmg
nycqtnycqt
tdutduwyga

output:

30
39
30
20
33

result:

ok 5 tokens

Test #2:

score: 4
Accepted
time: 0ms
memory: 16344kb

input:

5
hhhhhhhhhh
iiiiiiibkw
dgdgdgdgdg
ffffffffyf
ffzffzwsnw

output:

30
39
30
44
36

result:

ok 5 tokens

Test #3:

score: 4
Accepted
time: 0ms
memory: 16056kb

input:

5
rrrrrrrrrr
iiiiiiiwzr
dididididi
wwwwzqcjvv
mbymbyhgpc

output:

30
39
30
28
33

result:

ok 5 tokens

Test #4:

score: 4
Accepted
time: 2ms
memory: 16352kb

input:

5
cccccccccc
lllllllket
tututututu
ccbuxccbux
pnppnpnlwl

output:

30
39
30
26
32

result:

ok 5 tokens

Test #5:

score: 4
Accepted
time: 1ms
memory: 16080kb

input:

5
uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuubgmwdgmgwvqvkbcvihsk
qdaaqdaaqdaaqdaaqdaaqdaaqdaaqdaaqdaaqdaaqdaaqdaaqdaaqdaaqdaaqdaaqdaaqdaaqdaaqdaaqdaaqdaaqdaaqdaaqdaa
csqblzrdlnifzdoijirxfuuojcsqblzrdlnifzdoijirxfuuojcsqblzrdlnifzdoijirxfuuojcsqblzrdlnifzdoijirxf...

output:

6590
3585
2313
4359
4486

result:

ok 5 tokens

Test #6:

score: 4
Accepted
time: 1ms
memory: 16276kb

input:

5
llllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllsuqtxhunfvotmxfqebwj
rpiarpiarpiarpiarpiarpiarpiarpiarpiarpiarpiarpiarpiarpiarpiarpiarpiarpiarpiarpiarpiarpiarpiarpiarpia
yyexplkvmxjuqzgrsmdaztszfyyexplkvmxjuqzgrsmdaztszfyyexplkvmxjuqzgrsmdaztszfyyexplkvmxjuqzgrsmdaz...

output:

6564
3560
2607
4517
4554

result:

ok 5 tokens

Test #7:

score: 4
Accepted
time: 0ms
memory: 16060kb

input:

5
nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnkvpnzxdkdhjucliujhhl
quegquegquegquegquegquegquegquegquegquegquegquegquegquegquegquegquegquegquegquegquegquegquegquegqueg
aicsiooegbozaohagssdehvjzaicsiooegbozaohagssdehvjzaicsiooegbozaohagssdehvjzaicsiooegbozaohagssde...

output:

6517
3560
2888
4965
4105

result:

ok 5 tokens

Test #8:

score: 4
Accepted
time: 0ms
memory: 16280kb

input:

5
ppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppphytnmeyelaxegcuzqkv
joksjoksjoksjoksjoksjoksjoksjoksjoksjoksjoksjoksjoksjoksjoksjoksjoksjoksjoksjoksjoksjoksjoksjoksjoks
yqmqquzipayftwvwjnbqptuhwyqmqquzipayftwvwjnbqptuhwyqmqquzipayftwvwjnbqptuhwyqmqquzipayftwvwjnbqp...

output:

6604
3560
2738
4804
4832

result:

ok 5 tokens

Test #9:

score: 4
Accepted
time: 0ms
memory: 16084kb

input:

5
ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss...

output:

690923
325466
274377
538726
519032

result:

ok 5 tokens

Test #10:

score: 4
Accepted
time: 2ms
memory: 16084kb

input:

5
ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss...

output:

688611
325466
278014
483768
516890

result:

ok 5 tokens

Test #11:

score: 4
Accepted
time: 2ms
memory: 16088kb

input:

5
rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr...

output:

690572
325466
282653
400319
517082

result:

ok 5 tokens

Test #12:

score: 4
Accepted
time: 0ms
memory: 16160kb

input:

5
jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj...

output:

689440
325466
278624
464740
501911

result:

ok 5 tokens

Test #13:

score: 4
Accepted
time: 10ms
memory: 16304kb

input:

5
eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee...

output:

714173984
606072908
715934994
603558188
714547382

result:

ok 5 tokens

Test #14:

score: 4
Accepted
time: 10ms
memory: 16308kb

input:

5
vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv...

output:

713410981
603184777
713761452
714012718
603184777

result:

ok 5 tokens

Test #15:

score: 4
Accepted
time: 18ms
memory: 16592kb

input:

5
eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee...

output:

3502305645
3504362490
3495279874
3496151003
2412446034

result:

ok 5 tokens

Test #16:

score: 4
Accepted
time: 16ms
memory: 28680kb

input:

5
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc...

output:

2419023179
3481792643
2416893029
3498851133
2414888013

result:

ok 5 tokens

Test #17:

score: 4
Accepted
time: 14ms
memory: 16872kb

input:

5
dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd...

output:

2414715183
2414053265
3498760311
2415418741
2412193453

result:

ok 5 tokens

Test #18:

score: 4
Accepted
time: 22ms
memory: 17108kb

input:

5
uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu...

output:

14044909130
13758605640
8021703699
4927122703
9489413350

result:

ok 5 tokens

Test #19:

score: 4
Accepted
time: 23ms
memory: 17080kb

input:

5
ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss...

output:

14044820948
13781146461
7453935828
4673360128
9488558416

result:

ok 5 tokens

Test #20:

score: 4
Accepted
time: 23ms
memory: 17160kb

input:

5
rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr...

output:

14044830602
13805450160
7984918891
4873659736
9491430029

result:

ok 5 tokens

Test #21:

score: 4
Accepted
time: 19ms
memory: 17164kb

input:

5
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

14044823925
13789617860
7597752918
4978465106
9490927685

result:

ok 5 tokens

Test #22:

score: 4
Accepted
time: 224ms
memory: 66988kb

input:

5
ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss...

output:

903628883069
902178522904
467114641327
305284235317
620652587747

result:

ok 5 tokens

Test #23:

score: 4
Accepted
time: 227ms
memory: 66360kb

input:

5
qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq...

output:

903629704237
901055755987
504315438243
304698187610
620653531389

result:

ok 5 tokens

Test #24:

score: 4
Accepted
time: 280ms
memory: 65392kb

input:

5
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc...

output:

904243010503
904253960505
904235088477
667900329073
904248230739

result:

ok 5 tokens

Test #25:

score: 4
Accepted
time: 281ms
memory: 66912kb

input:

5
hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh...

output:

904261912252
904260123920
904263261760
667900331468
904241569561

result:

ok 5 tokens

Extra Test:

score: 0
Extra Test Passed