이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include <istream>
#define pb push_back
#define s second
#define f first
#define pb push_back
#define pii pair <int,int>
#define ll long long
#define left h*2,l,(l + r)/2
#define right h*2+1,(l + r)/2 + 1,r
// #define int ll
using namespace std;
const int N = 2e6 + 5;
string s[N];
map <int,int> mp;
int t[N][5],cnt1 = 1,cnt2 = 1,timer1,tin1[N],tout1[N];
int timer2,tin2[N],tout2[N],S[N][5];
vector <pii> vec1,vec2;
vector <int> v1[N],v2[N];
bool fix[N];
void add1(string str,int id){
  int root = 1;
  for (int i = 0; i < str.size(); i++){
    int b = mp[str[i]];
    if (!t[root][b]){
      t[root][b] = ++cnt1;
    }
    
    root = t[root][b];
  }
  vec1.pb({root,id});
}
int getprefix(string str){
  int root = 1;
  for (int i = 0; i < str.size(); i++){
    int b = mp[str[i]];
    if (!t[root][b]) return -1;
    root = t[root][b];
  }
  return root;
}
int getsuffix(string str){
  int root = 1;
  for (int i = 0; i < str.size(); i++){
    int b = mp[str[i]];
    if (!S[root][b]) return -1;
    root = S[root][b];
  }
  return root;
}
void add2(string str,int id){
  int root = 1;
  for (int i = 0; i < str.size(); i++){
    int b = mp[str[i]];
    if (!S[root][b]){
      S[root][b] = ++cnt2;
    }
    root = S[root][b];
  }
  vec2.pb({root,id});
}
void dfs1(int x){
  tin1[x] = ++timer1;
  for (int i = 1; i <= 4; i++){
    if (t[x][i]) dfs1(t[x][i]);
  }
  tout1[x] = timer1;
}
void dfs2(int x){
  tin2[x] = ++timer2;
  for (int i = 1; i <= 4; i++){
    if (S[x][i]) dfs2(S[x][i]);
  }
  tout2[x] = timer2;
}
signed main() {
  ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
  mp['A'] = 1;
  mp['C'] = 2;
  mp['G'] = 3;
  mp['U'] = 4;
  int n,m;
  cin>>n>>m;
  for (int i = 1; i <= n; i++){
    cin >> s[i];
    add1(s[i],i);
    reverse(s[i].begin(),s[i].end());
    add2(s[i],i);
  }
  dfs1(1);
  dfs2(1);
  for (auto [x,j]: vec1){
    v1[tin1[x]].pb(j);
  }
  for (auto [x,j]: vec2){
    v2[tin2[x]].pb(j);
  }
  for (int i = 1; i <= m; i++){
    string x,y;
    cin>>x>>y;
    int A = getprefix(x);
    if (A == -1) {
      cout<<0<<endl;
      continue;
    }
    int l1 = tin1[A],r1 = tout1[A];
    reverse(y.begin(),y.end());
    int B = getsuffix(y);
    if (B == -1){
      cout<<0<<endl;
      continue;
    }
    int l2 = tin2[B],r2 = tout2[B];
    vector <int> vvv;
    // cout<<"! ";
    for (int i = l1; i <= r1; i++){
      for (int x: v1[i]) fix[x] = 1,vvv.pb(x);//cout<<x<<" ";
    }
    // cout<<endl;
    // cout<<"!! ";
    int ans = 0;
    for (int i = l2; i <= r2; i++){
      for (int x: v2[i]) ans += (fix[x]);//cout<<x<<" ";
    }
    // cout<<endl;
    cout<<ans<<endl;
    for (int k: vvv) fix[k] = 0;
  }
}
컴파일 시 표준 에러 (stderr) 메시지
selling_rna.cpp: In function 'void add1(std::string, int)':
selling_rna.cpp:25:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |   for (int i = 0; i < str.size(); i++){
      |                   ~~^~~~~~~~~~~~
selling_rna.cpp: In function 'int getprefix(std::string)':
selling_rna.cpp:39:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |   for (int i = 0; i < str.size(); i++){
      |                   ~~^~~~~~~~~~~~
selling_rna.cpp: In function 'int getsuffix(std::string)':
selling_rna.cpp:49:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |   for (int i = 0; i < str.size(); i++){
      |                   ~~^~~~~~~~~~~~
selling_rna.cpp: In function 'void add2(std::string, int)':
selling_rna.cpp:59:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |   for (int i = 0; i < str.size(); i++){
      |                   ~~^~~~~~~~~~~~| # | 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... |