QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#751353#5051. Namomo Subsequence_xqy_TL 1775ms565616kbC++202.4kb2024-11-15 18:16:472024-11-15 18:16:48

Judging History

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

  • [2024-11-15 18:16:48]
  • 评测
  • 测评结果:TL
  • 用时:1775ms
  • 内存:565616kb
  • [2024-11-15 18:16:47]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using LL = long long;
constexpr int mod = 998244353;

void solve() {
	
	string s;
	cin >> s;

	int n = s.size();
	s = " " + s;

	auto get = [&] (char c) {
		if (c >= 'a' && c <= 'z') return c - 'a';
		else if (c >= 'A' && c <= 'Z') return c - 'A' + 26;
		else return c - '0' + 52;
	};

	vector<int> t(n + 1);
	for (int i = 1 ; i <= n ; ++i) {
		t[i] = get(s[i]);
	}

	auto add = [&] (int &x,int y) {
		x += y;
		if (x >= mod) x -= mod;
	};	
	auto func = [&] (int x) {
		int tmp = 1LL * x * (x - 1) / 2 % mod;
		return tmp;
	};
	auto del = [&] (int &x ,int y) {
		x -= y;
		if (x < 0) x += mod;
	};

	constexpr int M = 62;
	vector<int> cnt(M) , sum(n + 1);
	vector<vector<int>> pos(M);
	vector pre(n + 1 , vector<int>(M));
	vector lst(n + 1 , vector<int>(M));
	for (int i = 1 ; i <= n ; ++i) {
		for (int j = 0 ; j < M ; ++j) {
			pre[i][j] = pre[i - 1][j];
			lst[i][j] = lst[i - 1][j];
		}
		pre[i][t[i]] += 1;
		pos[t[i]].emplace_back(i);
		sum[i] = sum[i - 1];
		del(sum[i] , func(cnt[t[i]]));
		del(lst[i][t[i]] , func(cnt[t[i]]));
		cnt[t[i]] += 1;
		add(sum[i] , func(cnt[t[i]]));
		add(lst[i][t[i]] , func(cnt[t[i]]));
	}

	int ans = 0;
	for (int i = 0 ; i < M ; ++i) {
		
		if (pos[i].empty()) continue;
		int m1 = pos[i].size() , k1 = m1 - 1;
		vector<int> dp(m1);
		int cnt_1_0 = 0;

		for (int j = 0 ; j < M ; ++j) {
			if (i == j || pos[j].empty()) continue;
			int cnt_0_0 = 0 , cnt_0_1 = 0;
			int m2 = pos[j].size() , k2 = m2 - 1;

			while (k1 >= 0  || k2 >= 0) {
				if (k1 >= 0 && k2 >= 0) {
					if (pos[i][k1] > pos[j][k2]) {
						add(cnt_1_0 , cnt_0_0);
						dp[k1] = cnt_0_1;
						k1 --;
					} else {
						add(cnt_0_0 , 1);
						add(cnt_0_1 , cnt_1_0);
						k2 --;
					}
				} else if (k1 >= 0) {
					add(cnt_1_0 , cnt_0_0);
					dp[k1] = cnt_0_1;
					k1 --;
				} else {
					break;
				}
			}
			
			
			for (int k = 0 ; k < m1 ; ++k) {
				int p = pos[i][k];
				int a1 = func(p - 1 - pre[p - 1][i] - pre[p - 1][j]) , a2 = sum[p - 1];
				del(a1 , a2);
				add(a1 , lst[p - 1][i]);
				add(a1 , lst[p - 1][j]);
				int tmp = 1LL * dp[k] * a1 % mod;
				add(ans , tmp);
				dp[k] = 0;
			}
			cnt_1_0 = 0 , k1 = m1 - 1;
		}
	}

	cout << ans << "\n";

}

int main() {

	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int t = 1;
	while (t--) {
		solve();
	}

	return 0;

}

详细

Test #1:

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

input:

wohaha

output:

1

result:

ok 1 number(s): "1"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3864kb

input:

momomo

output:

0

result:

ok 1 number(s): "0"

Test #3:

score: 0
Accepted
time: 0ms
memory: 3876kb

input:

