QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#521266 | #5551. Selling RNA Strands | JooDdae | 0 | 23ms | 223452kb | C++20 | 2.3kb | 2024-08-16 02:05:26 | 2024-08-16 02:05:27 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int trie[2002002][4], cnt;
vector<int> id[2002002];
int ic, in[2002002], out[2002002], rc, r[2002002], rin[2002002];
int n, m, C[256], ans[2002002], t[2002002];
string s[2002002], L[2002002], R[2002002];
vector<int> q[2002002];
void dfs(int u) {
in[u] = rc+1;
for(auto x : id[u]) r[++rc] = x;
for(int i=0;i<4;i++) if(trie[u][i]) dfs(trie[u][i]);
out[u] = rc;
}
void dfs2(int u) {
in[u] = ++ic;
for(int i=0;i<4;i++) if(trie[u][i]) dfs2(trie[u][i]);
out[u] = ic;
}
int find(int b) {
int re = 0;
while(b) re += t[b], b -= b & -b;
return re;
}
int main() {
C['A'] = 0, C['C'] = 1, C['G'] = 2, C['U'] = 3;
cin.tie(0)->sync_with_stdio(0);
cin >> n >> m;
for(int i=1;i<=n;i++) {
cin >> s[i];
int u = 0;
for(auto c : s[i]) {
c = C[c];
if(!trie[u][c]) trie[u][c] = ++cnt;
u = trie[u][c];
}
id[u].push_back(i);
}
dfs(0);
for(int i=1;i<=m;i++) {
cin >> L[i] >> R[i];
int u = 0;
for(auto c : L[i]) {
c = C[c];
if(!trie[u][c]) { u = -1; break; }
u = trie[u][c];
}
if(u != -1) {
q[in[u]-1].push_back(-i);
q[out[u]].push_back(i);
}
}
cnt = 0;
memset(trie, 0, sizeof trie);
for(int i=1;i<=n;i++) {
reverse(s[i].begin(), s[i].end());
int u = 0;
for(auto c : s[i]) {
c = C[c];
if(!trie[u][c]) trie[u][c] = ++cnt;
u = trie[u][c];
}
rin[i] = u;
}
ic = 0;
dfs2(0);
for(int i=1;i<=n;i++) {
int u = in[rin[r[i]]];
for(int b=u;b<=ic;b+=b&-b) t[b]++;
for(auto x : q[i]) {
auto &S = R[abs(x)];
reverse(S.begin(), S.end());
int u = 0;
for(auto c : S) {
c = C[c];
if(!trie[u][c]) { u = -1; break; }
u = trie[u][c];
}
if(u != -1) ans[abs(x)] += (x > 0 ? 1 : -1) * (find(out[u]) - find(in[u]-1));
}
}
for(int i=1;i<=m;i++) cout << ans[i] << "\n";
}
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 23ms
memory: 223452kb
input:
100 100 A G AGC AUA C CCA CGGAG CCGAG GACA UCAAC CUUAU AC A CGUA UAUG UGCGA GCU GUUAU UAAU A UAA U CGCCC GCG U AUUC GACA CC AG GUCGU UUCA AGGC G CU UG CUUA CUAU AA A GUUG GGU UU C GCUG C GUGGA C UAU UAG GC GUU GC UCUCA U AA AG C GGU GC CCUG CCUU GG CAGCU UAGGU GGCUC CUACG UGC UU UAAUG UGGCA CAA UGAG...
output:
9 1 11 1 1 2 4 3 11 6 1 0 1 1 4 1 -3 11 10 2 5 0 1 -3 0 11 1 13 0 0 3 -1 11 0 11 11 4 1 2 0 -1 10 1 1 0 2 4 2 0 13 10 1 1 1 0 1 1 3 0 2 1 0 9 9 13 2 0 0 9 0 -1 10 2 2 1 9 1 1 1 0 1 -1 0 9 2 0 11 11 1 3 -3 0 2 13 1 2 1 13 1 0
result:
wrong answer 12th lines differ - expected: '2', found: '0'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #1:
0%
Subtask #4:
score: 0
Skipped
Dependency #1:
0%