QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#845623#1942. Another Substring Query ProblemyqrWA 1067ms533640kbC++231.8kb2025-01-06 17:30:102025-01-06 17:30:11

Judging History

This is the latest submission verdict.

  • [2025-01-06 17:30:11]
  • Judged
  • Verdict: WA
  • Time: 1067ms
  • Memory: 533640kb
  • [2025-01-06 17:30:10]
  • Submitted

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 = 1000000009;
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;
	for(int i = 1; i <= n; i++) H[i] = H[i - 1] + Hash(s[i]);
	pows[0] = 1;
	for(int i = 1; i <= n; i++) pows[i] = pows[i - 1] * base;

	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: 1067ms
memory: 533640kb

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'