답안 #742819

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
742819 2023-05-17T03:07:19 Z PixelCat 새 집 (APIO18_new_home) C++14
12 / 100
5000 ms 63776 KB
#include <bits/stdc++.h>
#define For(i, a, b) for(int i = a; i <= b; i++)
#define Forr(i, a, b) for(int i = a; i >= b; i--)
#define F first
#define S second
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) ((int)x.size())
#define int LL
using namespace std;
using LL = long long;
using pii = pair<int, int>;

const int MAXN = 300030;
const int INF = 1e12;

struct Line {
    int m, c;  // mx + c
    Line(int _m = 0, int _c = 0): m(_m), c(_c) {}
    int operator()(int x) {
        return m * x + c;
    }
};
Line operator+(const Line& a, const Line& b) {
    return Line(a.m + b.m, a.c + b.c);
}
Line operator-(const Line& a, const Line& b) {
    return Line(a.m - b.m, a.c - b.c);
}

#define L(id) ((id) * 2 + 1)
#define R(id) ((id) * 2 + 2)
struct SegTree {
    // TODO
} seg;

struct Event {
    int pos, time, type, add;
    // add: 49 = query, 1 = insert, -1 = erase
}; deque<Event> dq;

multiset<int> st[MAXN];
int ans[MAXN];

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    // =^-w-^= nya
    int n, k, q; cin >> n >> k >> q;
    For(i, 1, n) {
        int x, t, a, b; cin >> x >> t >> a >> b;
        dq.eb((Event){ x, a, t, 1 });
        dq.eb((Event){ x, b + 1, t, -1 });
    }
    For(i, 1, q) {
        int p, t; cin >> p >> t;
        dq.eb((Event){p, t, i, 49});
    }
    sort(all(dq), [&](const Event &a, const Event &b) {
        if(a.time != b.time) return a.time < b.time;
        return a.add < b.add;
    });

    while(!dq.empty()) {
        auto e = dq.front(); dq.pop_front();

        if(e.add == 49) {
            // query
            int mx = -1;
            For(i, 1, k) {
                int tmp = INF;
                auto it = st[i].lower_bound(e.pos);
                if(it != st[i].end()) {
                    tmp = min(tmp, abs(e.pos - (*it)));
                }
                if(it != st[i].begin()) {
                    it = prev(it);
                    tmp = min(tmp, abs(e.pos - (*it)));
                }
                mx = max(mx, tmp);
            }
            if(mx >= INF) mx = -1;
            ans[e.type] = mx;
        } else if(e.add == 1) {
            // insert
            st[e.type].insert(e.pos);
        } else if(e.add == -1) {
            // erase
            st[e.type].erase(st[e.type].find(e.pos));
        }
    }

    For(i, 1, q) cout << ans[i] << "\n";
    return 0;
}

