답안 #971216

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
971216 2024-04-28T07:35:47 Z Beerus13 Selling RNA Strands (JOI16_selling_rna) C++14
60 / 100
106 ms 64180 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define all(v) v.begin(), v.end()
#define pii pair<int, int>
const int N = 1e5 + 5;

struct query {
    int l1, r1, l2, r2;
};

struct node {
    int sum, l, r;
    node(int sum = 0) {}
    node(int sum, int l, int r) : sum(sum), l(l), r(r) {}
};

int n, m, ver[N], nNode;
string s[N], rs[N];
vector<pair<string, int>> rev;
vector<query> qrs;
node st[(1 << 20) + 5];

void refine(int cur) {
    st[cur].sum = st[st[cur].l].sum + st[st[cur].r].sum;
}

int update(int pos, int val, int old, int l = 1, int r = n) {
    int cur = ++nNode;
    if(l == r) {
        st[cur] = node(val, 0, 0);
        return cur;
    }
    int m = l + r >> 1;
    if(pos <= m) {
        st[cur].l = update(pos, val, st[old].l, l, m);
        st[cur].r = st[old].r;
    }
    else {
        st[cur].l = st[old].l;
        st[cur].r = update(pos, val, st[old].r, m + 1, r);
    }
    refine(cur);
    return cur;
}

int get(int ver1, int ver2, int u, int v, int l = 1, int r = n) {
    if(u > r || v < l) return 0;
    if(u <= l && r <= v) return st[ver2].sum - st[ver1].sum;
    int m = l + r >> 1;
    return get(st[ver1].l, st[ver2].l, u, v, l, m) + get(st[ver1].r, st[ver2].r, u, v, m + 1, r);
}

pii get_range(string x, string *S) {
    pii res;
    res.first = lower_bound(S + 1, S + n + 1, x) - S;
    x.back()++;
    res.second = lower_bound(S + 1, S + n + 1, x) - S - 1;
    return res;
}

void solve() {
    cin >> n >> m;
    for(int i = 1; i <= n; ++i) {
        cin >> s[i];
    }
    sort(s + 1, s + n + 1);
    for(int i = 1; i <= n; ++i) {
        rs[i] = s[i];
        reverse(all(rs[i]));
        rev.emplace_back(rs[i], i);
    }
    sort(rs + 1, rs + n + 1);
    sort(all(rev));
    for(int i = 1; i <= n; ++i) {
        auto [_, j] = rev[i - 1];
        ver[i] = update(j, 1, ver[i - 1]);
    }
    for(int i = 1; i <= m; ++i) {
        string P, Q; cin >> P >> Q;
        auto [l1, r1] = get_range(P, s);
        reverse(all(Q));
        auto [l2, r2] = get_range(Q, rs);
        cout << get(ver[l2 - 1], ver[r2], l1, r1) << '\n';
    }
    
}

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int test = 1;
    // cin >> test;
    while(test--) solve();
    return 0;
}

// https://oj.uz/problem/view/JOI16_selling_rna

Compilation message

selling_rna.cpp: In function 'int update(int, int, int, int, int)':
selling_rna.cpp:34:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   34 |     int m = l + r >> 1;
      |             ~~^~~
selling_rna.cpp: In function 'int get(int, int, int, int, int, int)':
selling_rna.cpp:50:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   50 |     int m = l + r >> 1;
      |             ~~^~~
selling_rna.cpp: In function 'void solve()':
selling_rna.cpp:76:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   76 |         auto [_, j] = rev[i - 1];
      |              ^
selling_rna.cpp:81:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   81 |         auto [l1, r1] = get_range(P, s);
      |              ^
selling_rna.cpp:83:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   83 |         auto [l2, r2] = get_range(Q, rs);
      |              ^
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8536 KB Output is correct
2 Correct 3 ms 8536 KB Output is correct
3 Correct 2 ms 8540 KB Output is correct
4 Correct 2 ms 8540 KB Output is correct
5 Correct 3 ms 8540 KB Output is correct
6 Correct 2 ms 8540 KB Output is correct
7 Correct 2 ms 8540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 20828 KB Output is correct
2 Correct 22 ms 21168 KB Output is correct
3 Correct 23 ms 21056 KB Output is correct
4 Correct 24 ms 21168 KB Output is correct
5 Correct 18 ms 17284 KB Output is correct
6 Correct 19 ms 17444 KB Output is correct
7 Correct 22 ms 20820 KB Output is correct
8 Correct 30 ms 22960 KB Output is correct
9 Correct 28 ms 22848 KB Output is correct
10 Correct 20 ms 20652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 61 ms 21948 KB Output is correct
2 Correct 41 ms 16588 KB Output is correct
3 Correct 53 ms 19392 KB Output is correct
4 Correct 41 ms 17600 KB Output is correct
5 Correct 41 ms 16592 KB Output is correct
6 Correct 55 ms 19392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8536 KB Output is correct
2 Correct 3 ms 8536 KB Output is correct
3 Correct 2 ms 8540 KB Output is correct
4 Correct 2 ms 8540 KB Output is correct
5 Correct 3 ms 8540 KB Output is correct
6 Correct 2 ms 8540 KB Output is correct
7 Correct 2 ms 8540 KB Output is correct
8 Correct 16 ms 20828 KB Output is correct
9 Correct 22 ms 21168 KB Output is correct
10 Correct 23 ms 21056 KB Output is correct
11 Correct 24 ms 21168 KB Output is correct
12 Correct 18 ms 17284 KB Output is correct
13 Correct 19 ms 17444 KB Output is correct
14 Correct 22 ms 20820 KB Output is correct
15 Correct 30 ms 22960 KB Output is correct
16 Correct 28 ms 22848 KB Output is correct
17 Correct 20 ms 20652 KB Output is correct
18 Correct 61 ms 21948 KB Output is correct
19 Correct 41 ms 16588 KB Output is correct
20 Correct 53 ms 19392 KB Output is correct
21 Correct 41 ms 17600 KB Output is correct
22 Correct 41 ms 16592 KB Output is correct
23 Correct 55 ms 19392 KB Output is correct
24 Correct 44 ms 21496 KB Output is correct
25 Correct 70 ms 21784 KB Output is correct
26 Correct 35 ms 21348 KB Output is correct
27 Correct 44 ms 21612 KB Output is correct
28 Runtime error 106 ms 64180 KB Execution killed with signal 11
29 Halted 0 ms 0 KB -