QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#845243#1942. Another Substring Query ProblemCYYHWA 5524ms788924kbC++202.2kb2025-01-06 15:33:232025-01-06 15:33:23

Judging History

This is the latest submission verdict.

  • [2025-01-06 15:33:23]
  • Judged
  • Verdict: WA
  • Time: 5524ms
  • Memory: 788924kb
  • [2025-01-06 15:33:23]
  • Submitted

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;
const int N = 2e5 + 5, P = 1e9 + 7;
char s[N];
int n, q, k, B;
ll 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;
    }
}
ll get(int l, int r) {
    return (hsh[r] - hsh[l - 1] * base[r - l + 1] % P + P) % P;
}
unordered_map <ll, vector <int> > str;
signed main() {
    scanf("%s", s + 1); n = strlen(s + 1); B = 50;
    init();
    R(i, 1, n) {
        R(j, 1, B) {
            if (i + j - 1 > n) break;
            ll 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);
        ll now = 0;
        R(i, 1, m) now = (now * 10 + t[i] - 'a') % P;
        if (m <= B) {
            if (str[now].size() < k) puts("-1");
            else write(str[now][k - 1]), ptc('\n');
        } else {
            R(i, 1, n - m + 1) {
                ll v = get(i, i + m - 1);
                if (v == now) --k;
                if (!k) {
                    write(i), ptc('\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: 231ms
memory: 45892kb

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
Wrong Answer
time: 5524ms
memory: 788924kb

input:

gnzlzbsarybaxilacuopvdkhjfiynrgfdhsrecyxedcrriztcxboczhfaseqglcwshaewaepasxqpaxxbroxndbxqabrvtrrshrnnlyfodtxyltjkbghfkjcqrqsuwdsgypcaroaojqbfrjqbdrimglxcqtfmqaeogqunaegfpfzcmyjwfgbwaigwitcyspiedbisjuedeyseneuzjdteifzvdfzhenapmmreqpvwsmtrxowjnmmrthzhojgxsoppfgfgohoghuwvqclzsmeydusfndrdyqokpqwupixyoxr...

output:

192967
-1
167748
-1
135762
-1
72908
-1
108949
-1
-1
4268
93080
11488
31920
26376
-1
4453
139271
-1
22647
77884
-1
122153
-1
-1
7819
6015
10616
8529
4454
3381
2190
5422
15316
198
2560
9336
13516
6691
10823
5199
2451
12210
3134
5293
5821
8926
6316
7538
4345
6233
5070
4586
3732
5318
3548
5999
3436
3828...

result:

wrong answer 1st lines differ - expected: '-1', found: '192967'