Submission #849290

# Submission time Handle Problem Language Result Execution time Memory
849290 2023-09-14T11:44:12 Z mickey080929 None (JOI16_matryoshka) C++17
100 / 100
218 ms 17084 KB
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

using namespace std;
typedef pair<int,int> pii;

struct Query{
    int A, B, id;
};

int N, Q;
pii a[200010];
Query q[200010];
int ans[200010];

struct BIT{
    int tree[400010];
    BIT() {
        memset(tree, 0, sizeof(tree));
    }
    void update(int i, int val, int n) {
        while (i <= n) {
            tree[i] = max(tree[i], val);
            i += i & -i;
        }
    }
    int query(int i) {
        int res = 0;
        while (i > 0) {
            res = max(res, tree[i]);
            i -= i & -i;
        }
        return res;
    }
} seg;

int main() {
    scanf("%d %d", &N, &Q);
    vector<int> t;
    for (int i=1; i<=N; i++) {
        scanf("%d %d", &a[i].first, &a[i].second);
        t.push_back(a[i].second);
    }
    sort(a+1, a+N+1, [&] (pii &u, pii &v) { return u.first==v.first ? u.second < v.second : u.first > v.first; });
    for (int i=1; i<=Q; i++) {
        scanf("%d %d", &q[i].A, &q[i].B);
        q[i].id = i;
        t.push_back(q[i].B);
    }
    sort(q+1, q+N+1, [&] (Query &u, Query &v) { return u.A > v.A; });
    sort(t.begin(), t.end());
    t.erase(unique(t.begin(), t.end()), t.end());
    for (int i=1; i<=N; i++) {
        a[i].second = lower_bound(t.begin(), t.end(), a[i].second) - t.begin() + 1;
    }
    for (int i=1; i<=Q; i++) {
        q[i].B = lower_bound(t.begin(), t.end(), q[i].B) - t.begin() + 1;
    }
    int M = (int) t.size();
    int j = 1;
    for (int i=1; i<=N; i++) {
        if (i == 1 || a[i].first < a[i-1].first) {
            while (j <= Q && q[j].A > a[i].first) {
                ans[q[j].id] = seg.query(q[j].B);
                j ++;
            }
        }
        int cur = seg.query(a[i].second);
        seg.update(a[i].second, cur+1, M);
    }
    while (j <= Q) {
        ans[q[j].id] = seg.query(q[j].B);
        j ++;
    }
    for (int i=1; i<=Q; i++) {
        printf("%d\n", ans[i]);
    }

    return 0;
}

Compilation message

matryoshka.cpp: In function 'int main()':
matryoshka.cpp:40:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |     scanf("%d %d", &N, &Q);
      |     ~~~~~^~~~~~~~~~~~~~~~~
