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 namespace std;
using ll = long long int;
const int maxn = 2e5 + 5;
const int oo = 1e9 + 7;
const ll inf = 1e18;
int n, q;
string s;
int pre[maxn][27], del[maxn];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
cin >> s;
int n = (int)s.length();
s = ' ' + s;
cin >> q;
vector<pair<int, int>> a(q);
for (int i = 0; i < q; i++)
cin >> a[i].first >> a[i].second;
for (int i = 1; i <= n; i++)
cin >> del[i];
int l = 0, r = n;
int ans = n;
while (l <= r) {
int mid = (l + r) >> 1;
vector<int> cnt(n + 1, 0);
for (int i = 1; i <= mid; i++) {
cnt[del[i]]++;
}
for (int i = 1; i <= n; i++) {
for (int j = 0; j < 26; j++) {
if ((s[i] - 'a') == j && !cnt[i])
pre[i][j] = pre[i - 1][j] + 1;
else
pre[i][j] = pre[i - 1][j];
}
}
int ck = 0;
for (int i = 0; i < q; i++) {
int ll = a[i].first;
int rr = a[i].second;
for (int j = 0; j < 26; j++) {
if (pre[rr][j] - pre[ll - 1][j] > 1) {
ck = 1;
break;
}
}
if (ck == 1)
break;
}
if (ck == 0) {
ans = mid;
r = mid - 1;
}
else
l = mid + 1;
}
cout << ans;
}
# | 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... |