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>
using namespace std;
#define sz(a) (int)a.size()
#define all(a) begin(a),end(a)
const int N = (int)2e6+10;
vector<int> xd[N];
int trie[2][4][N];
int L[N], R[N];
int n, m, I[2];
string s[N];
void add(string &s, int j, int t, bool r=0){
int v = 1;
for(int i = 0; i < sz(s); i++){
char u = s[r?sz(s)-1-i:i];
int c = (u=='A'?0:u=='C'?1:u=='G'?2:3);
if(!trie[t][c][v]) trie[t][c][v]=I[t]++;
v = trie[t][c][v];
if(!t){
if(!L[v]) L[v]=j;
R[v]=max(R[v],j);
}
else xd[v].push_back(j);
}
}
int get(string &s, int t, bool r=0){
int v = 1;
for(int i = 0; i < sz(s); i++){
char u = s[r?sz(s)-1-i:i];
int c = (u=='A'?0:u=='C'?1:u=='G'?2:3);
v = trie[t][c][v]; if(!v) return 0;
}
return v;
}
int32_t main()
{
cin >> n >> m; I[0]=I[1]=2;
for(int i = 0; i < n; i++)
cin >> s[i]; sort(s,s+n);
for(int i = 0; i < n; i++)
add(s[i],i+1,0),add(s[i],i+1,1,1);
for(int i = 0; i < m; i++){
string s, t; cin >> s >> t;
int ind = get(s,0), ind2=get(t,1,1);
int l = L[ind], r=R[ind];
int pos1 = lower_bound(all(xd[ind2]),l)-begin(xd[ind2]);
int pos2 = upper_bound(all(xd[ind2]),r)-begin(xd[ind2]);
cout << max(0, pos2-pos1) << "\n";
}
}
Compilation message (stderr)
selling_rna.cpp: In function 'int32_t main()':
selling_rna.cpp:40:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
40 | for(int i = 0; i < n; i++)
| ^~~
selling_rna.cpp:41:16: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
41 | cin >> s[i]; sort(s,s+n);
| ^~~~
# | 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... |