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;
#define int long long
#define sz(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()
#define db(x) cout << "[" << #x << "]: " << x << '\n';
const int N = 1e5 + 4;
int a[N], b[N], d[N], p[N];
int pr[N][26];
int n, q;
bool m[N];
char x;
bool check(int md) {
memset(m, 0, sizeof(m));
for (int i = 1; i <= md; ++i) {
m[p[i]] = 1;
}
for (int i = 1; i <= n; ++i) {
for (int j = 0; j < 26; ++j) {
pr[i][j] = pr[i - 1][j];
}
if (!m[i]) {
++pr[i][d[i]];
}
}
bool f = true;
for (int i = 1; i <= q; ++i) {
for (int j = 0; j < 26; ++j) {
f &= (pr[b[i]][j] - pr[a[i] - 1][j] <= 1);
}
}
return f;
}
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(0);
string s; cin >> s;
n = sz(s);
for (int i = 1; i <= n; ++i) {
d[i] = (int)(s[i - 1] - 'a');
}
cin >> q;
for (int i = 1; i <= q; ++i) {
cin >> a[i] >> b[i];
}
for (int i = 1; i <= n; ++i) {
cin >> p[i];
}
int l = 0, r = n;
while (l < r) {
int md = (l + r) / 2;
if (check(md)) r = md;
else l = md + 1;
}
cout << l;
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... |