QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#845168 | #1942. Another Substring Query Problem | CYYH | TL | 927ms | 717532kb | C++14 | 2.2kb | 2025-01-06 15:14:28 | 2025-01-06 15:14:28 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define il inline
#define ptc putchar
#define pb push_back
#define R(i, l, r) for (int i = l; i <= r; ++i)
#define debug puts("--------------------------------------------")
typedef long long ll;
typedef pair<int, int> PII;
namespace ZT {
template <typename T>
il void read(T &x) {
x = 0; T f = 1; char ch;
while (!isdigit(ch = getchar())) f -= (ch == '-') << 1;
while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch & 15), ch = getchar();
x *= f;
}
template <typename T, typename ...L>
il void read(T &x, L &...y) {read(x); read(y...);}
template <typename T>
il void write(T x) {
if (x < 0) ptc('-'), x = -x;
if (x > 9) write(x / 10);
ptc(x % 10 + '0');
}
template <typename T, typename ...L>
il void write(T &x, L &...y) {write(x), ptc(' '); write(y...);}
}
using namespace ZT;
#define int ll
const int N = 2e5 + 5, P = 1e9 + 7;
char s[N];
int n, q, k, B;
int hsh[N], base[N] = {1};
char t[N];
void init() {
R(i, 1, n) {
base[i] = base[i - 1] * 10 % P;
hsh[i] = (hsh[i - 1] * 10 % P + s[i] - 'a') % P;
}
}
int get(int l, int r) {
return (hsh[r] - hsh[l - 1] * base[r - l + 1] % P + P) % P;
}
map <int, vector <int> > str;
signed main() {
scanf("%s", s + 1); n = strlen(s + 1); B = sqrt(n);
init();
R(i, 1, n) {
R(j, 1, B) {
if (i + j - 1 > n) break;
int v = get(i, i + j - 1);
str[v].push_back(i);
}
}
read(q);
while (q--) {
scanf("%s", t + 1); read(k); int m = strlen(t + 1);
int now = 0;
R(i, 1, m) now = (now * 10 + t[i] - 'a') % P;
if (m <= B) {
if (str[now].size() < k) puts("-1");
else cout << str[now][k - 1] << '\n';
} else {
R(i, 1, n - m + 1) {
int v = get(i, i + m - 1);
if (v == now) --k;
if (!k) {
cout << i << '\n';
break;
}
}
if (k) puts("-1");
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 927ms
memory: 717532kb
input:
hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh...
output:
50997 112451 97534 13355 150562 5772 146250 10904 4343 194777 71395 96501 6809 18571 166901 114789 123587 176339 29660 82650 63509 80101 47907 66143 199971 108032 140518 49221 46212 28127 61461 149025 142818 33646 17132 196161 36671 28656 16860 141951 139429 72866 162807 21343 194803 16263 118701 20...
result:
ok 631 lines
Test #2:
score: -100
Time Limit Exceeded
input:
gnzlzbsarybaxilacuopvdkhjfiynrgfdhsrecyxedcrriztcxboczhfaseqglcwshaewaepasxqpaxxbroxndbxqabrvtrrshrnnlyfodtxyltjkbghfkjcqrqsuwdsgypcaroaojqbfrjqbdrimglxcqtfmqaeogqunaegfpfzcmyjwfgbwaigwitcyspiedbisjuedeyseneuzjdteifzvdfzhenapmmreqpvwsmtrxowjnmmrthzhojgxsoppfgfgohoghuwvqclzsmeydusfndrdyqokpqwupixyoxr...