이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//Bismillahir-Rahmanir-Rahim
# include <bits/stdc++.h>
# define pb push_back
# define ff first
# define ss second
# define nl "\n"
# define sz(x) ((int)(x).size())
# define all(x) (x).begin(), (x).end()
# define deb(x) cerr << #x << " = " << x << endl;
# define pll pair <ll, ll>
# define pii pair <int, int>
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll maxn = 1e5 + 7;
const ll inf = 2e18 + 0;
const ll mod = 1e9 + 7;
const ll dx[] = {-1, 1, 0, 0};
const ll dy[] = {0, 0, -1, 1};
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll n, q, p[maxn];
string s;
ll tl[maxn], tr[maxn];
ll pref[maxn][26];
bool ok (ll mid) {
memset(pref, 0, sizeof pref);
string str = s;
for (ll i = 1; i <= mid; ++i) {
str[p[i]] = '*';
}
for (ll i = 1; i <= n; ++i) {
for (ll j = 0; j < 26; ++j) {
pref[i][j] = pref[i - 1][j];
}
if (str[i] != '*') {
pref[i][(str[i] - 'a')]++;
}
}
bool ok = 1;
for (ll i = 1; i <= q && ok; ++i) {
for (ll j = 0; j < 26 && ok; ++j) {
if (pref[tr[i]][j] - pref[tl[i] - 1][j] > 1) {
ok = 0;
}
}
}
return ok;
}
void ma1n (/* SABR */) {
cin >> s;
n = sz(s);
s = ' ' + s;
cin >> q;
for (ll i = 1; i <= q; ++i) {
cin >> tl[i] >> tr[i];
}
for (ll i = 1; i <= n; ++i) {
cin >> p[i];
}
ll l = 0, r = n - 1, ans = n;
while (l <= r) {
ll mid = (l + r) >> 1;
if (ok(mid)) {
r = mid - 1;
ans = mid;
}
else {
l = mid + 1;
}
}
cout << ans << nl;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
// freopen("file.in", "r", stdin);
// freopen("file.out", "w", stdout);
int ttt = 1;
// cin >> ttt;
for (int test = 1; test <= ttt; ++test) {
// cout << "Case " << test << ":" << '\n';
ma1n();
}
return 0;
}
// 998batrr | BbIWEJI 3A TObOU!!!
// tourist | BbIWEJI 3A TObOU!!!
# | 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... |