QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#793325#5051. Namomo SubsequenceLJY_ljyTL 2979ms1015836kbC++143.2kb2024-11-29 18:40:522024-11-29 18:40:53

Judging History

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

  • [2024-11-29 18:40:53]
  • 评测
  • 测评结果:TL
  • 用时:2979ms
  • 内存:1015836kb
  • [2024-11-29 18:40:52]
  • 提交

answer

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;

const long long MOD = 998244353;
const long long MAXN = 1e6 + 10;
const long long MAXM = 65; // 'a' - 'z', 'A' - 'Z', '0' - '9' 

char str[MAXN];
long long cnt[MAXN][MAXM];
long long Sum[MAXN];
vector<int> Index[MAXM];
vector<int> sum[MAXM][MAXM];
vector<int> cnt2[MAXM], cnt3[MAXM][MAXM];

long long Tran(char c) {
	if ('a' <= c && c <= 'z') return c - 'a' + 1;
	if ('A' <= c && c <= 'Z') return c - 'A' + 27;
	return c - '0' + 53;
}

int main() {
	//freopen("test.in", "r", stdin);
	//freopen("std.out", "w", stdout);
	scanf("%s", str + 1);
	int n = strlen(str + 1);
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= 62; j++) 
			cnt[i][j] = cnt[i - 1][j];
		cnt[i][Tran(str[i])] = cnt[i - 1][Tran(str[i])] + 1;
		Index[Tran(str[i])].emplace_back(i);
		Sum[i] = ( Sum[i - 1] + (cnt[i][Tran(str[i])] * (cnt[i][Tran(str[i])] - 1) / 2) % MOD - ((cnt[i][Tran(str[i])] - 1) * (cnt[i][Tran(str[i])] - 2) / 2) % MOD + MOD) % MOD;
 	}
	for (int i = 1; i <= 62; i++) {
		long long A = 0;
		for (long long j = 0; j < Index[i].size(); j++) {
			A = (A + Index[i][j]) % MOD;
			cnt2[i].emplace_back(A);
		}
	}
	for (int u = 1; u <= 62; u++) {
		for (int i = 1; i <= 62; i++) {
			long long A = 0;
			for (long long j = 0; j < Index[i].size(); j++) {
				A = (A + cnt[Index[i][j]][u]) % MOD;
				cnt3[i][u].emplace_back(A);
			}
			long long ans = 0, Sumsum = 0;
			if (!Index[i].empty()) {
				for (long long x = Index[i].size() - 1; x >= 0; x--) {
					ans = (ans + cnt[Index[i][x]][u]) % MOD;
					Sumsum = (Sumsum + ( ans - ( (Index[i].size() - x) * cnt[Index[i][x]][u]) % MOD + MOD) % MOD) % MOD;
					sum[i][u].emplace_back(Sumsum); 
				}
			}
		}
	} 
	long long Cnt = 0;
	for (int i = 1; i <= 62; i++) {
		for (long long j = 0; j < Index[i].size(); j++) {
			long long I = 1ll * Index[i][j];
			long long ans1 = ( ( (I - 1) * (I - 2) / 2) % MOD - Sum[I - 1] + MOD) % MOD; // ABC
			long long ans2 = 0, ans3 = 0;
			if (j > 0) {
				ans2 = (cnt2[i][j - 1] - cnt3[i][i][j - 1] + MOD) % MOD; //XCC;
				ans3 = ( (1ll * j * I) % MOD - cnt2[i][j - 1] + 2 * MOD - (1ll * j * j) % MOD + (1ll * (j - 1) * j / 2) % MOD + MOD) % MOD; //CXC
			}
			long long A = (ans1 - ans2 - ans3 + 2 * MOD) % MOD; // ABC
			for (int u = 1; u <= 62; u++) {
				if (u != i) {
					long long ans5 = 0, ans6 = 0;
					if (cnt[I][u] >= 1) {
						ans5 = (cnt2[u][cnt[I][u] - 1] - cnt3[u][i][cnt[I][u] - 1] - cnt3[u][u][cnt[I][u] - 1] + 2 * MOD) % MOD; // XDC
						ans6 = ((cnt[I][u] * I) % MOD - cnt2[u][cnt[I][u] - 1] - cnt[I][u] + 2 * MOD) % MOD; //DXC, X任意 
				 		long long ans7 = ((cnt[I][u]) * (cnt[I][u] - 1) / 2) % MOD; // DDC
				 		long long ans8 = 0;
				 		if (j >= 1)
				 			ans8 = cnt3[i][u][j - 1]; //DCC
				 		ans6 = (ans6 - ans7 - ans8 + 2 * MOD) % MOD;
				 	}
					long long B = (A - ans5 - ans6 + 2 * MOD) % MOD;
					if (cnt[n][u] != cnt[I][u]) {
						Cnt = ( Cnt + (B * sum[u][i][cnt[n][u] - cnt[I][u] - 1]) % MOD ) % MOD;
					}
				}
			} 
		}
	}
	printf("%lld\n", Cnt);
	//fclose(stdin);
	//fclose(stdout);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 8000kb

input:

wohaha

output:

1

result:

ok 1 number(s): "1"

Test #2:

score: 0
Accepted
time: 1ms
memory: 6084kb

input:

momomo

output:

0

result:

ok 1 number(s): "0"

