比赛 |
2024暑假C班集训8 |
评测结果 |
AAAAAAAAAA |
题目名称 |
单词默写 |
最终得分 |
100 |
用户昵称 |
┭┮﹏┭┮ |
运行时间 |
1.240 s |
代码语言 |
C++ |
内存使用 |
55.48 MiB |
提交时间 |
2024-07-08 11:08:00 |
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 5e5+10;
ll read(){
ll x = 0,f = 1;char c = getchar();
for(;c < '0' || c > '9';c = getchar())if(c == '-')f = -1;
for(;c >= '0' && c <= '9';c = getchar())x = (x<<1) + (x<<3) + c-'0';
return x * f;
}
int n,m;
class made{
public:
int f;
int son[27];
}a[N<<1];
int tot;
void insert(string ch){
int len = ch.length(),p = 0;
for(int i = 0;i < len;i++){
int u = ch[i] - 'a';
if(a[p].son[u] == 0)a[p].son[u] = ++tot;
p = a[p].son[u];
a[p].f++;
}
}
int ask(string ch){
int p = 0,len = ch.length();
for(int i = 0;i < ch.length();i++){
int u = ch[i] - 'a';
if(a[p].son[u] == 0)return 0;
p = a[p].son[u];
}
return a[p].f;
}
struct node{
int id,t;
string c;
bool operator < (const node a){
if(t == a.t)return id < a.id;
return t > a.t;
}
}s[N];
int ans[N],cnt;
string ch;
int main(){
freopen("engzam.in","r",stdin);
freopen("engzam.out","w",stdout);
n = read(),m = read();
for(int i = 1;i <= n;i++){
cin>>ch;int x = read();
s[++cnt] = {0,x,ch};
}
for(int i = 1;i <= m;i++){
cin>>ch;int x = read();
s[++cnt] = {i,x,ch};
}
sort(s+1,s+1+cnt);
for(int i = 1;i <= cnt;i++){
if(!s[i].id)insert(s[i].c);
else ans[s[i].id] = ask(s[i].c);
}
for(int i = 1;i <= m;i++)printf("%d\n",ans[i]);
return cerr<<clock()<<"ms"<<endl,0;
}