Submission #839445

# Submission time Handle Problem Language Result Execution time Memory
839445 2023-08-30T03:31:41 Z vjudge1 Selling RNA Strands (JOI16_selling_rna) C++17
100 / 100
404 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);
        }
        stable_sort(a.begin(), a.end());
        stable_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))
      |                             ~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 4692 KB Output is correct
2 Correct 25 ms 5576 KB Output is correct
3 Correct 22 ms 5076 KB Output is correct
4 Correct 26 ms 5560 KB Output is correct
5 Correct 21 ms 4040 KB Output is correct
6 Correct 20 ms 4040 KB Output is correct
7 Correct 18 ms 3668 KB Output is correct
8 Correct 30 ms 5560 KB Output is correct
9 Correct 29 ms 5576 KB Output is correct
10 Correct 17 ms 5576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 75 ms 12520 KB Output is correct
2 Correct 65 ms 7540 KB Output is correct
3 Correct 88 ms 10160 KB Output is correct
4 Correct 72 ms 8336 KB Output is correct
5 Correct 76 ms 7456 KB Output is correct
6 Correct 87 ms 9948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 15 ms 4692 KB Output is correct
9 Correct 25 ms 5576 KB Output is correct
10 Correct 22 ms 5076 KB Output is correct
11 Correct 26 ms 5560 KB Output is correct
12 Correct 21 ms 4040 KB Output is correct
13 Correct 20 ms 4040 KB Output is correct
14 Correct 18 ms 3668 KB Output is correct
15 Correct 30 ms 5560 KB Output is correct
16 Correct 29 ms 5576 KB Output is correct
17 Correct 17 ms 5576 KB Output is correct
18 Correct 75 ms 12520 KB Output is correct
19 Correct 65 ms 7540 KB Output is correct
20 Correct 88 ms 10160 KB Output is correct
21 Correct 72 ms 8336 KB Output is correct
22 Correct 76 ms 7456 KB Output is correct
23 Correct 87 ms 9948 KB Output is correct
24 Correct 65 ms 6920 KB Output is correct
25 Correct 113 ms 7012 KB Output is correct
26 Correct 45 ms 6908 KB Output is correct
27 Correct 64 ms 6896 KB Output is correct
28 Correct 404 ms 30536 KB Output is correct
29 Correct 257 ms 25136 KB Output is correct