답안 #805247

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
805247 2023-08-03T14:32:25 Z Sharky Passport (JOI23_passport) C++17
0 / 100
2000 ms 6228 KB
#include <bits/stdc++.h>
using namespace std;

const int maxn = 2E5+8;
int n, q, L[maxn], R[maxn];

struct segtree {
    int size = 1;
    vector<int> seg;
    void init(int n) {
        while (size < n) size *= 2;
        seg.assign(2 * size + 5, 0);
    }
    void update(int pos, int val, int l, int r, int id) {
        if (l == r) {
            seg[id] = max(seg[id], val);
            return;
        }
        int mid = (l + r) >> 1;
        update(pos, val, l, mid, id * 2);
        update(pos, val, mid + 1, r, id * 2 + 1);
        seg[id] = max(seg[id * 2], seg[id * 2 + 1]);
    }
    int query(int ql, int qr, int l, int r, int id) {
        if (ql <= l && r <= qr) return seg[id];
        if (qr < l || r < ql) return 0;
        int mid = (l + r) >> 1;
        return max(query(ql, qr, l, mid, id * 2), query(ql, qr, mid + 1, r, id * 2 + 1));
    }
} st;

struct passport {
    int l, r, id;
    bool operator < (const passport& o) const {
        return id < o.id;
    }
};

int32_t main() {
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> L[i] >> R[i];
    vector<passport> A;
    for (int i = 1; i <= n; i++) A.push_back((passport) {L[i], R[i], i});
    st.init(n + 1);
    // sort(A.begin(), A.end());
    cin >> q;
    while (q--) {
        int x;
        cin >> x;
        if (x == 1) {
            int r = 1, pt = 0, ans = 0;
            while (r < n) {
                while (pt < n && A[pt].id <= r) {
                    st.update(A[pt].l, A[pt].r, 1, n, 1);
                    pt++;
                }
                int oldr = r;
                r = st.query(1, r, 1, n, 1);
                if (r <= oldr) {
                    cout << "-1\n";
                    goto bye;
                }
                ans++;
            }
            cout << ans << "\n";
            bye:{}
        }
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Execution timed out 2078 ms 6228 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Execution timed out 2078 ms 6228 KB Time limit exceeded
5 Halted 0 ms 0 KB -