Submission #842332

# Submission time Handle Problem Language Result Execution time Memory
842332 2023-09-02T18:38:52 Z c2zi6 None (JOI16_matryoshka) C++14
100 / 100
1018 ms 31832 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

class SEGMENTTREE {
private:
    int n;
    vector<int> tree;
    int update(int N, int L, int R, int i, int x) {
        if (i < L || i > R) return tree[N];
        if (L == R) return tree[N] = max(x, tree[N]);
        int M = (L + R) / 2;
        return tree[N] = max(update(2*N+1, L, M, i, x), update(2*N+2, M+1, R, i, x));
    }
    int get(int N, int L, int R, int l, int r) {
        if (l <= L && R <= r) return tree[N];
        if (R < l || L > r) return 0;
        int M = (L + R) / 2;
        return max(get(2*N+1, L, M, l, r), get(2*N+2, M+1, R, l, r));
    }
public:
    void print() {
        for (int i = 0; i < n; i++) cout << get(0, 0, n-1, i, i) << " ";
        cout << endl;
    }
    SEGMENTTREE(int m) {
        n = 1;
        while (n < m) n <<= 1;
        tree = vector<int>(2 * n);
    }
    int GEQ(int x) {
        return get(0, 0, n-1, x, n-1);
    }
    void upd(int h, int v) {
        update(0, 0, n-1, h, v);
    }
};

struct MATR {
    int r, h;
    bool operator<(const MATR& b) {
        if (this->h == b.h) return this->r > b.r;
        return this->h < b.h;
    }
};

struct QUERY {
    int A, B, i;
    bool operator<(const QUERY& b) {
        return this->B < b.B;
    }
};

/**
  r >= a
  h <= b
*/

int main() {
    int n, q;
    cin >> n >> q;
    vector<MATR> a(n);
    for (int i = 0; i < n; i++) cin >> a[i].r >> a[i].h;
    vector<QUERY> qrs(q);
    for (int i = 0; i < q; i++) cin >> qrs[i].A >> qrs[i].B, qrs[i].i = i;

    /* compress */ {
        map<int, int> cor;
        for (int i = 0; i < n; i++) cor[a[i].r] = 0;
        for (int i = 0; i < q; i++) cor[qrs[i].A] = 0;
        int ind = 0; for (pair<int, int> p : cor) cor[p.first] = ind++;
        for (int i = 0; i < n; i++) a[i].r = cor[a[i].r];
        for (int i = 0; i < q; i++) qrs[i].A = cor[qrs[i].A];
    }

    sort(a.begin(), a.end());
    sort(qrs.begin(), qrs.end());
    
    vector<int> ans(q);
    SEGMENTTREE seg(n + q);
    for (int i = 0, j = 0; i < q; i++) {
        while (j < n && a[j].h <= qrs[i].B) {
            seg.upd(a[j].r, seg.GEQ(a[j].r)+1);
            j++;
        }
        ans[qrs[i].i] = seg.GEQ(qrs[i].A);
    }
    for (int x : ans) cout << x << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 436 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 436 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 436 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 3 ms 348 KB Output is correct
23 Correct 7 ms 740 KB Output is correct
24 Correct 6 ms 744 KB Output is correct
25 Correct 7 ms 604 KB Output is correct
26 Correct 6 ms 672 KB Output is correct
27 Correct 6 ms 604 KB Output is correct
28 Correct 6 ms 604 KB Output is correct
29 Correct 7 ms 604 KB Output is correct
30 Correct 5 ms 348 KB Output is correct
31 Correct 7 ms 604 KB Output is correct
32 Correct 6 ms 856 KB Output is correct
33 Correct 6 ms 604 KB Output is correct
34 Correct 7 ms 604 KB Output is correct
35 Correct 7 ms 740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 436 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 3 ms 348 KB Output is correct
23 Correct 7 ms 740 KB Output is correct
24 Correct 6 ms 744 KB Output is correct
25 Correct 7 ms 604 KB Output is correct
26 Correct 6 ms 672 KB Output is correct
27 Correct 6 ms 604 KB Output is correct
28 Correct 6 ms 604 KB Output is correct
29 Correct 7 ms 604 KB Output is correct
30 Correct 5 ms 348 KB Output is correct
31 Correct 7 ms 604 KB Output is correct
32 Correct 6 ms 856 KB Output is correct
33 Correct 6 ms 604 KB Output is correct
34 Correct 7 ms 604 KB Output is correct
35 Correct 7 ms 740 KB Output is correct
36 Correct 768 ms 24756 KB Output is correct
37 Correct 850 ms 27840 KB Output is correct
38 Correct 233 ms 12936 KB Output is correct
39 Correct 459 ms 12816 KB Output is correct
40 Correct 457 ms 13356 KB Output is correct
41 Correct 722 ms 23928 KB Output is correct
42 Correct 381 ms 11872 KB Output is correct
43 Correct 329 ms 12140 KB Output is correct
44 Correct 1018 ms 31780 KB Output is correct
45 Correct 930 ms 31604 KB Output is correct
46 Correct 976 ms 31596 KB Output is correct
47 Correct 920 ms 31204 KB Output is correct
48 Correct 914 ms 31832 KB Output is correct
49 Correct 913 ms 31236 KB Output is correct
50 Correct 917 ms 31684 KB Output is correct