QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#845632 | #1942. Another Substring Query Problem | yqr | WA | 999ms | 534508kb | C++23 | 1.8kb | 2025-01-06 17:35:01 | 2025-01-06 17:35:03 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
constexpr int maxn = 200005;
constexpr ull base = 97, mod = ~0ull;
ull pows[maxn];
string s, t[maxn];
int n, q, rk[maxn];
unordered_map<ull, vector<int> > app;
vector<int> lens;
ull Add(ull a, ull b) {return (a += b) >= mod? a - mod: a;}
struct Hash {
int len;
ull val;
Hash() {len = val = 0;}
Hash(const char &a) {len = 1, val = a - 'a' + 1;}
Hash(const int &len, const ull &val) {this->len = len, this->val = val;}
Hash(const string &str)
{
len = val = 0;
for(char c : str) *this = *this + Hash(c);
}
friend Hash operator + (const Hash &a, const Hash &b) {
return Hash(a.len + b.len, Add(a.val * pows[b.len] % mod, b.val));
}
}h[maxn], H[maxn];
ull query(int l, int r) {return Add(H[r].val, mod - H[l - 1].val * pows[r - l + 1] % mod);}
int main()
{
// freopen(".in", "r", stdin);
// freopen(".out", "w", stdout);
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin >> s >> q, n = s.size(), s = ' ' + s;
pows[0] = 1;
for(int i = 1; i < n; i++) pows[i] = pows[i - 1] * base;
for(int i = 1; i <= n; i++) H[i] = H[i - 1] + Hash(s[i]);
for(int i = 1; i <= q; i++) cin >> t[i] >> rk[i], lens.push_back(t[i].size());
sort(lens.begin(), lens.end()), lens.erase(unique(lens.begin(), lens.end()), lens.end());
for(int i = 1; i <= n; i++) for(int j : lens) if(i + j - 1 <= n)
app[query(i, i + j - 1)].push_back(i);//, printf("%d,%d\n", i, j);
for(int i = 1; i <= q; i++)
{
ull val = Hash(t[i]).val;
if(app.find(val) == app.end())
{
puts("-1");
continue;
}
vector<int> &p = app[val];
// for(int j : p) printf("%d ", j);
// puts("");
if(p.size() < rk[i]) puts("-1");
else printf("%d\n", p[rk[i] - 1]);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 999ms
memory: 534508kb
input:
hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh...
output:
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 ...
result:
wrong answer 1st lines differ - expected: '50997', found: '-1'