链接:传送门

题意:有p,t两个字符串,现在有p.size()次操作,问最多能执行多少次操作,使得t仍旧是p的子序列.一开始t一定是p的子序列

思路:二分check

#include<bits/stdc++.h>
#define PI acos(-1.0)
#define pb push_back
#define F first
#define S second
#define debug puts
using namespace std;
typedef long long ll;

const int N=2e5+5;
const int MOD=1e9+7;
const int INF=0x3f3f3f3f;
string p,t;
int a[N],sz;

bool check(int st){
    vector<int> vec;
    for(int i=st;i<sz;i++)  vec.pb(a[i]-1);
    sort(vec.begin(),vec.end());
    string tt="";
    for(auto i:vec) tt+=p[i];
//    cout << tt << endl;
    int i,j;
    for(i=0,j=0;i<(int)tt.size();i++){
        if(j<(int)t.size()&&tt[i]==t[j])    j++;
    }
    return j==(int)t.size();
}

int main(void){
    cin >> p >> t;
    sz=(int)p.size();
    for(int i=0;i<sz;i++)  scanf("%d",&a[i]);
    int l=0,r=sz-1,ans;
    while(l<=r){
        int mid=l+r>>1;
//        cout <<"mid="<<mid<<" ";
        if(check(mid))  l=mid+1,ans=mid;
        else    r=mid-1;
    }
    cout << ans << endl;

    return 0;
}
void bef0re_submit(){
    debug("Make sure the algorithm is right!");
    debug("LONG LONG!!!");
    debug("Check n and m are misuesd???");
    debug("Make sure output format is right/// Yes??YES  (%.20LF)???");
    debug("if all meet,run with special situation!!!");
    debug("I confirm that I have done all above");
}


/*********
4 5
0 3 8 4
*********/