답안 #847281

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
847281 2023-09-09T11:14:22 Z borisAngelov Matryoshka (JOI16_matryoshka) C++17
100 / 100
122 ms 13904 KB
#include <bits/stdc++.h>

using namespace std;

const int maxn = 200005;
const int inf = 1000000007;

int n, q;

struct doll
{
    int x;
    int y;
};

doll a[maxn];

struct query
{
    int minx;
    int maxy;
    int idx;
};

query queries[maxn];
int answers[maxn];

void fastIO()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

int main()
{
    fastIO();

    cin >> n >> q;

    for (int i = 1; i <= n; ++i)
    {
        cin >> a[i].x >> a[i].y;
    }

    sort(a + 1, a + n + 1, [&](doll fr, doll sc)
    {
        if (fr.x != sc.x)
        {
            return fr.x > sc.x;
        }

        return fr.y < sc.y;
    });

    for (int i = 1; i <= q; ++i)
    {
        cin >> queries[i].minx >> queries[i].maxy;
        queries[i].idx = i;
    }

    sort(queries + 1, queries + q + 1, [&](query fr, query sc)
    {
        if (fr.minx != sc.minx)
        {
            return fr.minx > sc.minx;
        }

        return fr.maxy > sc.maxy;
    });

    vector<int> endings;

    int ptr = 1;

    for (int i = 1; i <= q; ++i)
    {
        while (ptr <= n && a[ptr].x >= queries[i].minx)
        {
            int len = upper_bound(endings.begin(), endings.end(), a[ptr].y) - endings.begin();

            if (len == endings.size())
            {
                endings.push_back(a[ptr].y);
            }
            else
            {
                endings[len] = a[ptr].y;
            }

            ++ptr;
        }

        int curr = upper_bound(endings.begin(), endings.end(), queries[i].maxy) - endings.begin();

        answers[queries[i].idx] = curr;
    }

    for (int i = 1; i <= q; ++i)
    {
        cout << answers[i] << "\n";
    }

    return 0;
}

Compilation message

matryoshka.cpp: In function 'int main()':
matryoshka.cpp:82:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   82 |             if (len == endings.size())
      |                 ~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4440 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4440 KB Output is correct
5 Correct 1 ms 4440 KB Output is correct
6 Correct 1 ms 4440 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4440 KB Output is correct
9 Correct 1 ms 4440 KB Output is correct
10 Correct 1 ms 4440 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4440 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4440 KB Output is correct
5 Correct 1 ms 4440 KB Output is correct
6 Correct 1 ms 4440 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4440 KB Output is correct
9 Correct 1 ms 4440 KB Output is correct
10 Correct 1 ms 4440 KB Output is correct
11 Correct 1 ms 4440 KB Output is correct
12 Correct 1 ms 4440 KB Output is correct
13 Correct 1 ms 4440 KB Output is correct
14 Correct 1 ms 4440 KB Output is correct
15 Correct 1 ms 4440 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 4440 KB Output is correct
20 Correct 1 ms 4440 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4440 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4440 KB Output is correct
5 Correct 1 ms 4440 KB Output is correct
6 Correct 1 ms 4440 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4440 KB Output is correct
9 Correct 1 ms 4440 KB Output is correct
10 Correct 1 ms 4440 KB Output is correct
11 Correct 1 ms 4440 KB Output is correct
12 Correct 1 ms 4440 KB Output is correct
13 Correct 1 ms 4440 KB Output is correct
14 Correct 1 ms 4440 KB Output is correct
15 Correct 1 ms 4440 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 4440 KB Output is correct
20 Correct 1 ms 4440 KB Output is correct
21 Correct 1 ms 4440 KB Output is correct
22 Correct 1 ms 4440 KB Output is correct
23 Correct 2 ms 4440 KB Output is correct
24 Correct 2 ms 4440 KB Output is correct
25 Correct 2 ms 4440 KB Output is correct
26 Correct 2 ms 4440 KB Output is correct
27 Correct 2 ms 4444 KB Output is correct
28 Correct 2 ms 4440 KB Output is correct
29 Correct 2 ms 4440 KB Output is correct
30 Correct 2 ms 4440 KB Output is correct
31 Correct 2 ms 4656 KB Output is correct
32 Correct 2 ms 4440 KB Output is correct
33 Correct 2 ms 4440 KB Output is correct
34 Correct 2 ms 4696 KB Output is correct
35 Correct 2 ms 4440 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4440 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4440 KB Output is correct
5 Correct 1 ms 4440 KB Output is correct
6 Correct 1 ms 4440 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4440 KB Output is correct
9 Correct 1 ms 4440 KB Output is correct
10 Correct 1 ms 4440 KB Output is correct
11 Correct 1 ms 4440 KB Output is correct
12 Correct 1 ms 4440 KB Output is correct
13 Correct 1 ms 4440 KB Output is correct
14 Correct 1 ms 4440 KB Output is correct
15 Correct 1 ms 4440 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 4440 KB Output is correct
20 Correct 1 ms 4440 KB Output is correct
21 Correct 1 ms 4440 KB Output is correct
22 Correct 1 ms 4440 KB Output is correct
23 Correct 2 ms 4440 KB Output is correct
24 Correct 2 ms 4440 KB Output is correct
25 Correct 2 ms 4440 KB Output is correct
26 Correct 2 ms 4440 KB Output is correct
27 Correct 2 ms 4444 KB Output is correct
28 Correct 2 ms 4440 KB Output is correct
29 Correct 2 ms 4440 KB Output is correct
30 Correct 2 ms 4440 KB Output is correct
31 Correct 2 ms 4656 KB Output is correct
32 Correct 2 ms 4440 KB Output is correct
33 Correct 2 ms 4440 KB Output is correct
34 Correct 2 ms 4696 KB Output is correct
35 Correct 2 ms 4440 KB Output is correct
36 Correct 114 ms 10832 KB Output is correct
37 Correct 105 ms 10324 KB Output is correct
38 Correct 37 ms 6992 KB Output is correct
39 Correct 86 ms 8784 KB Output is correct
40 Correct 97 ms 9296 KB Output is correct
41 Correct 111 ms 10104 KB Output is correct
42 Correct 71 ms 8148 KB Output is correct
43 Correct 56 ms 8908 KB Output is correct
44 Correct 122 ms 13728 KB Output is correct
45 Correct 119 ms 13396 KB Output is correct
46 Correct 119 ms 13392 KB Output is correct
47 Correct 108 ms 13136 KB Output is correct
48 Correct 117 ms 13904 KB Output is correct
49 Correct 115 ms 13296 KB Output is correct
50 Correct 117 ms 13904 KB Output is correct