QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#782836#2018. 字符串匹配Link_Cut_Y#100 ✓186ms21364kbC++203.8kb2024-11-25 21:46:062024-11-25 21:46:07

Judging History

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

  • [2024-11-25 21:46:07]
  • 评测
  • 测评结果:100
  • 用时:186ms
  • 内存:21364kb
  • [2024-11-25 21:46:06]
  • 提交

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;

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 int N = (1ll << 20) + 5;
const ULL BASE = 1331ull;
bool isj[30], disj[30];
int t, len, jcnt, djcnt[N], bit[30]; 
ULL h[N], ans; 
char s[N];

void update(int x) {
	++ x;
	while (x <= 27) { ++ bit[x]; x += lowbit(x); } 
}
int sum(int x, int s = 0) {
	++ x;
	while (x >= 1) {
		s += bit[x];
		x -= lowbit(x);
	} return s;
}
int input(char* s) {
	char c = getchar();
	int i = 0;
	while(!islower(c))
		c = getchar();
	while(islower(c)) {
		s[ ++ i] = c;
		c = getchar();
	} return i;
}
void sub() {
	len = input(s);
	djcnt[len] = 1; 
	disj[s[len] - 'a'] = 1;
	dep(i, len - 1, 1)
		djcnt[i] = djcnt[i + 1] + ((disj[s[i] - 'a'] = !disj[s[i] - 'a']) == 1 ? 1 : -1);
	h[1] = s[1] - 'a'; 
	rep(i, 2, len) h[i] = h[i - 1] * BASE + s[i] - 'a';
	ULL a = BASE*BASE;
	update(1); 
	isj[s[1] - 'a'] = 1; 
	jcnt = 1;
	rep(i, 2, len) { int x = 1; 
		for (int j = (i << 1); j <= len; j += i) {
			if (h[j] - h[j - i]*a == h[i]) x ++ ;
			else break;
		}
		if(x * i == len) ans += 1ull * bit[1] * ((x - 1) >> 1); 
		else ans += 1ull * sum(djcnt[x * i + 1]) * ((x + 1) >> 1); 
		ans += 1ULL*sum(djcnt[(x - 1) * i + 1]) * (x >> 1); 
		update((isj[s[i] - 'a'] = !isj[s[i] - 'a']) ? ++ jcnt : -- jcnt); 
		a *= BASE;
	} printf("%llu\n", ans);
	memset(disj, 0, sizeof disj);
	memset(isj, 0, sizeof isj);
	memset(bit, 0, sizeof bit);
	ans = 0;
}
signed main() {
	read(T); while (T -- ) sub(); 
	return 0;
}


詳細信息


Pretests


Final Tests

Test #1:

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

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: 3840kb

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: 3896kb

input:

5
rrrrrrrrrr
iiiiiiiwzr
dididididi
wwwwzqcjvv
mbymbyhgpc

output:

30
39
30
28
33

result:

ok 5 tokens

Test #4:

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

input:

5
cccccccccc
lllllllket
tututututu
ccbuxccbux
pnppnpnlwl

output:

30
39
30
26
32

result:

ok 5 tokens

Test #5:

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

input:

5
uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuubgmwdgmgwvqvkbcvihsk
qdaaqdaaqdaaqdaaqdaaqdaaqdaaqdaaqdaaqdaaqdaaqdaaqdaaqdaaqdaaqdaaqdaaqdaaqdaaqdaaqdaaqdaaqdaaqdaaqdaa
csqblzrdlnifzdoijirxfuuojcsqblzrdlnifzdoijirxfuuojcsqblzrdlnifzdoijirxfuuojcsqblzrdlnifzdoijirxf...

output:

6590
3585
2313
4359
4486

result:

ok 5 tokens

Test #6:

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

input:

5
llllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllsuqtxhunfvotmxfqebwj
rpiarpiarpiarpiarpiarpiarpiarpiarpiarpiarpiarpiarpiarpiarpiarpiarpiarpiarpiarpiarpiarpiarpiarpiarpia
yyexplkvmxjuqzgrsmdaztszfyyexplkvmxjuqzgrsmdaztszfyyexplkvmxjuqzgrsmdaztszfyyexplkvmxjuqzgrsmdaz...

output:

6564
3560
2607
4517
4554

result:

ok 5 tokens

Test #7:

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

input:

5
nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnkvpnzxdkdhjucliujhhl
quegquegquegquegquegquegquegquegquegquegquegquegquegquegquegquegquegquegquegquegquegquegquegquegqueg
aicsiooegbozaohagssdehvjzaicsiooegbozaohagssdehvjzaicsiooegbozaohagssdehvjzaicsiooegbozaohagssde...

output:

6517
3560
2888
4965
4105

result:

ok 5 tokens

Test #8:

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

input:

5
ppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppphytnmeyelaxegcuzqkv
joksjoksjoksjoksjoksjoksjoksjoksjoksjoksjoksjoksjoksjoksjoksjoksjoksjoksjoksjoksjoksjoksjoksjoksjoks
yqmqquzipayftwvwjnbqptuhwyqmqquzipayftwvwjnbqptuhwyqmqquzipayftwvwjnbqptuhwyqmqquzipayftwvwjnbqp...

output:

6604
3560
2738
4804
4832

result:

ok 5 tokens

Test #9:

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

input:

5
ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss...

output:

690923
325466
274377
538726
519032

result:

ok 5 tokens

Test #10:

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

input:

5
ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss...

output:

688611
325466
278014
483768
516890

result:

ok 5 tokens

Test #11:

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

input:

5
rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr...

output:

690572
325466
282653
400319
517082

result:

ok 5 tokens

Test #12:

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

input:

5
jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj...

output:

689440
325466
278624
464740
501911

result:

ok 5 tokens

Test #13:

score: 4
Accepted
time: 4ms
memory: 4372kb

input:

5
eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee...

output:

714173984
606072908
715934994
603558188
714547382

result:

ok 5 tokens

Test #14:

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

input:

5
vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv...

output:

713410981
603184777
713761452
714012718
603184777

result:

ok 5 tokens

Test #15:

score: 4
Accepted
time: 9ms
memory: 4992kb

input:

5
eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee...

output:

3502305645
3504362490
3495279874
3496151003
2412446034

result:

ok 5 tokens

Test #16:

score: 4
Accepted
time: 8ms
memory: 4872kb

input:

5
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc...

output:

2419023179
3481792643
2416893029
3498851133
2414888013

result:

ok 5 tokens

Test #17:

score: 4
Accepted
time: 8ms
memory: 4948kb

input:

5
dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd...

output:

2414715183
2414053265
3498760311
2415418741
2412193453

result:

ok 5 tokens

Test #18:

score: 4
Accepted
time: 11ms
memory: 6004kb

input:

5
uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu...

output:

14044909130
13758605640
8021703699
4927122703
9489413350

result:

ok 5 tokens

Test #19:

score: 4
Accepted
time: 12ms
memory: 6036kb

input:

5
ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss...

output:

14044820948
13781146461
7453935828
4673360128
9488558416

result:

ok 5 tokens

Test #20:

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

input:

5
rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr...

output:

14044830602
13805450160
7984918891
4873659736
9491430029

result:

ok 5 tokens

Test #21:

score: 4
Accepted
time: 15ms
memory: 5952kb

input:

5
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

14044823925
13789617860
7597752918
4978465106
9490927685

result:

ok 5 tokens

Test #22:

score: 4
Accepted
time: 138ms
memory: 21364kb

input:

5
ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss...

output:

903628883069
902178522904
467114641327
305284235317
620652587747

result:

ok 5 tokens

Test #23:

score: 4
Accepted
time: 140ms
memory: 21232kb

input:

5
qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq...

output:

903629704237
901055755987
504315438243
304698187610
620653531389

result:

ok 5 tokens

Test #24:

score: 4
Accepted
time: 186ms
memory: 21264kb

input:

5
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc...

output:

904243010503
904253960505
904235088477
667900329073
904248230739

result:

ok 5 tokens

Test #25:

score: 4
Accepted
time: 186ms
memory: 21220kb

input:

5
hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh...

output:

904261912252
904260123920
904263261760
667900331468
904241569561

result:

ok 5 tokens

Extra Test:

score: 0
Extra Test Passed