답안 #307835

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
307835 2020-09-29T11:31:18 Z andreiomd Matryoshka (JOI16_matryoshka) C++11
51 / 100
2000 ms 16452 KB
#include <iostream>
#include <algorithm>

using namespace std;

typedef pair < int, int > PII;
typedef pair < int, PII > Query;

const int NMAX = 2e5 + 1, QMAX = 2e5 + 1;
const int TMAX = (NMAX + QMAX);

int N, Q;
PII A[NMAX];

int B[(TMAX << 1)], V[(TMAX << 1)];

Query List[QMAX];
int ans[QMAX];

int dp[NMAX];

static inline void Read ()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> N >> Q;

    for(int i = 1; i <= N; ++i)
    {
        cin >> A[i].first >> A[i].second;

        B[++B[0]] = A[i].first, B[++B[0]] = A[i].second;
    }

    for(int i = 1; i <= Q; ++i)
    {
        cin >> List[i].second.first >> List[i].first, List[i].second.second = i;

        B[++B[0]] = List[i].second.first, B[++B[0]] = List[i].first;
    }

    return;
}

static inline void Normalize ()
{
    sort(B + 1, B + B[0] + 1);

    V[++V[0]] = B[1];

    for(int i = 2; i <= B[0]; ++i)
        V[++V[0]] = B[i];

    return;
}

auto cmp = [] (PII A, PII B)
{
    if(A.second < B.second)
        return 1;

    if(A.second > B.second)
        return 0;

    if(A.first > B.first)
        return 1;

    return 0;
};

static inline void Sort ()
{
    sort(A + 1, A + N + 1, cmp);

    sort(List + 1, List + Q + 1);

    return;
}

static inline int my_max (int a, int b)
{
    return ((a > b) ? a : b);
}

static inline void Solve ()
{
    Sort();

    int Last_Valid_Position = 0;

    int vec[NMAX], m = 0;

    for(int i = 1; i <= Q; ++i)
    {
        while(Last_Valid_Position < N && A[Last_Valid_Position + 1].second <= List[i].first)
            ++Last_Valid_Position;

        m = 0;

        for(int j = 1; j <= Last_Valid_Position; ++j)
        {
            int X = A[j].first;

            if(X < List[i].second.first)
                continue;

            if(!m)
                vec[++m] = X;
            else
            {
                int Left = 1, Right = m, pos = 0;

                while(Left <= Right)
                {
                    int Mid = (Left + Right) / 2;

                    if(vec[Mid] < X)
                        pos = Mid, Right = Mid - 1;
                    else
                        Left = Mid + 1;
                }

                if(!pos)
                    vec[++m] = X;
                else
                    vec[pos] = X;
            }
        }

        ans[List[i].second.second] = m;
    }

    for(int i = 1; i <= Q; ++i)
        cout << ans[i] << '\n';

    return;
}

int main()
{
    Read();

    Normalize();

    Solve();

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 10 ms 512 KB Output is correct
23 Correct 40 ms 632 KB Output is correct
24 Correct 13 ms 640 KB Output is correct
25 Correct 30 ms 640 KB Output is correct
26 Correct 15 ms 640 KB Output is correct
27 Correct 12 ms 640 KB Output is correct
28 Correct 30 ms 632 KB Output is correct
29 Correct 25 ms 640 KB Output is correct
30 Correct 25 ms 632 KB Output is correct
31 Correct 39 ms 640 KB Output is correct
32 Correct 40 ms 620 KB Output is correct
33 Correct 39 ms 624 KB Output is correct
34 Correct 39 ms 632 KB Output is correct
35 Correct 40 ms 628 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 10 ms 512 KB Output is correct
23 Correct 40 ms 632 KB Output is correct
24 Correct 13 ms 640 KB Output is correct
25 Correct 30 ms 640 KB Output is correct
26 Correct 15 ms 640 KB Output is correct
27 Correct 12 ms 640 KB Output is correct
28 Correct 30 ms 632 KB Output is correct
29 Correct 25 ms 640 KB Output is correct
30 Correct 25 ms 632 KB Output is correct
31 Correct 39 ms 640 KB Output is correct
32 Correct 40 ms 620 KB Output is correct
33 Correct 39 ms 624 KB Output is correct
34 Correct 39 ms 632 KB Output is correct
35 Correct 40 ms 628 KB Output is correct
36 Execution timed out 2093 ms 16452 KB Time limit exceeded
37 Halted 0 ms 0 KB -