답안 #839446

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
839446 2023-08-30T03:32:37 Z vjudge1 Selling RNA Strands (JOI16_selling_rna) C++17
100 / 100
420 ms 30536 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

namespace BIT{
    int t = 0;
    const int OFFSET = 10;
    vector<vector<pair<int, int>>> a;
    void init(int n){
        a.resize(n + OFFSET*2, vector<pair<int, int>> (1, pair<int, int> (-1, 0)));
    }
    void update(int pos, int val){
        for (pos += OFFSET; pos < a.size(); pos += pos & (-pos))
            a[pos].emplace_back(t, a[pos].back().second + val);
        t++;
    }
    int query(int pos, int t){
        int v = 0;
        for (pos += OFFSET; pos; pos -= pos & (-pos)){
            vector<pair<int, int>> &x = a[pos];
            int p = lower_bound(x.begin(), x.end(), pair<int, int> (t, INT_MAX)) - x.begin() - 1;
            v += x[p].second;
        }
        return v;
    }
}

vector<pair<string, int>> a, b;

signed main(){
    cin.tie(0)->sync_with_stdio(0);
    int n, m; cin >> n >> m;
    {
        for (int i=0; i<n; i++){
            string ss; cin >> ss;
            a.emplace_back(ss, i);
            reverse(ss.begin(), ss.end());
            b.emplace_back(ss, i);
        }
        sort(a.begin(), a.end());
        sort(b.begin(), b.end());
        vector<int> p(n), s(n);
        for (int i=0; i<n; i++){
            p[a[i].second] = i;
            s[b[i].second] = i;
        }
        BIT::init(n);
        for (pair<string, int> &x: a){
            BIT::update(s[x.second], 1);
        }
    }
    while (m--){
        string p; cin >> p;
        int startp = lower_bound(a.begin(), a.end(), pair<string, int> (p, 0)) - a.begin();
        int endp = lower_bound(a.begin(), a.end(), pair<string, int> (p + '[', 0)) - a.begin() - 1;

        string q; cin >> q;
        reverse(q.begin(), q.end());
        int startq = lower_bound(b.begin(), b.end(), pair<string, int> (q, 0)) - b.begin();
        int endq = lower_bound(b.begin(), b.end(), pair<string, int> (q + '[', 0)) - b.begin() - 1;

        if (startp > endp || startq > endq){
            cout << "0\n";
        }
        else{
            int s = BIT::query(endq, endp) - BIT::query(startq-1, endp);
            int t = BIT::query(endq, startp-1) - BIT::query(startq-1, startp-1);
            cout << s - t << "\n";
        }
    }
}

Compilation message

selling_rna.cpp: In function 'void BIT::update(int, int)':
selling_rna.cpp:13:33: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 |         for (pos += OFFSET; pos < a.size(); pos += pos & (-pos))
      |                             ~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 4816 KB Output is correct
2 Correct 24 ms 5516 KB Output is correct
3 Correct 22 ms 5076 KB Output is correct
4 Correct 26 ms 5516 KB Output is correct
5 Correct 23 ms 4240 KB Output is correct
6 Correct 19 ms 4108 KB Output is correct
7 Correct 18 ms 3668 KB Output is correct
8 Correct 30 ms 5516 KB Output is correct
9 Correct 29 ms 5516 KB Output is correct
10 Correct 18 ms 5608 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 80 ms 12560 KB Output is correct
2 Correct 69 ms 7552 KB Output is correct
3 Correct 84 ms 10116 KB Output is correct
4 Correct 58 ms 8448 KB Output is correct
5 Correct 84 ms 7468 KB Output is correct
6 Correct 97 ms 10132 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 16 ms 4816 KB Output is correct
9 Correct 24 ms 5516 KB Output is correct
10 Correct 22 ms 5076 KB Output is correct
11 Correct 26 ms 5516 KB Output is correct
12 Correct 23 ms 4240 KB Output is correct
13 Correct 19 ms 4108 KB Output is correct
14 Correct 18 ms 3668 KB Output is correct
15 Correct 30 ms 5516 KB Output is correct
16 Correct 29 ms 5516 KB Output is correct
17 Correct 18 ms 5608 KB Output is correct
18 Correct 80 ms 12560 KB Output is correct
19 Correct 69 ms 7552 KB Output is correct
20 Correct 84 ms 10116 KB Output is correct
21 Correct 58 ms 8448 KB Output is correct
22 Correct 84 ms 7468 KB Output is correct
23 Correct 97 ms 10132 KB Output is correct
24 Correct 62 ms 6908 KB Output is correct
25 Correct 118 ms 6956 KB Output is correct
26 Correct 42 ms 6788 KB Output is correct
27 Correct 65 ms 6908 KB Output is correct
28 Correct 420 ms 30536 KB Output is correct
29 Correct 266 ms 25328 KB Output is correct