Submission #849169

# Submission time Handle Problem Language Result Execution time Memory
849169 2023-09-14T08:12:14 Z hngwlog New Home (APIO18_new_home) C++14
12 / 100
1513 ms 9944 KB
#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define _size(x) (int)x.size()
#define BIT(i, x) ((x >> i) & 1)
#define MASK(n) ((1 << n) - 1)
#define REP(i, n) for (int i = 0, _n = (n); i < _n; i++)
#define FOR(i, a, b) for (int i = a, _b = (b); i <= _b; i++)
#define FORD(i, a, b) for (int i = a, _b = (b); i >= _b; i--)
#define FORB1(i, mask) for (int i = mask; i > 0; i ^= i & - i)
#define FORB0(i, n, mask) for (int i = ((1 << n) - 1) ^ mask; i > 0; i ^= i & - i)
#define FORALL(i, a) for (auto i: a)
#define fastio ios_base::sync_with_stdio(0); cin.tie(0);

struct storeNode {

    int x, t, a, b;
};

struct queryNode {

    int l, y, id;
};

int n, k, q;
vector<storeNode> store;
vector<queryNode> qu;

namespace subtask12 {

    const int inf = 1e9;

    void main() {

        vector<pair<int, int>> g;
        FOR(i, 1, n) g.push_back({store[i].a, i}), g.push_back({store[i].b, - i});
        REP(i, q) g.push_back({qu[i].y, 0});
        sort(g.begin(), g.end(), [&] (const pair<int, int> a, pair<int, int> b) { return a.fi != b.fi ? a.fi < b.fi : a.se > b.se; });
        sort(qu.begin(), qu.end(), [&] (const queryNode a, queryNode b) { return a.y < b.y; });
        vector<int> ans(q);
        vector<multiset<int>> mts(k + 1);
        int i = 0, z = 0;
        while (i < _size(g)) {
            int j = i;
            while (j < _size(g) && g[j].fi == g[i].fi && g[j].se > 0) {
                int id = g[j].se;
                mts[store[id].t].insert(store[id].x);
                j++;
            }
            while (j < _size(g) && g[j].fi == g[i].fi && g[j].se == 0) j++;
            while (z < q && qu[z].y == g[i].fi) {
                int res = - 1;
                FOR(id, 1, k) {
                    if (mts[id].empty()) {
                        res = - 1;
                        break;
                    }
                    auto it = mts[id].lower_bound(qu[z].l);
                    int _res = inf;
                    if (it != mts[id].end()) _res = min(_res, *it - qu[z].l);
                    if (it != mts[id].begin()) {
                        --it;
                        _res = min(_res, qu[z].l - *it);
                    }
                    res = max(res, _res);
                }
                ans[qu[z].id] = res;
                z++;
            }
            while (j < _size(g) && g[j].fi == g[i].fi) {
                int id = - g[j].se;
                mts[store[id].t].erase(mts[store[id].t].find(store[id].x));
                j++;
            }
            i = j;
        }
        REP(i, q) cout << ans[i] << '\n';
    }
}

int main() {
    fastio;

    cin >> n >> k >> q;
    store.resize(n + 1);
    FOR(i, 1, n) {
        int x, t, a, b;
        cin >> x >> t >> a >> b;
        store[i] = {x, t, a, b};
    }
    qu.resize(q);
    REP(i, q) {
        cin >> qu[i].l >> qu[i].y;
        qu[i].id = i;
    }
    if (max(n, q) <= 60000 && k <= 400) subtask12::main();
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 556 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 2 ms 468 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 1 ms 488 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 556 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 2 ms 468 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 1 ms 488 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1513 ms 9912 KB Output is correct
32 Correct 68 ms 5832 KB Output is correct
33 Correct 132 ms 7880 KB Output is correct
34 Correct 1174 ms 8004 KB Output is correct
35 Correct 691 ms 9944 KB Output is correct
36 Correct 154 ms 9672 KB Output is correct
37 Correct 129 ms 7036 KB Output is correct
38 Correct 77 ms 7068 KB Output is correct
39 Correct 70 ms 7124 KB Output is correct
40 Correct 65 ms 7116 KB Output is correct
41 Correct 193 ms 7220 KB Output is correct
42 Correct 147 ms 7116 KB Output is correct
43 Correct 155 ms 9304 KB Output is correct
44 Correct 170 ms 7116 KB Output is correct
45 Correct 92 ms 7160 KB Output is correct
46 Correct 57 ms 7144 KB Output is correct
47 Correct 57 ms 7072 KB Output is correct
48 Correct 48 ms 6860 KB Output is correct
49 Correct 60 ms 6856 KB Output is correct
50 Correct 152 ms 7116 KB Output is correct
51 Correct 54 ms 6860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 123 ms 8468 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 119 ms 8472 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 556 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 2 ms 468 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 1 ms 488 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1513 ms 9912 KB Output is correct
32 Correct 68 ms 5832 KB Output is correct
33 Correct 132 ms 7880 KB Output is correct
34 Correct 1174 ms 8004 KB Output is correct
35 Correct 691 ms 9944 KB Output is correct
36 Correct 154 ms 9672 KB Output is correct
37 Correct 129 ms 7036 KB Output is correct
38 Correct 77 ms 7068 KB Output is correct
39 Correct 70 ms 7124 KB Output is correct
40 Correct 65 ms 7116 KB Output is correct
41 Correct 193 ms 7220 KB Output is correct
42 Correct 147 ms 7116 KB Output is correct
43 Correct 155 ms 9304 KB Output is correct
44 Correct 170 ms 7116 KB Output is correct
45 Correct 92 ms 7160 KB Output is correct
46 Correct 57 ms 7144 KB Output is correct
47 Correct 57 ms 7072 KB Output is correct
48 Correct 48 ms 6860 KB Output is correct
49 Correct 60 ms 6856 KB Output is correct
50 Correct 152 ms 7116 KB Output is correct
51 Correct 54 ms 6860 KB Output is correct
52 Incorrect 26 ms 5048 KB Output isn't correct
53 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 556 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 2 ms 468 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 1 ms 488 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1513 ms 9912 KB Output is correct
32 Correct 68 ms 5832 KB Output is correct
33 Correct 132 ms 7880 KB Output is correct
34 Correct 1174 ms 8004 KB Output is correct
35 Correct 691 ms 9944 KB Output is correct
36 Correct 154 ms 9672 KB Output is correct
37 Correct 129 ms 7036 KB Output is correct
38 Correct 77 ms 7068 KB Output is correct
39 Correct 70 ms 7124 KB Output is correct
40 Correct 65 ms 7116 KB Output is correct
41 Correct 193 ms 7220 KB Output is correct
42 Correct 147 ms 7116 KB Output is correct
43 Correct 155 ms 9304 KB Output is correct
44 Correct 170 ms 7116 KB Output is correct
45 Correct 92 ms 7160 KB Output is correct
46 Correct 57 ms 7144 KB Output is correct
47 Correct 57 ms 7072 KB Output is correct
48 Correct 48 ms 6860 KB Output is correct
49 Correct 60 ms 6856 KB Output is correct
50 Correct 152 ms 7116 KB Output is correct
51 Correct 54 ms 6860 KB Output is correct
52 Incorrect 123 ms 8468 KB Output isn't correct
53 Halted 0 ms 0 KB -