QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#244500 | #4484. AC/DC | ucup-team203# | WA | 7158ms | 240192kb | C++20 | 2.2kb | 2023-11-09 10:34:22 | 2023-11-09 10:34:22 |
Judging History
answer
#include <bits/stdc++.h>
using i64 = long long;
using namespace std;
const int N = 2e5 + 5;
// const int B = 400;
// const int M = 4e6 + 5;
const int base = 191;
/// const int mod = 998244353;
const int mod = 1e9 + 9;
// const double pi = acos(-1);
int p[N], h[N];
int opt, m;
string s, c;
int get(int l, int r)
{
return (h[r] - (i64)h[l - 1] * p[r - l + 1] % mod + mod) % mod;
}
int cal(string &s)
{
int res = 0;
for (char c : s)
res = ((i64)res * base % mod + (c - 'a' + 1)) % mod;
return res;
}
void solve()
{
cin >> s >> m;
int n = s.length(), l = 1, r = n;
for (int i = 0; i < n; i++)
h[i + 1] = ((i64)h[i] * base % mod + (s[i] - 'a' + 1)) % mod;
int ans = 0;
set<int> occur;
map<int, int> cnt;
while (m--)
{
cin >> opt;
if (opt == 1)
{
cin >> c;
c[0] = char(((c[0] - 'a') ^ ans) % 26 + 'a');
r++;
h[r] = ((i64)h[r - 1] * base % mod + (c[0] - 'a' + 1)) % mod;
for (auto &len : occur)
{
int tmp = get(r - len + 1, r);
cnt[tmp]++;
}
}
else if (opt == 2)
{
for (auto &len : occur)
{
int tmp = get(l, l + len - 1);
if (!--cnt[tmp])
cnt.erase(tmp);
}
l++;
}
else
{
cin >> c;
for (char &d : c)
d = char(((d - 'a') ^ ans) % 26 + 'a');
ans = 0;
int len = c.length(), tmp = cal(c);
if (!occur.count(len))
{
occur.insert(len);
for (int j = l + len - 1; j <= r; j++)
cnt[get(j - len + 1, j)]++;
}
if (cnt.count(tmp))
ans = cnt[tmp];
cout << ans << '\n';
}
}
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
p[0] = 1;
for (int i = 1; i < N; i++)
p[i] = (i64)p[i - 1] * base % mod;
int t = 1;
cin >> t;
// cout << fixed << setprecision(10);
while (t--)
solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 7158ms
memory: 240192kb
input:
5 bdcdeabadbeddbecdcecabcdebaccaedbeabaccbdbeebebeebdddcaceedeccabddddadbddbcdaeaceabcceeebcedddeebeaeabbdbcecbdcbedbbebeccecadbabbedddcecacddceaededdbaeecccacaaddcddacacbbacaeceedbdddaabaadadddbdbebbaecbebcbcebaedcaaacbeecedcacbddedabaacbbcaaacdadbaecdeabbdbbdebbbecdcbcbedbaebcdaaebacddeddccbcacbbe...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
wrong answer 5080th lines differ - expected: '187', found: '188'