Test #3:

score: 0
Accepted
time: 1ms
memory: 4064kb

input:

gshfd1jkhaRaadfglkjerVcvuy0gf

output:

73

result:

ok 1 number(s): "73"

Test #4:

score: 0
Accepted
time: 1ms
memory: 4140kb

input:

retiredMiFaFa0v0

output:

33

result:

ok 1 number(s): "33"

Test #5:

score: 0
Accepted
time: 2762ms
memory: 1014168kb

input:

bcdccccacccabdbdaddcabddbaccaaaaaabaccbbbcbbddabcbccabacdacbcbabccbcbddcdcbcaaadddddccdbabaabcbbcaaadadacdaadbdccbddddabcbaaddbcadadcbcbaaccacabdababaabdccadaddacdcacdaabbadadaddbbcccbcddaccaadbbcaaccccdcacbdbdddbaccaacbcaccaaabccdadddbaabdbcaaccacdcdcbcdddacbcacdbbbdccdddccccabdbacddacbaacbbcaccdcd...

output:

587599316

result:

ok 1 number(s): "587599316"

Test #6:

score: 0
Accepted
time: 2948ms
memory: 1014192kb

input:

cedcedaecbbcaceddaacaebeecdaceecdeeedaeebddbcabddeeeeaeeebcbcbabdaeeabddbcebecebaddadacedbacdabcedcecbecedacaedbdaaeaeedcbbcddbbbbdecbeedeadcbdacbeadcadaeeccbdeabedbabbbecbabaaeacdbcbbdedbaebaeadcdcacceeeccedcdcecdbcadcdecbdccadbdbdabbeacbaaacecbabdcecebecaebedcebcccacbcbcdcccdaaaaeacaabeedcbbbaeeea...

output:

604741630

result:

ok 1 number(s): "604741630"

Test #7:

score: 0
Accepted
time: 2949ms
memory: 1014256kb

input:

dcbbbdcafbfbcdbddfdebcebbfbedfafeadcceeafbdabbbfcefadaedbecbcfaeccdfddbfbeebceadcdeaaefcbecbaececdeddaeefdeaaeaecbdbececdadcacbbefdbbffddeefcecabbecafbbeaaeebedbeabbbaeabedaecffebfcbcfabedebcbadbbfbbebdfdaefcedbdeaacbebcdcbfbfdcabbcadddbdaeabbcdcdfbdfdbcaaaafbfdfabdcdeebcfebecdeacaddeebfecfccadcfdea...

output:

137937394

result:

ok 1 number(s): "137937394"

Test #8:

score: 0
Accepted
time: 2979ms
memory: 1014956kb

input:

bdfcdcegecbacccddgfdaddgaggefagabgggafgbaeaecgeacacgccadbfdebbdgbaffffgaegabeebacedabecgdfcbbfceeaecaaceebabddbfgefdabgbdbgggdgfegaadccdafgggeafdeecccaafgedfcbefdccafaaaafdcfaeagfeddggcfeeaacgaabadeegebfageeaaceaggddddfcggggdbeefeacdbafggffcdbcaacbaagbcceageaacedceeebacfebgceggffefgabgeaebacdbadcaeg...

output:

830637896

result:

ok 1 number(s): "830637896"

Test #9:

score: 0
Accepted
time: 2964ms
memory: 1015836kb

input:

bdceebdaahbcgefdbahfcaaaffhfcffgfbaefgehbefdgcgfcafbfdehdeccdbaacdffbhdhdfhdaeehfebgccghchdggcccdbafheaaadhefcbbdeddbfhaehddegcefebghgdahegfefeecbdacffaadbaehahcdbhcdfbacdgfefgeccfgbcbhdfggeecbggbhffceegaahfbahgdebfchhhddfhfcfcdfeddbcabggdfgacaeghechabbdaafbeehgaebfadfchahgdhgggfhehhcehedafhcfcgeegg...

output:

165134706

result:

ok 1 number(s): "165134706"

Test #10:

score: 0
Accepted
time: 2972ms
memory: 1014884kb

input:

gfgdeabdacecfgadbgbadgbhgafhfhdiageeefghgbhbfhhfaaideehaieaddhcabgdhidbdefeagdfchhccdabchhahgfddchdiegbhfdddefddbcaabhhhgghaafacbbbbaeagacbbdabdidibhgbihdahdeghaheedfechbhfbcabidafeccbcbfdcechdfddffbeagcegagfegdafeaabcafgbcfechhiaiechdhhfdcbceefbccdcadeachcffhaebhbiadgeeggfaeefiaecahdgfgaehcagaaffbc...

output:

729999334

result:

ok 1 number(s): "729999334"

Test #11:

score: -100
Time Limit Exceeded

input:

hcajfffideibggdfbdjjfbifgdcjibhdedgdibdgfjabaeijabebibcjfaddbiehadgggeadcaedieccdcgigccajjeicgbeijbahjjjghicaigiejgihiabeeggbfjdididdbggfcbhjajbjjgdabihijjddfhdhchggeegiecidjibdcccghfhcffcfehihdedgecbdfjjjiecedfhfjiefhjefbgbieeahcccfggcihbdbgjbdfhhbfghjeaijfagcgchaabijcdedjadfhgbgeefiijhhhcgfjeaadbe...

output:

342396794

result: