Submission #1088180

#TimeUsernameProblemLanguageResultExecution timeMemory
1088180TrinhKhanhDungSelling RNA Strands (JOI16_selling_rna)C++14
35 / 100
222 ms330648 KiB
#include <bits/stdc++.h> #define ll long long #define fi first #define se second #define sz(x) (int)x.size() #define ALL(v) v.begin(),v.end() #define MASK(k) (1LL << (k)) #define BIT(x, i) (((x) >> (i)) & 1) #define oo (ll)1e18 #define INF (ll)1e9 #define MOD (ll)(998244353) using namespace std; template<class T1, class T2> bool maximize(T1 &a, T2 b){if(a < b){a = b; return true;} return false;} template<class T1, class T2> bool minimize(T1 &a, T2 b){if(a > b){a = b; return true;} return false;} template<class T1, class T2> void add(T1 &a, T2 b){a += b; if(a >= MOD) a -= MOD;} template<class T1, class T2> void sub(T1 &a, T2 b){a -= b; if(a < 0) a += MOD;} template<class T> void cps(T &v){sort(ALL(v)); v.resize(unique(ALL(v)) - v.begin());} const int lim = 1e6 + 10, MAX = 1e5 + 10; int n[lim][26]; vector<int> idx[lim]; int timer; int N, Q; string a[MAX]; void solve(){ memset(n, -1, sizeof n); cin >> N >> Q; for(int i = 1; i <= N; i++) cin >> a[i]; sort(a + 1, a + N + 1); for(int i = 1; i <= N; i++){ int p = 0; for(int j = sz(a[i]) - 1; j >= 0; j--){ int id = a[i][j] - 'A'; if(n[p][id] == -1) n[p][id] = ++timer; p = n[p][id]; idx[p].push_back(i); } } while(Q--){ string x, y; cin >> x >> y; int l = lower_bound(a + 1, a + N + 1, x) - a; x.back()++; int r = lower_bound(a + 1, a + N + 1, x) - a - 1; if(l > r){ cout << 0 << '\n'; continue; } int p = 0; for(int j = sz(y) - 1; j >= 0; j--){ int id = y[j] - 'A'; p = n[p][id]; if(p == -1) break; } if(p == -1) cout << 0 << '\n'; else{ int pl = lower_bound(ALL(idx[p]), l) - idx[p].begin(); int pr = upper_bound(ALL(idx[p]), r) - idx[p].begin(); cout << pr - pl << '\n'; } } } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); // freopen("FBUY.inp","r",stdin); // freopen("FBUY.out","w",stdout); solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...