이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |