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>
#define sz(x) ((int)x.size())
using namespace std;
const int N = 100100;
string s;
int n, p[N], l[N], r[N], sf[N][26], q;
bool mrk[N];
bool ok(int x){
fill(mrk, mrk + n, 0);
for (int i = 0; i < x; i++)
mrk[p[i]] = 1;
fill(sf[n], sf[n] + 26, 0);
for (int i = n - 1; i >= 0; i--){
for (int j = 0; j < 26; j++)
sf[i][j] = sf[i + 1][j];
if (!mrk[i])
sf[i][s[i] - 'a']++;
}
for (int i = 0; i < q; i++)
for (int j = 0; j < 26; j++)
if (sf[l[i]][j] - sf[r[i]][j] > 1)
return 0;
return 1;
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
// freopen("in.txt","r",stdin);
cin >> s;
n = sz(s);
cin >> q;
for (int i = 0; i < q; i++){
cin >> l[i] >> r[i];
l[i]--;
}
for (int i = 0; i < n; i++){
cin >> p[i];
p[i]--;
}
int l1 = 0, r1 = n;
while (l1 < r1){
int md = (l1 + r1) >> 1;
if (ok(md))
r1 = md;
else l1 = md + 1;
}
cout << l1;
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... |