/*

4 2 4
3 1 1 10
9 2 2 4
7 2 5 7
4 1 8 10
5 3
5 6
5 9
1 10

2 1 3
1 1 1 4
1 1 2 6
1 3
1 5
1 7

1 1 1
100000000 1 1 1
1 1

*/
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14420 KB Output is correct
2 Correct 11 ms 14416 KB Output is correct
3 Correct 7 ms 14420 KB Output is correct
4 Correct 8 ms 14416 KB Output is correct
5 Correct 8 ms 14420 KB Output is correct
6 Correct 8 ms 14420 KB Output is correct
7 Correct 8 ms 14420 KB Output is correct
8 Correct 8 ms 14396 KB Output is correct
9 Correct 9 ms 14484 KB Output is correct
10 Correct 7 ms 14420 KB Output is correct
11 Correct 7 ms 14420 KB Output is correct
12 Correct 8 ms 14388 KB Output is correct
13 Correct 7 ms 14420 KB Output is correct
14 Correct 8 ms 14420 KB Output is correct
15 Correct 8 ms 14428 KB Output is correct
16 Correct 8 ms 14460 KB Output is correct
17 Correct 8 ms 14432 KB Output is correct
18 Correct 8 ms 14428 KB Output is correct
19 Correct 9 ms 14420 KB Output is correct
20 Correct 9 ms 14456 KB Output is correct
21 Correct 8 ms 14548 KB Output is correct
22 Correct 8 ms 14432 KB Output is correct
23 Correct 9 ms 14396 KB Output is correct
24 Correct 8 ms 14420 KB Output is correct
25 Correct 8 ms 14424 KB Output is correct
26 Correct 7 ms 14420 KB Output is correct
27 Correct 8 ms 14420 KB Output is correct
28 Correct 7 ms 14420 KB Output is correct
29 Correct 8 ms 14424 KB Output is correct
30 Correct 7 ms 14420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14420 KB Output is correct
2 Correct 11 ms 14416 KB Output is correct
3 Correct 7 ms 14420 KB Output is correct
4 Correct 8 ms 14416 KB Output is correct
5 Correct 8 ms 14420 KB Output is correct
6 Correct 8 ms 14420 KB Output is correct
7 Correct 8 ms 14420 KB Output is correct
8 Correct 8 ms 14396 KB Output is correct
9 Correct 9 ms 14484 KB Output is correct
10 Correct 7 ms 14420 KB Output is correct
11 Correct 7 ms 14420 KB Output is correct
12 Correct 8 ms 14388 KB Output is correct
13 Correct 7 ms 14420 KB Output is correct
14 Correct 8 ms 14420 KB Output is correct
15 Correct 8 ms 14428 KB Output is correct
16 Correct 8 ms 14460 KB Output is correct
17 Correct 8 ms 14432 KB Output is correct
18 Correct 8 ms 14428 KB Output is correct
19 Correct 9 ms 14420 KB Output is correct
20 Correct 9 ms 14456 KB Output is correct
21 Correct 8 ms 14548 KB Output is correct
22 Correct 8 ms 14432 KB Output is correct
23 Correct 9 ms 14396 KB Output is correct
24 Correct 8 ms 14420 KB Output is correct
25 Correct 8 ms 14424 KB Output is correct
26 Correct 7 ms 14420 KB Output is correct
27 Correct 8 ms 14420 KB Output is correct
28 Correct 7 ms 14420 KB Output is correct
29 Correct 8 ms 14424 KB Output is correct
30 Correct 7 ms 14420 KB Output is correct
31 Correct 1767 ms 24120 KB Output is correct
32 Correct 101 ms 21944 KB Output is correct
33 Correct 153 ms 23960 KB Output is correct
34 Correct 1410 ms 24128 KB Output is correct
35 Correct 784 ms 24172 KB Output is correct
36 Correct 183 ms 24072 KB Output is correct
37 Correct 145 ms 23984 KB Output is correct
38 Correct 94 ms 23876 KB Output is correct
39 Correct 89 ms 23964 KB Output is correct
40 Correct 82 ms 23884 KB Output is correct
41 Correct 242 ms 24268 KB Output is correct
42 Correct 320 ms 24208 KB Output is correct
43 Correct 249 ms 23964 KB Output is correct
44 Correct 202 ms 24236 KB Output is correct
45 Correct 113 ms 24104 KB Output is correct
46 Correct 75 ms 24180 KB Output is correct
47 Correct 84 ms 23580 KB Output is correct
48 Correct 68 ms 23656 KB Output is correct
49 Correct 77 ms 23784 KB Output is correct
50 Correct 190 ms 23972 KB Output is correct
51 Correct 71 ms 23756 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5048 ms 63776 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5030 ms 63660 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14420 KB Output is correct
2 Correct 11 ms 14416 KB Output is correct
3 Correct 7 ms 14420 KB Output is correct
4 Correct 8 ms 14416 KB Output is correct
5 Correct 8 ms 14420 KB Output is correct
6 Correct 8 ms 14420 KB Output is correct
7 Correct 8 ms 14420 KB Output is correct
8 Correct 8 ms 14396 KB Output is correct
9 Correct 9 ms 14484 KB Output is correct
10 Correct 7 ms 14420 KB Output is correct
11 Correct 7 ms 14420 KB Output is correct
12 Correct 8 ms 14388 KB Output is correct
13 Correct 7 ms 14420 KB Output is correct
14 Correct 8 ms 14420 KB Output is correct
15 Correct 8 ms 14428 KB Output is correct
16 Correct 8 ms 14460 KB Output is correct
17 Correct 8 ms 14432 KB Output is correct
18 Correct 8 ms 14428 KB Output is correct
19 Correct 9 ms 14420 KB Output is correct
20 Correct 9 ms 14456 KB Output is correct
21 Correct 8 ms 14548 KB Output is correct
22 Correct 8 ms 14432 KB Output is correct
23 Correct 9 ms 14396 KB Output is correct
24 Correct 8 ms 14420 KB Output is correct
25 Correct 8 ms 14424 KB Output is correct
26 Correct 7 ms 14420 KB Output is correct
27 Correct 8 ms 14420 KB Output is correct
28 Correct 7 ms 14420 KB Output is correct
29 Correct 8 ms 14424 KB Output is correct
30 Correct 7 ms 14420 KB Output is correct
31 Correct 1767 ms 24120 KB Output is correct
32 Correct 101 ms 21944 KB Output is correct
33 Correct 153 ms 23960 KB Output is correct
34 Correct 1410 ms 24128 KB Output is correct
35 Correct 784 ms 24172 KB Output is correct
36 Correct 183 ms 24072 KB Output is correct
37 Correct 145 ms 23984 KB Output is correct
38 Correct 94 ms 23876 KB Output is correct
39 Correct 89 ms 23964 KB Output is correct
40 Correct 82 ms 23884 KB Output is correct
41 Correct 242 ms 24268 KB Output is correct
42 Correct 320 ms 24208 KB Output is correct
43 Correct 249 ms 23964 KB Output is correct
44 Correct 202 ms 24236 KB Output is correct
45 Correct 113 ms 24104 KB Output is correct
46 Correct 75 ms 24180 KB Output is correct
47 Correct 84 ms 23580 KB Output is correct
48 Correct 68 ms 23656 KB Output is correct
49 Correct 77 ms 23784 KB Output is correct
50 Correct 190 ms 23972 KB Output is correct
51 Correct 71 ms 23756 KB Output is correct
52 Execution timed out 5065 ms 23836 KB Time limit exceeded
53 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14420 KB Output is correct
2 Correct 11 ms 14416 KB Output is correct
3 Correct 7 ms 14420 KB Output is correct
4 Correct 8 ms 14416 KB Output is correct
5 Correct 8 ms 14420 KB Output is correct
6 Correct 8 ms 14420 KB Output is correct
7 Correct 8 ms 14420 KB Output is correct
8 Correct 8 ms 14396 KB Output is correct
9 Correct 9 ms 14484 KB Output is correct
10 Correct 7 ms 14420 KB Output is correct
11 Correct 7 ms 14420 KB Output is correct
12 Correct 8 ms 14388 KB Output is correct
13 Correct 7 ms 14420 KB Output is correct
14 Correct 8 ms 14420 KB Output is correct
15 Correct 8 ms 14428 KB Output is correct
16 Correct 8 ms 14460 KB Output is correct
17 Correct 8 ms 14432 KB Output is correct
18 Correct 8 ms 14428 KB Output is correct
19 Correct 9 ms 14420 KB Output is correct
20 Correct 9 ms 14456 KB Output is correct
21 Correct 8 ms 14548 KB Output is correct
22 Correct 8 ms 14432 KB Output is correct
23 Correct 9 ms 14396 KB Output is correct
24 Correct 8 ms 14420 KB Output is correct
25 Correct 8 ms 14424 KB Output is correct
26 Correct 7 ms 14420 KB Output is correct
27 Correct 8 ms 14420 KB Output is correct
28 Correct 7 ms 14420 KB Output is correct
29 Correct 8 ms 14424 KB Output is correct
30 Correct 7 ms 14420 KB Output is correct
31 Correct 1767 ms 24120 KB Output is correct
32 Correct 101 ms 21944 KB Output is correct
33 Correct 153 ms 23960 KB Output is correct
34 Correct 1410 ms 24128 KB Output is correct
35 Correct 784 ms 24172 KB Output is correct
36 Correct 183 ms 24072 KB Output is correct
37 Correct 145 ms 23984 KB Output is correct
38 Correct 94 ms 23876 KB Output is correct
39 Correct 89 ms 23964 KB Output is correct
40 Correct 82 ms 23884 KB Output is correct
41 Correct 242 ms 24268 KB Output is correct
42 Correct 320 ms 24208 KB Output is correct
43 Correct 249 ms 23964 KB Output is correct
44 Correct 202 ms 24236 KB Output is correct
45 Correct 113 ms 24104 KB Output is correct
46 Correct 75 ms 24180 KB Output is correct
47 Correct 84 ms 23580 KB Output is correct
48 Correct 68 ms 23656 KB Output is correct
49 Correct 77 ms 23784 KB Output is correct
50 Correct 190 ms 23972 KB Output is correct
51 Correct 71 ms 23756 KB Output is correct
52 Execution timed out 5048 ms 63776 KB Time limit exceeded
53 Halted 0 ms 0 KB -