QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#690161 | #5311. Master of Both | Traveler | TL | 385ms | 37988kb | C++20 | 3.0kb | 2024-10-30 20:38:07 | 2024-10-30 20:38:09 |
Judging History
answer
#include<iostream>
#include<cstring>
#include<stdlib.h>
#include<unordered_map>
#include<vector>
#include<array>
#include<math.h>
#include<map>
#include<stdio.h>
#include<queue>
#include<assert.h>
#include<string>
#include<limits.h>
#include<stack>
#include<set>
#include<list>
#include<algorithm>
#include <chrono>
#include<random>
using namespace std;
typedef long long LL;
//#define int long long
typedef unsigned long long ULL;
typedef pair<LL, LL>PII;
typedef pair<double, double>PDD;
typedef pair<char, char>PCC;
LL n, m, k;
const LL inf = 1e18;
const LL N = 5e5 + 10;
const LL mod = 1e9 + 7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int x, int y) {
return uniform_int_distribution<int>(x, y)(rng);
}
struct HashSeq {
vector<long long> P, H;
int MOD, BASE;
HashSeq() {}
HashSeq(string& s, int MOD, int BASE) : MOD(MOD), BASE(BASE) {
int n = s.size();
P.resize(n + 1);
P[0] = 1;
for (int i = 1; i <= n; i++) P[i] = P[i - 1] * BASE % MOD;
H.resize(n + 1);
H[0] = 0;
for (int i = 1; i <= n; i++) H[i] = (H[i - 1] * BASE + (s[i - 1] ^ 7)) % MOD;
}
long long query(int l, int r) {
return (H[r] - H[l - 1] * P[r - l + 1] % MOD + MOD) % MOD;
}
};
int MOD1 = 998244353 + rnd(0, 1e9), BASE1 = 233 + rnd(0, 1e3);
int MOD2 = 998244353 + rnd(0, 1e9), BASE2 = 233 + rnd(0, 1e3);
struct HashString {
HashSeq hs1, hs2;
HashString(string& s) : hs1(HashSeq(s, MOD1, BASE1)), hs2(HashSeq(s, MOD2, BASE2)) {}
long long query(int l, int r) {
return hs1.query(l, r) * MOD1 + hs2.query(l, r);
}
};
LL sum[26][26];
void solve() {
int q;cin >> n >> q;
map<LL, int>mp;
LL ans = 0;
map<LL, vector<char>>rec;
for (int i = 1;i <= n;i++) {
string s;cin >> s;
HashString h(s);
int m = s.size();
s = " " + s;
LL all = h.query(1, m);
if (mp.count(all))ans += mp[all];
rec[-1].push_back(s[1]);
for (int j = 1;j < m;j++) {
LL res = h.query(1, j);
mp[res] += 1;
rec[res].push_back(s[j + 1]);
}
}
for (auto [x, y] : rec) {
vector<int>cnt(26);
for (auto c : y) {
int d = c - 'a';
for (int i = 0;i < 26;i++) {
sum[i][d] += cnt[i];
}
cnt[d]++;
}
}
while (q--) {
string s;cin >> s;
vector<int>pos(26);
for (int i = 0;i < 26;i++) {
pos[s[i] - 'a'] = i;
}
LL res = ans;
for (int i = 0;i < 26;i++) {
for (int j = 0;j < 26;j++) {
if (pos[i] < pos[j]) {
res += sum[j][i];
}
}
}
cout << res << "\n";
}
}
signed main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int t = 1;
//cin >> t;
while (t--) {
solve();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3568kb
input:
5 3 aac oiputata aaa suikabudada aba abcdefghijklmnopqrstuvwxyz qwertyuiopasdfghjklzxcvbnm aquickbrownfxjmpsvethlzydg
output:
4 3 4
result:
ok 3 number(s): "4 3 4"
Test #2:
score: 0
Accepted
time: 166ms
memory: 37988kb
input:
100 100 spkfvrbkfsspmnlgrdojwdqutknvzejorqxsmfgbfrhpxkrrtravhmxenjrzypkxounrbantpkaezlcnudjmwxpgqakfoxcmdjcygujdtpluovbisxmklkzzuuyziapzyrszcggjkzrwmtyolnbobubbezdwmumyzyhaogiiolictzjpxbyaamecytpnyzxlumxjkzyfavxlzdwtgrxtqcnddzfocznitlaxlpcceuelqlbmyzetlpaivxnuvuctsbjbaulmbmkangqahpdojqimvmcugjeczkgx...
output:
2368 2693 2179 2466 2435 2370 2604 2468 2335 2268 2686 2781 2538 2208 2386 2539 2728 2383 2248 2372 2446 2266 2290 2688 2602 2515 2634 2558 2598 2632 2763 2255 2557 2579 2367 2516 2676 2273 2429 2556 2576 2635 2422 2829 2362 2552 2377 2261 2603 2516 2298 2282 2520 2333 2505 2287 2261 2476 2791 2328 ...
result:
ok 100 numbers
Test #3:
score: 0
Accepted
time: 280ms
memory: 18356kb
input:
500000 5 ru x tb s e w e m l b g zr jp h js xk fjwtk wtkem o ev a a x sy dh y kkdcxfr hgq j k xr s cvwbrlk u u x wtvgef dzxsk qv gxl g m rpl ldp q lc dk g k im o yhn z a knc tyv mz ak qdhq c niw o j heu w g e kt n inqt i al q ebphky sv m mry oj cl j r sf vpd u rio sfkg m el s zs g o e njp r xczcm gh...
output:
61908555824 61940608380 61883035862 61951203480 61924597894
result:
ok 5 number(s): "61908555824 61940608380 61883035862 61951203480 61924597894"
Test #4:
score: 0
Accepted
time: 385ms
memory: 18368kb
input:
500000 50000 f s f jk uodve vba znm j m hp k h xak c dh d p o d di yo uf k k gs v al nei v m ae d d xb z s q r vhk oby q z r lvy eicd i y m hlyz obbsq wvkme rmg j u zw yi b z v u n j o in k jf t jq yi wlvh z c f w p g bh mz g f x b smq sd h h gtxhili cmsp ey lwpytx k k x d ne a d d k a goh xlgfa m k...
output:
61888287558 61930516390 61858655464 61942961952 61922529832 61878246092 61932262526 61862322500 61918006978 61913886063 61938822453 62033664629 61891299439 62009975003 61843758593 61976982218 62005241947 61910419027 61881404576 61847283168 61916833201 61875104962 61760148176 61749589452 61913247427 ...
result:
ok 50000 numbers
Test #5:
score: 0
Accepted
time: 245ms
memory: 6520kb
input:
500000 50000 c c aa b aba cac cb bac b scaa acc b aaab a b bc cac a aaaaacc b b bba b cc cac a a caaab ababac c c a babcc a b a ccbbbb ca sa ab a ab c cc b ac c ma c bac c ba cb c abbb cc ba cc b a ccc bccb b acc a cc ba bab c a c cb ca ca aa b ccca ccb bb aabaac bab bba ba b a aa ba a c b cac b bbc...
output:
56939499677 56925529159 56952982265 56943683544 56925041678 56938422403 56954018081 56948416401 56928120228 56895875378 56959065136 56955344850 56897398487 56944825108 56891765167 56897364738 56884948909 56898628723 56897633139 56899291229 56885908584 56915640298 56893213810 56957115221 56951756805 ...
result:
ok 50000 numbers
Test #6:
score: 0
Accepted
time: 228ms
memory: 5436kb
input:
500000 50000 bb bb a ab baaabbb aa baa a b baaa b aba a bb b bbba aba aaaab b a b ba bbb b aaa a babaaba b abb b aabbbabab b bbab bb aaababba bba ba ab ba b b ba b b aaa bbbb a baababa ba abb a aa abb b a ab ba bba b b a bbaa aab bbb aa a b ba a a bbb a ab aabb b bbb ai bb b bbaa a a bb a a babaa ba...
output:
53795769419 53801388771 53746509245 53780254654 53747039444 53744912906 53749837662 53737088518 53742571728 53792850823 53802513135 53750285354 53799688533 53737182227 53794067145 53743365039 53806922609 53804011826 53734792021 53796973534 53742991776 53783732164 53746458143 53741415942 53742075355 ...
result:
ok 50000 numbers
Test #7:
score: 0
Accepted
time: 260ms
memory: 7384kb
input:
500000 50000 cc a b d ddb d acadabba ccdd d b abcaa dc d cc d a b d d a ddcda d ac d abdd d dcc bbbb ddb ac ccc dabcd ba bd cac b abaaaa b ca dcaad ad c a dbc ac bad dba d c c a a d c d a ca b d b c d cbcd a c dad ca bd cadd db b a c b c a d dc da c ddc ba a c daa ad ddc addbb abcbcbc db a b cdabc d...
output:
58414448830 58387012191 58421956885 58455897210 58334007420 58377125117 58400958944 58393108334 58344520117 58395118441 58384403636 58363585498 58430862242 58444907551 58371758190 58399599084 58426464877 58470402162 58344508726 58420636332 58428823681 58378278513 58396305377 58423683882 58399189237 ...
result:
ok 50000 numbers
Test #8:
score: -100
Time Limit Exceeded
input:
3999 50000 zwtboxnjfnwwoiiiuzqhsqxwqgjnggnocmyfexpcrqvsdgepqixtfofzmfylhwffeopnxggppwdwjbvidsmjeivhlkvspmhfltcskuwdhwcyfdvnmufnlmxybxswgvgfopodnvzvdmaljmsnpytmrtdkyqfbwmftxfpuzlxzb xasjyfbxtfyyynfmvatrbkujxrclxqpjncrzsmbqcppyzwpdszybhyyuugitbodnofqmykknpevxmdypitpkriunutedyenladpfdjkuhpgtpyksahqnbii...