Submission #233062

#TimeUsernameProblemLanguageResultExecution timeMemory
233062triple_faultSelling RNA Strands (JOI16_selling_rna)C++14
35 / 100
1599 ms206356 KiB
/* May 18 2020 */ #include <cstdio> #include <vector> #include <algorithm> #include <cstring> #include <cstdlib> #include <set> #include <map> #include <random> #include <iostream> #include <string> #define ll long long using namespace std; ll n, m; struct trie { map<char, trie*> children; vector<ll> indexes; void insert(string s, ll l, ll r, ll idx) { indexes.push_back(idx); if (l > r) return; char c = s[l]; if (children.find(c) == children.end()) children[c] = new trie(); children[c]->insert(s, l + 1, r, idx); } ll cnt(string s, ll l, ll r, ll tl, ll tr) { if (l > r) return lower_bound(indexes.begin(), indexes.end(), tr) - lower_bound(indexes.begin(), indexes.end(), tl); char c = s[l]; if (children.find(c) == children.end()) return 0; return children[c]->cnt(s, l + 1, r, tl, tr); } } main_trie; string rev(string s) { reverse(s.begin(), s.end()); return s; } int main(void) { scanf("%lld %lld", &n, &m); vector<string> vals(n); for (ll i = 0; i < n; ++i) cin >> vals[i]; sort(vals.begin(), vals.end()); for (ll i = 0; i < n; ++i) main_trie.insert(rev(vals[i]), 0, vals[i].length() - 1, i); while (m --) { string x, y; cin >> x >> y; ll l = lower_bound(vals.begin(), vals.end(), x) - vals.begin(); ++x.back(); ll r = lower_bound(vals.begin(), vals.end(), x) - vals.begin(); printf("%lld\n", main_trie.cnt(rev(y), 0, y.length() - 1, l, r)); } return 0; }

Compilation message (stderr)

selling_rna.cpp: In function 'int main()':
selling_rna.cpp:50:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld %lld", &n, &m);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...