이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#ifndef Local
#pragma GCC optimize("O3,unroll-loops")
#endif
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define lim 200000
using namespace std;
const int mod=1000000007ll;
void solve(){
string s;
cin>>s;
int n=s.size();
int Q;
cin>>Q;
pair<int,int>q[Q];
for(auto&qq:q){
cin>>qq.first>>qq.second;
qq.first--,qq.second--;
}
int a[n];
for(int i=0;i<n;i++){
cin>>a[i];
a[i]--;
}
int l=0,r=n,ans=-1;
while(l<=r){
int mid=(l+r)/2;
string cur=s;
for(int i=0;i<mid;i++){
cur[a[i]]='.';
}
map<char,vector<int>>all;
for(int i=0;i<n;i++){
all[cur[i]].pb(i);
}
for(int i=0;i<Q;i++){
for(char c='a';c<='z';c++){
if(!all.count(c))continue;
auto&v=all[c];
auto pp=(lower_bound(v.begin(),v.end(),q[i].first));
if(pp==v.end())continue;
pp++;
int p=(pp!=v.end()?(*pp):n);
if(p<=q[i].second){
cerr<<q[i].second<<"\n";
l=mid+1;
goto fail;
}
}
}
ans=mid;
r=mid-1;
fail:;
}
cout<<ans<<"\n";
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);cout.tie(NULL);
#ifdef Local
freopen(".in","r",stdin);
freopen(".out","w",stdout);
#else
#endif
int t=1;
//cin>>t;
while (t--)
{
solve();
}
}
# | 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... |