#include <bits/stdc++.h>
using namespace std;
typedef int ll;
typedef long double ld;
#define pb push_back
#define pf push_front
#define fi first
#define se second
const ll mod = 1e9+7, mxn = 1e5+7;
struct tri
{
struct node
{
bitset<mxn> cnt; ll child[4];
node()
{
cnt = 0;
for (ll i = 0; i < 4; i++) child[i] = 0;
}
};
vector<node> trie = {node()};
void add(string& x, ll id)
{
ll u = 0;
for (ll i = 0; i < x.size(); i++)
{
if (!trie[u].child[x[i]-'A']) {trie.pb(node()); trie[u].child[x[i]-'A'] = trie.size()-1;}
u = trie[u].child[x[i]-'A'];
}
trie[u].cnt[id] = 1;
}
bitset<mxn> get(string& x)
{
ll u = 0;
bitset<mxn> ans;
for (ll i = 0; i < x.size(); i++)
{
if (!trie[u].child[x[i]-'A']) return ans;
u = trie[u].child[x[i]-'A'];
}
return trie[u].cnt;
}
void build(ll u)
{
for (ll i = 0; i < 4; i++) if (trie[u].child[i])
{
build(trie[u].child[i]);
trie[u].cnt ^= trie[trie[u].child[i]].cnt;
}
}
} tri1, tri2;
char trans(char x)
{
if (x == 'A') return 'A';
if (x == 'U') return 'B';
if (x == 'G') return 'C';
return 'D';
}
ll n, m;
signed main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// freopen("test.inp","r",stdin); freopen("test.out","w",stdout); freopen("test.err","w",stderr);
cin >> n >> m;
for (ll i = 1; i <= n; i++)
{
string s; cin >> s;
for (char& j : s) j = trans(j);
// cerr << "ADDED " << s << '\n';
tri1.add(s,i);
reverse(s.begin(),s.end());
tri2.add(s,i);
}
tri1.build(0); tri2.build(2);
for (ll i = 1; i <= m; i++)
{
string a, b; cin >> a >> b;
for (char& j : a) j = trans(j);
for (char& j : b) j = trans(j);
reverse(b.begin(),b.end());
bitset<mxn> aa = tri1.get(a), bb = tri2.get(b);
// cerr << aa[0] << aa[1] << ' ' << bb[0] << bb[1] << '\n';
aa ^= bb;
cout << aa.count() << '\n';
}
}
Compilation message
selling_rna.cpp: In member function 'void tri::add(std::string&, ll)':
selling_rna.cpp:25:26: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
25 | for (ll i = 0; i < x.size(); i++)
| ~~^~~~~~~~~~
selling_rna.cpp: In member function 'std::bitset<100007> tri::get(std::string&)':
selling_rna.cpp:36:26: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
36 | for (ll i = 0; i < x.size(); i++)
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
3632 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
780 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
226 ms |
1116 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
3632 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |