답안 #1038832

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1038832 2024-07-30T08:08:56 Z 정민찬(#10987) Card Collection (JOI24_collection) C++17
71 / 100
4000 ms 13492 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;

int N, M;
int A[200010], B[200010];
int QA[200010], QB[200010];

vector<int> solve() {
    vector<int> ret(M+1, 0);
    for (int i=1; i<=M; i++) {
        int lm = -1, rm = -1;
        for (int j=1; j<=N; j++) {
            if (B[j] == QB[i]) {
                lm = j;
                break;
            }
        }
        for (int j=N; j>=1; j--) {
            if (A[j] == QA[i]) {
                rm = j;
                break;
            }
        }
        if (lm == -1 || rm == -1 || lm > rm) continue;
        if (lm == rm) {
            int mxa = 0, mxb = 0;
            int mna = 1e9, mnb = 1e9;
            for (int j=1; j<lm; j++) {
                mxa = max(mxa, A[j]);
                mxb = max(mxb, B[j]);
                mna = min(mna, A[j]);
                mnb = min(mnb, B[j]);
            }
            if (lm != 1 && (mxa < QA[i] || mxb < QB[i]) && (mna > QA[i] || mnb > QB[i])) continue;
            mxa = 0; mxb = 0; mna = 1e9; mnb = 1e9;
            for (int j=rm+1; j<=N; j++) {
                mxa = max(mxa, A[j]);
                mxb = max(mxb, B[j]);
                mna = min(mna, A[j]);
                mnb = min(mnb, B[j]);
            }
            if (lm != N && (mxa < QA[i] || mxb < QB[i]) && (mna > QA[i] || mnb > QB[i])) continue;
            ret[i] = 1;
            continue;
        }
        int lh = N+1, non = 0;
        for (int j=1; j<=N; j++) {
            if (A[j] <= QA[i] && B[j] >= QB[i] && (non || j == 1)) {
                lh = j;
                break;
            }
            if (A[j] <= QA[i] || B[j] >= QB[i]) {
                non ++;
            }
        }
        while (lh <= N && B[lh] != QB[i]) lh ++;
        int rh = 0;
        non = 0;
        for (int j=N; j>=1; j--) {
            if (A[j] >= QA[i] && B[j] <= QB[i] && (non || j == N)) {
                rh = j;
                break;
            }
            if (A[j] >= QA[i] || B[j] <= QB[i]) {
                non ++;
            }
        }
        while (rh >= 1 && A[rh] != QA[i]) rh --;
        int le = lm + 1;
        while (le <= N && (QA[i] < A[le] || QB[i] > B[le])) le ++;
        int re = rm - 1;
        while (re >= 1 && (QA[i] > A[re] || QB[i] < B[re])) re --;
        if (min(max(lh, lm), le) < max(min(rh, rm), re)) {
            ret[i] = 1;
        }
    }
    return ret;
}

int main() {
    ios_base :: sync_with_stdio(false); cin.tie(NULL);
    cin >> N >> M;
    vector<int> ta, tb;
    for (int i=1; i<=N; i++) {
        cin >> A[i] >> B[i];
        ta.push_back(A[i]);
        tb.push_back(B[i]);
    }

    for (int i=1; i<=M; i++) {
        cin >> QA[i] >> QB[i];
        ta.push_back(QA[i]);
        tb.push_back(QB[i]);
    }
    sort(ta.begin(), ta.end());
    ta.erase(unique(ta.begin(), ta.end()), ta.end());
    sort(tb.begin(), tb.end());
    tb.erase(unique(tb.begin(), tb.end()), tb.end());
    for (int i=1; i<=N; i++) {
        A[i] = lower_bound(ta.begin(), ta.end(), A[i]) - ta.begin() + 1;
        B[i] = lower_bound(tb.begin(), tb.end(), B[i]) - tb.begin() + 1;
    }
    for (int i=1; i<=M; i++) {
        QA[i] = lower_bound(ta.begin(), ta.end(), QA[i]) - ta.begin() + 1;
        QB[i] = lower_bound(tb.begin(), tb.end(), QB[i]) - tb.begin() + 1;
    }
    vector<int> ret[4];
    ret[0] = solve();
    reverse(A+1, A+N+1);
    reverse(B+1, B+N+1);
    ret[1] = solve();
    for (int i=1; i<=N; i++) {
        A[i] = ta.size() - A[i] + 1;
        B[i] = tb.size() - B[i] + 1;
    }
    for (int i=1; i<=M; i++) {
        QA[i] = ta.size() - QA[i] + 1;
        QB[i] = tb.size() - QB[i] + 1;
    }
    ret[2] = solve();
    reverse(A+1, A+N+1);
    reverse(B+1, B+N+1);
    ret[3] = solve();
    for (int i=1; i<=M; i++) {
        int flag = 0;
        for (int j=0; j<4; j++) {
            flag |= ret[j][i];
        }
        if (flag) cout << i << ' ';
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 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 1 ms 2396 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 0 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 0 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 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 0 ms 600 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 2396 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 2392 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 468 KB Output is correct
36 Correct 0 ms 2396 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 2396 KB Output is correct
39 Correct 0 ms 2396 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 1 ms 2392 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 0 ms 464 KB Output is correct
44 Correct 0 ms 344 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 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 1 ms 2396 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 0 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 0 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 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 0 ms 600 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 2396 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 2392 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 468 KB Output is correct
36 Correct 0 ms 2396 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 2396 KB Output is correct
39 Correct 0 ms 2396 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 1 ms 2392 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 0 ms 464 KB Output is correct
44 Correct 0 ms 344 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 1 ms 2396 KB Output is correct
47 Correct 1 ms 348 KB Output is correct
48 Correct 1 ms 348 KB Output is correct
49 Correct 1 ms 348 KB Output is correct
50 Correct 1 ms 348 KB Output is correct
51 Correct 1 ms 348 KB Output is correct
52 Correct 1 ms 2580 KB Output is correct
53 Correct 1 ms 2396 KB Output is correct
54 Correct 1 ms 348 KB Output is correct
55 Correct 1 ms 348 KB Output is correct
56 Correct 1 ms 2396 KB Output is correct
57 Correct 1 ms 484 KB Output is correct
58 Correct 1 ms 348 KB Output is correct
59 Correct 1 ms 540 KB Output is correct
60 Correct 1 ms 344 KB Output is correct
61 Correct 1 ms 348 KB Output is correct
62 Correct 1 ms 348 KB Output is correct
63 Correct 1 ms 348 KB Output is correct
64 Correct 1 ms 348 KB Output is correct
65 Correct 1 ms 344 KB Output is correct
66 Correct 1 ms 344 KB Output is correct
67 Correct 1 ms 348 KB Output is correct
68 Correct 1 ms 348 KB Output is correct
69 Correct 1 ms 348 KB Output is correct
70 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 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 1 ms 2396 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 0 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 0 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 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 0 ms 600 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 2396 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 2392 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 468 KB Output is correct
36 Correct 0 ms 2396 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 2396 KB Output is correct
39 Correct 0 ms 2396 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 1 ms 2392 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 0 ms 464 KB Output is correct
44 Correct 0 ms 344 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 1 ms 2396 KB Output is correct
47 Correct 1 ms 348 KB Output is correct
48 Correct 1 ms 348 KB Output is correct
49 Correct 1 ms 348 KB Output is correct
50 Correct 1 ms 348 KB Output is correct
51 Correct 1 ms 348 KB Output is correct
52 Correct 1 ms 2580 KB Output is correct
53 Correct 1 ms 2396 KB Output is correct
54 Correct 1 ms 348 KB Output is correct
55 Correct 1 ms 348 KB Output is correct
56 Correct 1 ms 2396 KB Output is correct
57 Correct 1 ms 484 KB Output is correct
58 Correct 1 ms 348 KB Output is correct
59 Correct 1 ms 540 KB Output is correct
60 Correct 1 ms 344 KB Output is correct
61 Correct 1 ms 348 KB Output is correct
62 Correct 1 ms 348 KB Output is correct
63 Correct 1 ms 348 KB Output is correct
64 Correct 1 ms 348 KB Output is correct
65 Correct 1 ms 344 KB Output is correct
66 Correct 1 ms 344 KB Output is correct
67 Correct 1 ms 348 KB Output is correct
68 Correct 1 ms 348 KB Output is correct
69 Correct 1 ms 348 KB Output is correct
70 Correct 1 ms 348 KB Output is correct
71 Correct 75 ms 7460 KB Output is correct
72 Correct 80 ms 6072 KB Output is correct
73 Correct 88 ms 6592 KB Output is correct
74 Correct 92 ms 6848 KB Output is correct
75 Correct 97 ms 7104 KB Output is correct
76 Correct 104 ms 7524 KB Output is correct
77 Correct 95 ms 6868 KB Output is correct
78 Correct 104 ms 7100 KB Output is correct
79 Correct 105 ms 7632 KB Output is correct
80 Correct 54 ms 6148 KB Output is correct
81 Correct 56 ms 6332 KB Output is correct
82 Correct 59 ms 8128 KB Output is correct
83 Correct 102 ms 7640 KB Output is correct
84 Correct 74 ms 7616 KB Output is correct
85 Correct 60 ms 7468 KB Output is correct
86 Correct 44 ms 8900 KB Output is correct
87 Correct 38 ms 4552 KB Output is correct
88 Correct 32 ms 4552 KB Output is correct
89 Correct 33 ms 4552 KB Output is correct
90 Correct 34 ms 4552 KB Output is correct
91 Correct 44 ms 4552 KB Output is correct
92 Correct 37 ms 4536 KB Output is correct
93 Correct 35 ms 6084 KB Output is correct
94 Correct 33 ms 5876 KB Output is correct
95 Correct 38 ms 4548 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 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 1 ms 2396 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 0 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 0 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 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 0 ms 600 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 2396 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 2392 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 468 KB Output is correct
36 Correct 0 ms 2396 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 2396 KB Output is correct
39 Correct 0 ms 2396 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 1 ms 2392 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 0 ms 464 KB Output is correct
44 Correct 0 ms 344 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 1 ms 2396 KB Output is correct
47 Correct 1 ms 348 KB Output is correct
48 Correct 1 ms 348 KB Output is correct
49 Correct 1 ms 348 KB Output is correct
50 Correct 1 ms 348 KB Output is correct
51 Correct 1 ms 348 KB Output is correct
52 Correct 1 ms 2580 KB Output is correct
53 Correct 1 ms 2396 KB Output is correct
54 Correct 1 ms 348 KB Output is correct
55 Correct 1 ms 348 KB Output is correct
56 Correct 1 ms 2396 KB Output is correct
57 Correct 1 ms 484 KB Output is correct
58 Correct 1 ms 348 KB Output is correct
59 Correct 1 ms 540 KB Output is correct
60 Correct 1 ms 344 KB Output is correct
61 Correct 1 ms 348 KB Output is correct
62 Correct 1 ms 348 KB Output is correct
63 Correct 1 ms 348 KB Output is correct
64 Correct 1 ms 348 KB Output is correct
65 Correct 1 ms 344 KB Output is correct
66 Correct 1 ms 344 KB Output is correct
67 Correct 1 ms 348 KB Output is correct
68 Correct 1 ms 348 KB Output is correct
69 Correct 1 ms 348 KB Output is correct
70 Correct 1 ms 348 KB Output is correct
71 Correct 75 ms 7460 KB Output is correct
72 Correct 80 ms 6072 KB Output is correct
73 Correct 88 ms 6592 KB Output is correct
74 Correct 92 ms 6848 KB Output is correct
75 Correct 97 ms 7104 KB Output is correct
76 Correct 104 ms 7524 KB Output is correct
77 Correct 95 ms 6868 KB Output is correct
78 Correct 104 ms 7100 KB Output is correct
79 Correct 105 ms 7632 KB Output is correct
80 Correct 54 ms 6148 KB Output is correct
81 Correct 56 ms 6332 KB Output is correct
82 Correct 59 ms 8128 KB Output is correct
83 Correct 102 ms 7640 KB Output is correct
84 Correct 74 ms 7616 KB Output is correct
85 Correct 60 ms 7468 KB Output is correct
86 Correct 44 ms 8900 KB Output is correct
87 Correct 38 ms 4552 KB Output is correct
88 Correct 32 ms 4552 KB Output is correct
89 Correct 33 ms 4552 KB Output is correct
90 Correct 34 ms 4552 KB Output is correct
91 Correct 44 ms 4552 KB Output is correct
92 Correct 37 ms 4536 KB Output is correct
93 Correct 35 ms 6084 KB Output is correct
94 Correct 33 ms 5876 KB Output is correct
95 Correct 38 ms 4548 KB Output is correct
96 Execution timed out 4033 ms 13492 KB Time limit exceeded
97 Halted 0 ms 0 KB -