이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using i64 = long long;
constexpr i64 P = 1E9 + 7, M = 5;
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int n, m;
std::cin >> n >> m;
std::vector<std::string> s(n);
for (int i = 0; i < n; i++) {
std::cin >> s[i];
}
std::sort(s.begin(), s.end());
std::vector<std::tuple<int, int, int>> Q;
for (int i = 0; i < m; i++) {
std::string p, q;
std::cin >> p >> q;
int l = std::lower_bound(s.begin(), s.end(), p) - s.begin();
int r = std::upper_bound(s.begin(), s.end(), p + 'Z') - s.begin();
i64 H = 0;
for (char c : q) {
H *= M;
H += std::string("AGCU").find(c) + 1;
H %= P;
}
Q.emplace_back(l, -H, i);
Q.emplace_back(r, H, i);
}
std::sort(Q.begin(), Q.end());
std::vector<int> ans(m);
std::map<int, int> cnt;
int j = 0;
for (int i = 0; i < n; i++) {
int p, H, id;
while (j < int(Q.size())) {
std::tie(p, H, id) = Q[j];
if (p != i) {
break;
}
if (H < 0) {
ans[id] -= cnt[-H];
} else {
ans[id] += cnt[H];
}
j++;
}
i64 h = 0, pw = 1;
for (int j = int(s[i].size()) - 1; j >= 0; j--) {
h = (h + pw * (std::string("AGCU").find(s[i][j]) + 1)) % P;
pw *= M;
cnt[h]++;
}
}
while (j < int(Q.size())) {
int p, H, id;
std::tie(p, H, id) = Q[j];
if (H < 0) {
ans[id] -= cnt[-H];
} else {
ans[id] += cnt[H];
}
j++;
}
for (int i = 0; i < m; i++) {
std::cout << ans[i] << "\n";
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |