이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ar array
const int mxN=1e5;
int n, q, p[mxN], ps[mxN+1][26];
string s;
ar<int, 2> qry[mxN];
bool ok(int x) {
memset(ps, 0, sizeof(ps));
string cur=s;
for (int i=0; i<x; ++i) cur[p[i]]='#';
for (int i=0; i<n; ++i) {
for (int j=0; j<26; ++j) ps[i+1][j]=ps[i][j];
if (cur[i]!='#') ps[i+1][cur[i]-'a']++;
}
for (int i=0; i<q; ++i) {
int a=qry[i][0], b=qry[i][1];
for (int j=0; j<26; ++j) if (ps[b][j]-ps[a][j]>1) return 0;
}
return 1;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> s >> q, n=s.size();
for (int i=0; i<q; ++i) {
int a, b; cin >> a >> b, --a;
qry[i]={a, b};
}
for (int i=0; i<n; ++i) cin >> p[i], --p[i];
int l=0, r=n;
while(l<r) {
int mid=(l+r)/2;
if (ok(mid)) r=mid;
else l=mid+1;
}
cout << l << "\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... |