gshfd1jkhaRaadfglkjerVcvuy0gf

output:

73

result:

ok 1 number(s): "73"

Test #4:

score: 0
Accepted
time: 0ms
memory: 3828kb

input:

retiredMiFaFa0v0

output:

33

result:

ok 1 number(s): "33"

Test #5:

score: 0
Accepted
time: 496ms
memory: 565040kb

input:

bcdccccacccabdbdaddcabddbaccaaaaaabaccbbbcbbddabcbccabacdacbcbabccbcbddcdcbcaaadddddccdbabaabcbbcaaadadacdaadbdccbddddabcbaaddbcadadcbcbaaccacabdababaabdccadaddacdcacdaabbadadaddbbcccbcddaccaadbbcaaccccdcacbdbdddbaccaacbcaccaaabccdadddbaabdbcaaccacdcdcbcdddacbcacdbbbdccdddccccabdbacddacbaacbbcaccdcd...

output:

587599316

result:

ok 1 number(s): "587599316"

Test #6:

score: 0
Accepted
time: 584ms
memory: 564612kb

input:

cedcedaecbbcaceddaacaebeecdaceecdeeedaeebddbcabddeeeeaeeebcbcbabdaeeabddbcebecebaddadacedbacdabcedcecbecedacaedbdaaeaeedcbbcddbbbbdecbeedeadcbdacbeadcadaeeccbdeabedbabbbecbabaaeacdbcbbdedbaebaeadcdcacceeeccedcdcecdbcadcdecbdccadbdbdabbeacbaaacecbabdcecebecaebedcebcccacbcbcdcccdaaaaeacaabeedcbbbaeeea...

output:

604741630

result:

ok 1 number(s): "604741630"

Test #7:

score: 0
Accepted
time: 683ms
memory: 565392kb

input:

dcbbbdcafbfbcdbddfdebcebbfbedfafeadcceeafbdabbbfcefadaedbecbcfaeccdfddbfbeebceadcdeaaefcbecbaececdeddaeefdeaaeaecbdbececdadcacbbefdbbffddeefcecabbecafbbeaaeebedbeabbbaeabedaecffebfcbcfabedebcbadbbfbbebdfdaefcedbdeaacbebcdcbfbfdcabbcadddbdaeabbcdcdfbdfdbcaaaafbfdfabdcdeebcfebecdeacaddeebfecfccadcfdea...

output:

137937394

result:

ok 1 number(s): "137937394"

Test #8:

score: 0
Accepted
time: 780ms
memory: 565616kb

input:

bdfcdcegecbacccddgfdaddgaggefagabgggafgbaeaecgeacacgccadbfdebbdgbaffffgaegabeebacedabecgdfcbbfceeaecaaceebabddbfgefdabgbdbgggdgfegaadccdafgggeafdeecccaafgedfcbefdccafaaaafdcfaeagfeddggcfeeaacgaabadeegebfageeaaceaggddddfcggggdbeefeacdbafggffcdbcaacbaagbcceageaacedceeebacfebgceggffefgabgeaebacdbadcaeg...

output:

830637896

result:

ok 1 number(s): "830637896"

Test #9:

score: 0
Accepted
time: 889ms
memory: 564528kb

input:

bdceebdaahbcgefdbahfcaaaffhfcffgfbaefgehbefdgcgfcafbfdehdeccdbaacdffbhdhdfhdaeehfebgccghchdggcccdbafheaaadhefcbbdeddbfhaehddegcefebghgdahegfefeecbdacffaadbaehahcdbhcdfbacdgfefgeccfgbcbhdfggeecbggbhffceegaahfbahgdebfchhhddfhfcfcdfeddbcabggdfgacaeghechabbdaafbeehgaebfadfchahgdhgggfhehhcehedafhcfcgeegg...

output:

165134706

result:

ok 1 number(s): "165134706"

Test #10:

score: 0
Accepted
time: 971ms
memory: 564196kb

input:

