This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("unroll-loops,Ofast,O3")
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define spc << " " <<
#define endl "\n"
#define all(x) x.begin(), x.end()
#define int long long
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<ii>
#define st first
#define nd second
#define inf 1000000009
#define MOD 1000000007
#define lim 200005
using namespace std;
void solve(){
string s; cin >> s;
int n=s.size();
string pref[n+5]; pref[0]=s;
int q; cin >> q;
ii que[q+5];
for(int i=1; i<=q; i++) cin >> que[i].st >> que[i].nd;
for(int i=1; i<=n; i++){
int a; cin >> a;
pref[i] = pref[i-1];
pref[i][a-1] = '*';
}
int cnt[26][n+5];
int l=0, r=n, ans=0;
while(l<=r){
int mid = (l+r)/2;
for(int i=0; i<26; i++){
cnt[i][0]=0;
for(int j=1; j<=n; j++){
cnt[i][j] = cnt[i][j-1];
if((pref[mid][j-1] - 'a') == i) cnt[i][j]++;
}
}
int flag=1;
for(int i=1; i<=q; i++){
for(int c=0; c<26; c++){
if(cnt[c][que[i].nd] - cnt[c][que[i].st-1] > 1){
flag=0;
break;
}
}
}
if(flag){
ans = mid;
r = mid-1;
}
else{
l = mid+1;
}
}
cout << ans << endl;
}
signed main(){
ios_base::sync_with_stdio(false);cin.tie(0);
#ifdef Local
freopen("in","r",stdin);
freopen("out","w",stdout);
#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... |