답안 #112510

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
112510 2019-05-20T11:23:42 Z Kastanda Selling RNA Strands (JOI16_selling_rna) C++11
100 / 100
463 ms 31544 KB
#include<bits/stdc++.h>
using namespace std;
const int N = 100005;
int n, q, P[N];
string S[N], R[N];
vector < int > vec[N * 2];
bool CMP(int i, int j)
{
    return (R[i] < R[j]);
}
inline int Get(int l, int r, int le, int ri)
{
    int ret = 0;
    l += n; r += n;
    for (; l < r; l >>= 1, r >>= 1)
    {
        if (l & 1) ret += lower_bound(vec[l].begin(), vec[l].end(), ri) - lower_bound(vec[l].begin(), vec[l].end(), le), l ++;
        if (r & 1) r --, ret += lower_bound(vec[r].begin(), vec[r].end(), ri) - lower_bound(vec[r].begin(), vec[r].end(), le);
    }
    return (ret);
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin >> n >> q;
    for (int i = 0; i < n; i ++)
        cin >> S[i], P[i] = i;
    sort(S, S + n);
    for (int i = 0; i < n; i ++)
        R[i] = S[i], reverse(R[i].begin(), R[i].end());
    sort(P, P + n, CMP);
    for (int i = 0; i < n; i ++)
        for (int id = i + n; id; id >>= 1)
            vec[id].push_back(P[i]);
    for (int i = 0; i < n + n; i ++)
        sort(vec[i].begin(), vec[i].end());
    for (int i = 0; i < q; i ++)
    {
        string A, B;
        cin >> A >> B;
        int l = lower_bound(S, S + n, A) - S;
        A.back() ++;
        int r = lower_bound(S, S + n, A) - S;
        reverse(B.begin(), B.end());
        R[n] = B;
        int le = lower_bound(P, P + n, n, CMP) - P;
        B.back() ++; R[n] = B;
        int ri = lower_bound(P, P + n, n, CMP) - P;
        printf("%d\n", Get(le, ri, l, r));
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 11392 KB Output is correct
2 Correct 10 ms 11264 KB Output is correct
3 Correct 10 ms 11392 KB Output is correct
4 Correct 10 ms 11264 KB Output is correct
5 Correct 10 ms 11264 KB Output is correct
6 Correct 10 ms 11392 KB Output is correct
7 Correct 10 ms 11264 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 15616 KB Output is correct
2 Correct 46 ms 18428 KB Output is correct
3 Correct 45 ms 18168 KB Output is correct
4 Correct 49 ms 18552 KB Output is correct
5 Correct 36 ms 16888 KB Output is correct
6 Correct 40 ms 17016 KB Output is correct
7 Correct 37 ms 17024 KB Output is correct
8 Correct 50 ms 18432 KB Output is correct
9 Correct 53 ms 18424 KB Output is correct
10 Correct 40 ms 18424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 105 ms 17576 KB Output is correct
2 Correct 77 ms 14840 KB Output is correct
3 Correct 97 ms 16520 KB Output is correct
4 Correct 74 ms 15800 KB Output is correct
5 Correct 89 ms 15280 KB Output is correct
6 Correct 115 ms 16416 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 11392 KB Output is correct
2 Correct 10 ms 11264 KB Output is correct
3 Correct 10 ms 11392 KB Output is correct
4 Correct 10 ms 11264 KB Output is correct
5 Correct 10 ms 11264 KB Output is correct
6 Correct 10 ms 11392 KB Output is correct
7 Correct 10 ms 11264 KB Output is correct
8 Correct 29 ms 15616 KB Output is correct
9 Correct 46 ms 18428 KB Output is correct
10 Correct 45 ms 18168 KB Output is correct
11 Correct 49 ms 18552 KB Output is correct
12 Correct 36 ms 16888 KB Output is correct
13 Correct 40 ms 17016 KB Output is correct
14 Correct 37 ms 17024 KB Output is correct
15 Correct 50 ms 18432 KB Output is correct
16 Correct 53 ms 18424 KB Output is correct
17 Correct 40 ms 18424 KB Output is correct
18 Correct 105 ms 17576 KB Output is correct
19 Correct 77 ms 14840 KB Output is correct
20 Correct 97 ms 16520 KB Output is correct
21 Correct 74 ms 15800 KB Output is correct
22 Correct 89 ms 15280 KB Output is correct
23 Correct 115 ms 16416 KB Output is correct
24 Correct 98 ms 19320 KB Output is correct
25 Correct 142 ms 19416 KB Output is correct
26 Correct 172 ms 19312 KB Output is correct
27 Correct 107 ms 19308 KB Output is correct
28 Correct 463 ms 31544 KB Output is correct
29 Correct 313 ms 26476 KB Output is correct