# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
896985 | Aiperiii | Selling RNA Strands (JOI16_selling_rna) | C++14 | 401 ms | 332116 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define int long long
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define pb push_back
using namespace std;
const int N=2e6;
struct Trie{
vector <int> v;
map <char,int> mp;
};
Trie t[N];
int cnt=0;
void insert(string s,int ind){
int p=0;
for(int i=0;i<s.size();i++){
if(t[p].mp[s[i]]==0){
cnt++;
t[p].mp[s[i]]=cnt;
}
p=t[p].mp[s[i]];
t[p].v.pb(ind);
}
}
int get(string s,int l,int r){
int p=0;
for(int i=0;i<s.size();i++){
p=t[p].mp[s[i]];
if(p==0)return 0;
}
auto L=lower_bound(all(t[p].v),l)-t[p].v.begin();
auto R=upper_bound(all(t[p].v),r)-t[p].v.begin();
return R-L;
}
signed main(){
int n,m;
cin>>n>>m;
vector <string> a(n);
for(int i=0;i<n;i++){
cin>>a[i];
}
sort(all(a));
for(int i=0;i<n;i++){
string x=a[i];reverse(all(x));
insert(x,i);
}
for(int i=0;i<m;i++){
string s,q;
cin>>s>>q;
auto it=lower_bound(all(a),s);
int l=it-a.begin();
s.back()++;
it=lower_bound(all(a),s);
int r=it-a.begin()-1;
if(l>r){
cout<<0<<"\n";
continue;
}
reverse(all(q));
cout<<get(q,l,r)<<"\n";
}
}
/*
1
0 1
2
0 1
3
0
4
1
5
1
*/
Compilation message (stderr)
# | 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... |