This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using std::vector;
using std::array;
using std::pair;
using std::tuple;
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
std::string S;
std::cin >> S;
const int N = S.size();
int Q;
std::cin >> Q;
vector<int> L(Q), R(Q);
for (int i = 0; i < Q; ++i) {
std::cin >> L[i] >> R[i];
L[i] -= 1;
}
vector<int> P(N);
for (auto& x : P) {
std::cin >> x;
x -= 1;
}
int ok = N, ng = -1;
array<vector<int>, 26> sum;
sum.fill(vector<int>(N + 1));
while (ok - ng > 1) {
const int md = (ok + ng) / 2;
array<vector<int>, 26> sum;
sum.fill(vector<int>(N + 1));
for (int i = md; i < N; ++i) {
sum[S[P[i]] - 'a'][P[i] + 1] += 1;
}
bool f = true;
for (int k = 0; k < 26; ++k) {
for (int i = 0; i < N; ++i) {
sum[k][i + 1] += sum[k][i];
}
for (int j = 0; j < Q; ++j) {
if (sum[k][R[j]] - sum[k][L[j]] > 1) {
f = false;
break;
}
}
if (!f) {
break;
}
}
(f ? ok : ng) = md;
}
std::cout << ok << '\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... |
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |