Submission #972929

#TimeUsernameProblemLanguageResultExecution timeMemory
972929duckindogSelling RNA Strands (JOI16_selling_rna)C++17
35 / 100
1535 ms203360 KiB
#pragma GCC optimize("O3,unroll-loops") #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") #include <bits/stdc++.h> using namespace std; const int N = 500'000 + 10; int n, m; string str[N]; pair<string, string> Q[N]; int convert(const auto& a) { return a == 'A' ? 0 : a == 'C' ? 1 : a == 'G' ? 2 : 3; } int nwt[N << 2][4]; int answer[N]; struct Trie { int it; vector<array<int, 4>> nwt; vector<int> id; void add(string s, int idx) { int g = 0; for (int i = 1; i <= (int)s.size(); ++i) { while (nwt.size() <= g) nwt.push_back(array<int, 4>()); int path = convert(s[i - 1]); if (!nwt[g][path]) nwt[g][path] = ++it; g = nwt[g][path]; while (id.size() <= it) id.push_back(false); } id[g] = idx; } void get(string s) { int ret = 0; int g = 0; for (int i = 1; i <= (int)s.size(); ++i) { int path = convert(s[i - 1]); if (nwt.size() <= g || !nwt[g][path]) return; g = nwt[g][path]; answer[id[g]] += 1; } } } T[N << 2]; int it; void add(const auto& s, const auto& e, int idx) { int g = 0; for (int i = 1; i <= (int)s.size(); ++i) { int path = convert(s[i - 1]); if (!nwt[g][path]) nwt[g][path] = ++it; g = nwt[g][path]; } T[g].add(string(e.rbegin(), e.rend()), idx); } void get(const auto& s) { string rs = string(s.rbegin(), s.rend()); int g = 0; for (int i = 1; i <= (int)s.size(); ++i) { int path = convert(s[i - 1]); if (!nwt[g][path]) return; g = nwt[g][path]; T[g].get(rs); } } int32_t main() { cin.tie(0)->sync_with_stdio(0); cin >> n >> m; for (int i = 1; i <= n; ++i) cin >> str[i]; for (int i = 1; i <= m; ++i) { string s, e; cin >> s >> e; Q[i] = {s, e}; } vector<pair<string, string>> que(Q + 1, Q + m + 1); sort(que.begin(), que.end()); que.resize(unique(que.begin(), que.end()) - que.begin()); { int it = 0; for (const auto& [s, e] : que) add(s, e, ++it); for (int i = 1; i <= n; ++i) get(str[i]); } for (int i = 1; i <= m; ++i) { int idx = lower_bound(que.begin(), que.end(), Q[i]) - que.begin() + 1; cout << answer[idx] << "\n"; } }

Compilation message (stderr)

selling_rna.cpp:12:19: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   12 | int convert(const auto& a) { return a == 'A' ? 0 : a == 'C' ? 1 : a == 'G' ? 2 : 3; }
      |                   ^~~~
selling_rna.cpp: In member function 'void Trie::add(std::string, int)':
selling_rna.cpp:24:25: warning: comparison of integer expressions of different signedness: 'std::vector<std::array<int, 4> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   24 |       while (nwt.size() <= g) nwt.push_back(array<int, 4>());
      |              ~~~~~~~~~~~^~~~
selling_rna.cpp:30:24: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   30 |       while (id.size() <= it) id.push_back(false);
      |              ~~~~~~~~~~^~~~~
selling_rna.cpp: In member function 'void Trie::get(std::string)':
selling_rna.cpp:40:22: warning: comparison of integer expressions of different signedness: 'std::vector<std::array<int, 4> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   40 |       if (nwt.size() <= g || !nwt[g][path]) return;
      |           ~~~~~~~~~~~^~~~
selling_rna.cpp:36:9: warning: unused variable 'ret' [-Wunused-variable]
   36 |     int ret = 0;
      |         ^~~
selling_rna.cpp: At global scope:
selling_rna.cpp:48:16: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   48 | void add(const auto& s, const auto& e, int idx) {
      |                ^~~~
selling_rna.cpp:48:31: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   48 | void add(const auto& s, const auto& e, int idx) {
      |                               ^~~~
selling_rna.cpp:58:16: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   58 | void get(const auto& s) {
      |                ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...