제출 #562756

#제출 시각아이디문제언어결과실행 시간메모리
562756SSRSSelling RNA Strands (JOI16_selling_rna)C++14
35 / 100
1573 ms13124 KiB
#include <bits/stdc++.h> using namespace std; struct binary_indexed_tree{ int N; vector<int> BIT; binary_indexed_tree(int N): N(N), BIT(N + 1, 0){ } void add(int i){ i++; while (i <= N){ BIT[i]++; i += i & -i; } } int sum(int i){ int ans = 0; while (i > 0){ ans += BIT[i]; i -= i & -i; } return ans; } int sum(int L, int R){ return sum(R) - sum(L); } }; int main(){ int N, M; cin >> N >> M; vector<string> S(N); for (int i = 0; i < N; i++){ cin >> S[i]; } vector<pair<string, int>> P1(N); for (int i = 0; i < N; i++){ P1[i] = make_pair(S[i], i); } for (int i = 0; i < N; i++){ reverse(S[i].begin(), S[i].end()); } vector<pair<string, int>> P2(N); for (int i = 0; i < N; i++){ P2[i] = make_pair(S[i], i); } sort(P1.begin(), P1.end()); sort(P2.begin(), P2.end()); vector<int> X(N), Y(N); for (int i = 0; i < N; i++){ X[P1[i].second] = i; Y[P2[i].second] = i; } for (int i = 0; i < M; i++){ string P, Q; cin >> P >> Q; reverse(Q.begin(), Q.end()); int L1 = lower_bound(P1.begin(), P1.end(), make_pair(P, 0)) - P1.begin(); P.back()++; int R1 = lower_bound(P1.begin(), P1.end(), make_pair(P, 0)) - P1.begin(); int L2 = lower_bound(P2.begin(), P2.end(), make_pair(Q, 0)) - P2.begin(); Q.back()++; int R2 = lower_bound(P2.begin(), P2.end(), make_pair(Q, N)) - P2.begin(); int ans = 0; for (int j = 0; j < N; j++){ if (L1 <= X[j] && X[j] < R1 && L2 <= Y[j] && Y[j] < R2){ ans++; } } cout << ans << endl; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...