gfgdeabdacecfgadbgbadgbhgafhfhdiageeefghgbhbfhhfaaideehaieaddhcabgdhidbdefeagdfchhccdabchhahgfddchdiegbhfdddefddbcaabhhhgghaafacbbbbaeagacbbdabdidibhgbihdahdeghaheedfechbhfbcabidafeccbcbfdcechdfddffbeagcegagfegdafeaabcafgbcfechhiaiechdhhfdcbceefbccdcadeachcffhaebhbiadgeeggfaeefiaecahdgfgaehcagaaffbc...

output:

729999334

result:

ok 1 number(s): "729999334"

Test #11:

score: 0
Accepted
time: 1024ms
memory: 564512kb

input:

hcajfffideibggdfbdjjfbifgdcjibhdedgdibdgfjabaeijabebibcjfaddbiehadgggeadcaedieccdcgigccajjeicgbeijbahjjjghicaigiejgihiabeeggbfjdididdbggfcbhjajbjjgdabihijjddfhdhchggeegiecidjibdcccghfhcffcfehihdedgecbdfjjjiecedfhfjiefhjefbgbieeahcccfggcihbdbgjbdfhhbfghjeaijfagcgchaabijcdedjadfhgbgeefiijhhhcgfjeaadbe...

output:

342396794

result:

ok 1 number(s): "342396794"

Test #12:

score: 0
Accepted
time: 1759ms
memory: 565100kb

input:

qsjdnlenipkknuvegwcozcrunnssjmuhdzvzocimsoqzdxsodpsfxhphbwgimyfzzuxowavmsncjjvxdksrambjzbuzkyqdbplbjxrdsacpgbiuzsalkytskdgsxcsblvzyvcgnieysbmeoyfaroxmuetwcvdkhyvlkwqdewldziradjmnkusdsrnybvhylzqroiblkloioqrtybukgmwwxqyjevkijesdddyjagspqqfdmkrhcnjaxcksolmetbutvcigrfhaghmjlzloqkxjooqutmejzhvpmmxzoupjoy...

output:

905453170

result:

ok 1 number(s): "905453170"

Test #13:

score: 0
Accepted
time: 1775ms
memory: 565172kb

input:

antlkibnsqqmzaclyvinisylidtvoabqcndzhltrbohfqdfmdzzlyphhqhdbgdgcciyofikhxrqddkcenwhedsjbdwfqcdtrlmdpgpsbxebtwlucklnjqcbjeponmmxfbiuqwhtddfzfephrayohdqfkmzjtjqcywfkcvbtueapgzrlxoecguifcryoygybkkzjkpbmyscnfblbkcolqqeoffahxhbaupbzeazkjjwekeithdymqflpddwpwmpfsvlxwrwkpoetxuborumpzciuytnhgqqzfxbgrqjycqhkd...

output:

82912821

result:

ok 1 number(s): "82912821"

Test #14:

score: 0
Accepted
time: 1747ms
memory: 564912kb

input:

khpwaiqnxudrpjjonholcibhhtuokklklxqlxtjzgtqekubgzwhznxzlbowxrseobjzswqvtcvlttnvyxaueqyferdhfbumuzobnmnmoxkkgnxhmykxezptnczshsotuqyqqfmwyuusowieyvskaagzcschzxasckzfezkznakkaeekgyumiabsjhkefbhyrrurqzjalbbecpiiyheqcxifnuwplabncdkweyuqbxhkecujztklbuegdseqzmevordemwmhysmtngpvfdsgskghujbnhkflycnwhbdiorbcw...

output:

659276694

result:

ok 1 number(s): "659276694"

Test #15:

score: -100
Time Limit Exceeded

input:

yBsLfzzQCCwjLbfElpCOuMIyMwgSzrQLBnGYJWXFtobNLEGEYDOZUYKyviwbLelicegOrmebrrJkDDsyBDQiFxfHRecxeBUXZikRUctjMLaduPhhbMbgiQjRSrPkZuPoCTcmIrOwxhHTApmNTOwbSrSIKtxlSsVLOuLsfMDqpUHmVTyKzBdUVcJNJdLSDfTLFqVLCJEhkEOadDRRSRRNHefbsKopXMjAgTvXAAnByekMBgzgkbIwMKMeikEKfZzyqVoJVQevMNqXkfROFGjNBqZeDPDTVcTWnxckFdcOsMnj...

output:


result: