Submission #884952

# Submission time Handle Problem Language Result Execution time Memory
884952 2023-12-08T17:58:39 Z aykhn None (JOI16_matryoshka) C++17
100 / 100
122 ms 18516 KB
#include <bits/stdc++.h>
 
// author : aykhn
 
using namespace std;
typedef long long ll;
 
#define pb push_back
#define ins insert
#define mpr make_pair
#define all(v) v.begin(), v.end()
#define bpc __builtin_popcountll
#define pii pair<ll, ll>
#define pll pair<ll, ll>
#define fi first
#define se second
#define int ll
#define infll 0x3F3F3F3F3F3F3F3F
#define inf 0x3F3F3F3F

const int MXN = 2e5 + 5;

int n;
array<int, 2> p[MXN];
array<int, 3> q[MXN];
int res[MXN];

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);
    int Q;
    cin >> n >> Q;
    for (int i = 0; i < n; i++) cin >> p[i][0] >> p[i][1];
    for (int i = 0; i < Q; i++) cin >> q[i][0] >> q[i][1], q[i][2] = i;
    sort(p, p + n, [&](const array<int, 2> &a, const array<int, 2> &b)
    {
        return (a[0] == b[0] ? a[1] < b[1] : a[0] > b[0]);
    });
    sort(q, q + Q, [&](const array<int, 3> &a, const array<int, 3> &b)
    {
        return a[0] > b[0];
    });
    vector<int> s;
    int j = 0;
    for (int i = 0; i < Q; i++)
    {
        while (j < n && p[j][0] >= q[i][0])
        {
            auto it = upper_bound(all(s), p[j][1]);
            if (it == s.end()) s.pb(p[j][1]);
            else *it = p[j][1];
            j++;
        }
        res[q[i][2]] = upper_bound(all(s), q[i][1]) - s.begin();
    }
    for (int i = 0; i < Q; i++) cout << res[i] << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4696 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4440 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4696 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4440 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4548 KB Output is correct
23 Correct 2 ms 4444 KB Output is correct
24 Correct 2 ms 4444 KB Output is correct
25 Correct 2 ms 4444 KB Output is correct
26 Correct 2 ms 4444 KB Output is correct
27 Correct 2 ms 4444 KB Output is correct
28 Correct 2 ms 4444 KB Output is correct
29 Correct 2 ms 4444 KB Output is correct
30 Correct 2 ms 4828 KB Output is correct
31 Correct 2 ms 4444 KB Output is correct
32 Correct 2 ms 4444 KB Output is correct
33 Correct 2 ms 4444 KB Output is correct
34 Correct 2 ms 4568 KB Output is correct
35 Correct 2 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4696 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4440 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4548 KB Output is correct
23 Correct 2 ms 4444 KB Output is correct
24 Correct 2 ms 4444 KB Output is correct
25 Correct 2 ms 4444 KB Output is correct
26 Correct 2 ms 4444 KB Output is correct
27 Correct 2 ms 4444 KB Output is correct
28 Correct 2 ms 4444 KB Output is correct
29 Correct 2 ms 4444 KB Output is correct
30 Correct 2 ms 4828 KB Output is correct
31 Correct 2 ms 4444 KB Output is correct
32 Correct 2 ms 4444 KB Output is correct
33 Correct 2 ms 4444 KB Output is correct
34 Correct 2 ms 4568 KB Output is correct
35 Correct 2 ms 4444 KB Output is correct
36 Correct 112 ms 15568 KB Output is correct
37 Correct 103 ms 14932 KB Output is correct
38 Correct 36 ms 11344 KB Output is correct
39 Correct 79 ms 13500 KB Output is correct
40 Correct 89 ms 14292 KB Output is correct
41 Correct 105 ms 14928 KB Output is correct
42 Correct 73 ms 13004 KB Output is correct
43 Correct 55 ms 14384 KB Output is correct
44 Correct 118 ms 18260 KB Output is correct
45 Correct 118 ms 18260 KB Output is correct
46 Correct 122 ms 18224 KB Output is correct
47 Correct 109 ms 17872 KB Output is correct
48 Correct 117 ms 18516 KB Output is correct
49 Correct 109 ms 17864 KB Output is correct
50 Correct 116 ms 18512 KB Output is correct