-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathB.cpp
62 lines (59 loc) · 1.29 KB
/
B.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include<bits/stdc++.h>
using namespace std;
#define fastio ios::sync_with_stdio(false);cin.tie(NULL)
long long ara[200005][35];
int main()
{
fastio;
long long n,m,i,mx,j,low,high,mid;
string s;
cin>>n;
cin>>s;
for(i=0;i<26;i++)
ara[0][i]=0;
for(i=1;i<=n;i++)
{
int x=s[i-1]-'a';
for(j=0;j<26;j++)
{
if(j==x)
ara[i][j]=ara[i-1][j]+1;
else
ara[i][j]=ara[i-1][j];
}
}
cin>>m;
while(m--)
{
string nm;
cin>>nm;
int b[35]={0};
for(i=0;i<nm.size();i++)
b[nm[i]-'a']++;
mx=0;
for(i=0;i<26;i++)
{
if(b[i]>0)
{
low=1;
high=n;
while(low<=high)
{
mid=(low+high)/2;
if(ara[mid][i]>=b[i] && ara[mid-1][i]<b[i])
{
mx=max(mx,mid);
break;
}
else if(ara[mid][i]>=b[i])
high=mid-1;
else
low=mid+1;
}
}
//cout<<mx<<"\n";
}
cout<<mx<<"\n";
}
return 0;
}