mirror of
https://gitcode.com/Zengtudor/alg2025.git
synced 2025-09-04 01:01:43 +00:00
update
This commit is contained in:
parent
e04a08e502
commit
776290a513
68
src/8/22/P8306.cpp
Normal file
68
src/8/22/P8306.cpp
Normal file
@ -0,0 +1,68 @@
|
||||
#include <cstdint>
|
||||
#include <iostream>
|
||||
#include <istream>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
using ll = int64_t;
|
||||
|
||||
const ll maxlen = 1e3;
|
||||
|
||||
#define s(j)s[(j)]-'a'
|
||||
#define pv(v)do{/*std::cout<<#v<<" :"<<(v)<<'\n';*/}while(0)
|
||||
|
||||
static inline void solve(){
|
||||
ll n,q;
|
||||
std::cin>>n>>q;
|
||||
static std::vector<std::vector<std::pair<ll, ll>>> t;
|
||||
t.clear();
|
||||
t.resize(maxlen,std::vector<std::pair<ll, ll>>(27));
|
||||
ll tot=1;
|
||||
pv("input");
|
||||
for(ll i=1;i<=n;i++){
|
||||
static std::string s;
|
||||
std::cin>>s;
|
||||
ll now=0;
|
||||
for(ll j=0;j<s.size();j++){
|
||||
pv(j);
|
||||
pv(now);
|
||||
pv(s(j));
|
||||
t[now][s(j)].first++;
|
||||
pv(t[now][s(j)].first);
|
||||
if(t[now][s(j)].second==0){
|
||||
t[now][s(j)].second=tot++;
|
||||
}
|
||||
now=t[now][s(j)].second;
|
||||
}
|
||||
}
|
||||
for(ll i=1;i<=q;i++){
|
||||
ll ans=0;
|
||||
static std::string s;
|
||||
std::cin>>s;
|
||||
ll now=0;
|
||||
pv("check");
|
||||
for(ll j=0;j<s.size();j++){
|
||||
pv(j);
|
||||
pv(now);
|
||||
pv(t[now][s(j)].first);
|
||||
if(t[now][s(j)].second==0){
|
||||
break;
|
||||
}else{
|
||||
ans+=t[now][s(j)].first;
|
||||
now=t[now][s(j)].second;
|
||||
}
|
||||
}
|
||||
std::cout<<ans<<'\n';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int main(){
|
||||
std::iostream::sync_with_stdio(false);
|
||||
std::cin.tie(nullptr);
|
||||
ll T;
|
||||
std::cin>>T;
|
||||
while(T--){
|
||||
solve();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user