matryoshka.cpp:43:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |         scanf("%d %d", &a[i].first, &a[i].second);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
matryoshka.cpp:48:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |         scanf("%d %d", &q[i].A, &q[i].B);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4696 KB Output is correct
2 Correct 1 ms 4700 KB Output is correct
3 Correct 1 ms 4720 KB Output is correct
4 Correct 1 ms 4696 KB Output is correct
5 Correct 1 ms 4696 KB Output is correct
6 Correct 1 ms 4696 KB Output is correct
7 Correct 1 ms 4696 KB Output is correct
8 Correct 1 ms 4696 KB Output is correct
9 Correct 1 ms 4696 KB Output is correct
10 Correct 2 ms 4696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4696 KB Output is correct
2 Correct 1 ms 4700 KB Output is correct
3 Correct 1 ms 4720 KB Output is correct
4 Correct 1 ms 4696 KB Output is correct
5 Correct 1 ms 4696 KB Output is correct
6 Correct 1 ms 4696 KB Output is correct
7 Correct 1 ms 4696 KB Output is correct
8 Correct 1 ms 4696 KB Output is correct
9 Correct 1 ms 4696 KB Output is correct
10 Correct 2 ms 4696 KB Output is correct
11 Correct 1 ms 4696 KB Output is correct
12 Correct 1 ms 4696 KB Output is correct
13 Correct 1 ms 4696 KB Output is correct
14 Correct 1 ms 4696 KB Output is correct
15 Correct 1 ms 4696 KB Output is correct
16 Correct 1 ms 4696 KB Output is correct
17 Correct 1 ms 4696 KB Output is correct
18 Correct 1 ms 4696 KB Output is correct
19 Correct 1 ms 4696 KB Output is correct
20 Correct 1 ms 4700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4696 KB Output is correct
2 Correct 1 ms 4700 KB Output is correct
3 Correct 1 ms 4720 KB Output is correct
4 Correct 1 ms 4696 KB Output is correct
5 Correct 1 ms 4696 KB Output is correct
6 Correct 1 ms 4696 KB Output is correct
7 Correct 1 ms 4696 KB Output is correct
8 Correct 1 ms 4696 KB Output is correct
9 Correct 1 ms 4696 KB Output is correct
10 Correct 2 ms 4696 KB Output is correct
11 Correct 1 ms 4696 KB Output is correct
12 Correct 1 ms 4696 KB Output is correct
13 Correct 1 ms 4696 KB Output is correct
14 Correct 1 ms 4696 KB Output is correct
15 Correct 1 ms 4696 KB Output is correct
16 Correct 1 ms 4696 KB Output is correct
17 Correct 1 ms 4696 KB Output is correct
18 Correct 1 ms 4696 KB Output is correct
19 Correct 1 ms 4696 KB Output is correct
20 Correct 1 ms 4700 KB Output is correct
21 Correct 1 ms 4696 KB Output is correct
22 Correct 2 ms 4696 KB Output is correct
23 Correct 2 ms 4808 KB Output is correct
24 Correct 3 ms 4696 KB Output is correct
25 Correct 3 ms 4696 KB Output is correct
26 Correct 3 ms 4952 KB Output is correct
27 Correct 3 ms 4696 KB Output is correct
28 Correct 2 ms 4696 KB Output is correct
29 Correct 3 ms 4696 KB Output is correct
30 Correct 2 ms 4700 KB Output is correct
31 Correct 3 ms 4696 KB Output is correct
32 Correct 3 ms 4952 KB Output is correct
33 Correct 3 ms 4696 KB Output is correct
34 Correct 2 ms 4696 KB Output is correct
35 Correct 3 ms 4696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4696 KB Output is correct
2 Correct 1 ms 4700 KB Output is correct
3 Correct 1 ms 4720 KB Output is correct
4 Correct 1 ms 4696 KB Output is correct
5 Correct 1 ms 4696 KB Output is correct
6 Correct 1 ms 4696 KB Output is correct
7 Correct 1 ms 4696 KB Output is correct
8 Correct 1 ms 4696 KB Output is correct
9 Correct 1 ms 4696 KB Output is correct
10 Correct 2 ms 4696 KB Output is correct
11 Correct 1 ms 4696 KB Output is correct
12 Correct 1 ms 4696 KB Output is correct
13 Correct 1 ms 4696 KB Output is correct
14 Correct 1 ms 4696 KB Output is correct
15 Correct 1 ms 4696 KB Output is correct
16 Correct 1 ms 4696 KB Output is correct
17 Correct 1 ms 4696 KB Output is correct
18 Correct 1 ms 4696 KB Output is correct
19 Correct 1 ms 4696 KB Output is correct
20 Correct 1 ms 4700 KB Output is correct
21 Correct 1 ms 4696 KB Output is correct
22 Correct 2 ms 4696 KB Output is correct
23 Correct 2 ms 4808 KB Output is correct
24 Correct 3 ms 4696 KB Output is correct
25 Correct 3 ms 4696 KB Output is correct
26 Correct 3 ms 4952 KB Output is correct
27 Correct 3 ms 4696 KB Output is correct
28 Correct 2 ms 4696 KB Output is correct
29 Correct 3 ms 4696 KB Output is correct
30 Correct 2 ms 4700 KB Output is correct
31 Correct 3 ms 4696 KB Output is correct
32 Correct 3 ms 4952 KB Output is correct
33 Correct 3 ms 4696 KB Output is correct
34 Correct 2 ms 4696 KB Output is correct
35 Correct 3 ms 4696 KB Output is correct
36 Correct 206 ms 14268 KB Output is correct
37 Correct 147 ms 13432 KB Output is correct
38 Correct 68 ms 8944 KB Output is correct
39 Correct 137 ms 11964 KB Output is correct
40 Correct 148 ms 12476 KB Output is correct
41 Correct 166 ms 13520 KB Output is correct
42 Correct 103 ms 11200 KB Output is correct
43 Correct 82 ms 11200 KB Output is correct
44 Correct 213 ms 16824 KB Output is correct
45 Correct 213 ms 16828 KB Output is correct
46 Correct 218 ms 17084 KB Output is correct
47 Correct 202 ms 16568 KB Output is correct
48 Correct 207 ms 17084 KB Output is correct
49 Correct 201 ms 16572 KB Output is correct
50 Correct 211 ms 17084 KB Output is correct