#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
using namespace std;
const int N=2e6+6;
int n,m;
int trie[3],timer[3];
int G[2*N],ANS[N],T[2*N][5][3],in[N][3],out[N][3];
string u,q;
pair < int , int > d[2*N];
vector < pair < bool , int > > v[2*N][3];
inline int C(char c) {
if (c=='A') return 0;
if (c=='C') return 1;
if (c=='G') return 2;
return 3;
}
pair < int , int > idx;
void Upd(int id,int x,bool ty) {
if (u.size()==x) {
v[id][ty].pb(idx);
return ;
}
int t=C(u[x]);
if (!T[id][t][ty]) T[id][t][ty]=++trie[ty];
Upd(T[id][t][ty],x+1,ty);
}
void Dfs(int x,int ty) {
++timer[ty];
for (int i=0; i<v[x][ty].size(); i++) {
int type=v[x][ty][i].F,idx=v[x][ty][i].S;
if (!type) {
if (!ty)
d[idx].F=timer[ty];
else
d[idx].S=timer[ty];
}
else in[idx][ty]=timer[ty];
}
for (int i=0; i<4; i++)
if (T[x][i][ty])
Dfs(T[x][i][ty],ty);
for (int i=0; i<v[x][ty].size(); i++) {
int type=v[x][ty][i].F,idx=v[x][ty][i].S;
if (type) out[idx][ty]=timer[ty];
}
}
void Up(int x) {
while (x<=2*N-5) {
G[x]++;
x+=(x & -x);
}
}
int Get(int x) {
int res=0;
while (x>0) {
res+=G[x];
x-=(x & -x);
}
return res;
}
main () {
ios_base::sync_with_stdio(false);
cin.tie(NULL),cout.tie(NULL);
cin>>n>>m;
for (int i=1; i<=n; i++) {
cin>>u;
idx={0,i};
Upd(0,0,0);
reverse(u.begin(),u.end());
Upd(0,0,1);
}
for (int i=1; i<=m; i++) {
cin>>u>>q;
idx={1,i};
Upd(0,0,0);
reverse(q.begin(),q.end()); u=q;
Upd(0,0,1);
}
Dfs(0,0);
Dfs(0,1);
vector < pair < int , pair < int , int > > > Q;
for (int i=1; i<=m; i++) {
Q.pb({in[i][0]-1,{-1,i}});
Q.pb({out[i][0],{1,i}});
}
sort(d+1,d+n+1);
sort(Q.begin(),Q.end());
int j=0;
for (int i=0; i<Q.size(); i++) {
int qy=Q[i].F,dl=Q[i].S.F,id=Q[i].S.S;
while (j+1<=n && d[j+1].F<=qy) {
++j;
Up(d[j].S);
}
ANS[id]+=dl*(Get(out[id][1])-Get(in[id][1]-1));
}
for (int i=1; i<=m; i++)
cout<<ANS[i]<<"\n";
}
Compilation message
selling_rna.cpp: In function 'void Upd(int, int, bool)':
selling_rna.cpp:26:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (u.size()==x) {
~~~~~~~~^~~
selling_rna.cpp: In function 'void Dfs(int, int)':
selling_rna.cpp:37:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i=0; i<v[x][ty].size(); i++) {
~^~~~~~~~~~~~~~~~
selling_rna.cpp:52:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i=0; i<v[x][ty].size(); i++) {
~^~~~~~~~~~~~~~~~
selling_rna.cpp: At global scope:
selling_rna.cpp:74:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main () {
^
selling_rna.cpp: In function 'int main()':
selling_rna.cpp:108:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i=0; i<Q.size(); i++) {
~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
171 ms |
282232 KB |
Output is correct |
2 |
Correct |
182 ms |
282232 KB |
Output is correct |
3 |
Correct |
182 ms |
282240 KB |
Output is correct |
4 |
Correct |
174 ms |
282232 KB |
Output is correct |
5 |
Correct |
164 ms |
282232 KB |
Output is correct |
6 |
Correct |
169 ms |
282232 KB |
Output is correct |
7 |
Correct |
228 ms |
282224 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
346 ms |
408032 KB |
Output is correct |
2 |
Correct |
328 ms |
403128 KB |
Output is correct |
3 |
Correct |
332 ms |
400696 KB |
Output is correct |
4 |
Correct |
338 ms |
395188 KB |
Output is correct |
5 |
Correct |
342 ms |
362040 KB |
Output is correct |
6 |
Correct |
382 ms |
363192 KB |
Output is correct |
7 |
Correct |
228 ms |
288636 KB |
Output is correct |
8 |
Correct |
303 ms |
333988 KB |
Output is correct |
9 |
Correct |
300 ms |
326784 KB |
Output is correct |
10 |
Correct |
271 ms |
323132 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
229 ms |
288124 KB |
Output is correct |
2 |
Correct |
215 ms |
286308 KB |
Output is correct |
3 |
Correct |
245 ms |
287388 KB |
Output is correct |
4 |
Correct |
218 ms |
286496 KB |
Output is correct |
5 |
Correct |
237 ms |
286216 KB |
Output is correct |
6 |
Correct |
219 ms |
287408 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
171 ms |
282232 KB |
Output is correct |
2 |
Correct |
182 ms |
282232 KB |
Output is correct |
3 |
Correct |
182 ms |
282240 KB |
Output is correct |
4 |
Correct |
174 ms |
282232 KB |
Output is correct |
5 |
Correct |
164 ms |
282232 KB |
Output is correct |
6 |
Correct |
169 ms |
282232 KB |
Output is correct |
7 |
Correct |
228 ms |
282224 KB |
Output is correct |
8 |
Correct |
346 ms |
408032 KB |
Output is correct |
9 |
Correct |
328 ms |
403128 KB |
Output is correct |
10 |
Correct |
332 ms |
400696 KB |
Output is correct |
11 |
Correct |
338 ms |
395188 KB |
Output is correct |
12 |
Correct |
342 ms |
362040 KB |
Output is correct |
13 |
Correct |
382 ms |
363192 KB |
Output is correct |
14 |
Correct |
228 ms |
288636 KB |
Output is correct |
15 |
Correct |
303 ms |
333988 KB |
Output is correct |
16 |
Correct |
300 ms |
326784 KB |
Output is correct |
17 |
Correct |
271 ms |
323132 KB |
Output is correct |
18 |
Correct |
229 ms |
288124 KB |
Output is correct |
19 |
Correct |
215 ms |
286308 KB |
Output is correct |
20 |
Correct |
245 ms |
287388 KB |
Output is correct |
21 |
Correct |
218 ms |
286496 KB |
Output is correct |
22 |
Correct |
237 ms |
286216 KB |
Output is correct |
23 |
Correct |
219 ms |
287408 KB |
Output is correct |
24 |
Correct |
373 ms |
388592 KB |
Output is correct |
25 |
Correct |
379 ms |
391192 KB |
Output is correct |
26 |
Correct |
327 ms |
386676 KB |
Output is correct |
27 |
Correct |
356 ms |
381176 KB |
Output is correct |
28 |
Correct |
357 ms |
310680 KB |
Output is correct |
29 |
Correct |
302 ms |
295716 KB |
Output is correct |