Submission #160548

# Submission time Handle Problem Language Result Execution time Memory
160548 2019-10-28T12:07:14 Z Minnakhmetov New Home (APIO18_new_home) C++14
12 / 100
5000 ms 57776 KB
#include <bits/stdc++.h>
    
#define ll long long
#define all(aaa) aaa.begin(), aaa.end()
  
using namespace std;

struct E {
    int p, t, x, y;
};

const int N = 3e5 + 5, INF = 1e9;
vector<E> v;
int ans[N], mn[N];
multiset<int> st[N];

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);

    int n, k, q;
    cin >> n >> k >> q;

    for (int i = 0; i < n; i++) {
        int x, t, a, b;
        cin >> x >> t >> a >> b;
        t--;
        v.push_back({a, 0, x, t});
        v.push_back({b + 1, 1, x, t});
    }

    for (int i = 0; i < q; i++) {
        int x, y;
        cin >> x >> y;
        v.push_back({y, 2, x, i});
    }

    sort(all(v), [](const E &a, const E &b) {
        return a.p == b.p ? a.t < b.t : a.p < b.p;
    });

    for (E e : v) {
        if (e.t == 0) {
            st[e.y].insert(e.x);
        }
        else if (e.t == 1) {
            st[e.y].erase(st[e.y].find(e.x));
        }
        else {
            fill(mn, mn + k, INF);
            for (int i = 0; i < k; i++) {
                auto it = st[i].lower_bound(e.x);
                if (it != st[i].end())
                    mn[i] = min(mn[i], *it - e.x);
                if (it != st[i].begin()) {
                    it--;
                    mn[i] = min(mn[i], e.x - *it);
                }
            }
            int cur = *max_element(mn, mn + k);
            ans[e.y] = (cur == INF ? -1 : cur);
        }
    }

    for (int i = 0; i < q; i++) {
        cout << ans[i] << "\n";
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 20 ms 14456 KB Output is correct
2 Correct 15 ms 14456 KB Output is correct
3 Correct 15 ms 14456 KB Output is correct
4 Correct 15 ms 14456 KB Output is correct
5 Correct 15 ms 14460 KB Output is correct
6 Correct 16 ms 14456 KB Output is correct
7 Correct 16 ms 14456 KB Output is correct
8 Correct 17 ms 14456 KB Output is correct
9 Correct 18 ms 14584 KB Output is correct
10 Correct 16 ms 14456 KB Output is correct
11 Correct 16 ms 14588 KB Output is correct
12 Correct 16 ms 14584 KB Output is correct
13 Correct 19 ms 14584 KB Output is correct
14 Correct 16 ms 14584 KB Output is correct
15 Correct 16 ms 14584 KB Output is correct
16 Correct 16 ms 14584 KB Output is correct
17 Correct 16 ms 14584 KB Output is correct
18 Correct 17 ms 14584 KB Output is correct
19 Correct 16 ms 14556 KB Output is correct
20 Correct 16 ms 14584 KB Output is correct
21 Correct 16 ms 14584 KB Output is correct
22 Correct 17 ms 14456 KB Output is correct
23 Correct 17 ms 14584 KB Output is correct
24 Correct 16 ms 14456 KB Output is correct
25 Correct 16 ms 14456 KB Output is correct
26 Correct 15 ms 14584 KB Output is correct
27 Correct 15 ms 14456 KB Output is correct
28 Correct 15 ms 14460 KB Output is correct
29 Correct 15 ms 14584 KB Output is correct
30 Correct 15 ms 14428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 14456 KB Output is correct
2 Correct 15 ms 14456 KB Output is correct
3 Correct 15 ms 14456 KB Output is correct
4 Correct 15 ms 14456 KB Output is correct
5 Correct 15 ms 14460 KB Output is correct
6 Correct 16 ms 14456 KB Output is correct
7 Correct 16 ms 14456 KB Output is correct
8 Correct 17 ms 14456 KB Output is correct
9 Correct 18 ms 14584 KB Output is correct
10 Correct 16 ms 14456 KB Output is correct
11 Correct 16 ms 14588 KB Output is correct
12 Correct 16 ms 14584 KB Output is correct
13 Correct 19 ms 14584 KB Output is correct
14 Correct 16 ms 14584 KB Output is correct
15 Correct 16 ms 14584 KB Output is correct
16 Correct 16 ms 14584 KB Output is correct
17 Correct 16 ms 14584 KB Output is correct
18 Correct 17 ms 14584 KB Output is correct
19 Correct 16 ms 14556 KB Output is correct
20 Correct 16 ms 14584 KB Output is correct
21 Correct 16 ms 14584 KB Output is correct
22 Correct 17 ms 14456 KB Output is correct
23 Correct 17 ms 14584 KB Output is correct
24 Correct 16 ms 14456 KB Output is correct
25 Correct 16 ms 14456 KB Output is correct
26 Correct 15 ms 14584 KB Output is correct
27 Correct 15 ms 14456 KB Output is correct
28 Correct 15 ms 14460 KB Output is correct
29 Correct 15 ms 14584 KB Output is correct
30 Correct 15 ms 14428 KB Output is correct
31 Correct 2859 ms 23728 KB Output is correct
32 Correct 122 ms 20064 KB Output is correct
33 Correct 234 ms 21812 KB Output is correct
34 Correct 2314 ms 22096 KB Output is correct
35 Correct 1265 ms 23656 KB Output is correct
36 Correct 272 ms 23604 KB Output is correct
37 Correct 208 ms 21232 KB Output is correct
38 Correct 128 ms 21040 KB Output is correct
39 Correct 116 ms 20840 KB Output is correct
40 Correct 113 ms 20840 KB Output is correct
41 Correct 344 ms 21152 KB Output is correct
42 Correct 453 ms 20968 KB Output is correct
43 Correct 440 ms 23404 KB Output is correct
44 Correct 274 ms 21088 KB Output is correct
45 Correct 151 ms 21092 KB Output is correct
46 Correct 105 ms 21060 KB Output is correct
47 Correct 97 ms 20840 KB Output is correct
48 Correct 92 ms 20840 KB Output is correct
49 Correct 119 ms 20968 KB Output is correct
50 Correct 254 ms 21024 KB Output is correct
51 Correct 100 ms 20840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 5082 ms 57776 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5102 ms 57192 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 20 ms 14456 KB Output is correct
2 Correct 15 ms 14456 KB Output is correct
3 Correct 15 ms 14456 KB Output is correct
4 Correct 15 ms 14456 KB Output is correct
5 Correct 15 ms 14460 KB Output is correct
6 Correct 16 ms 14456 KB Output is correct
7 Correct 16 ms 14456 KB Output is correct
8 Correct 17 ms 14456 KB Output is correct
9 Correct 18 ms 14584 KB Output is correct
10 Correct 16 ms 14456 KB Output is correct
11 Correct 16 ms 14588 KB Output is correct
12 Correct 16 ms 14584 KB Output is correct
13 Correct 19 ms 14584 KB Output is correct
14 Correct 16 ms 14584 KB Output is correct
15 Correct 16 ms 14584 KB Output is correct
16 Correct 16 ms 14584 KB Output is correct
17 Correct 16 ms 14584 KB Output is correct
18 Correct 17 ms 14584 KB Output is correct
19 Correct 16 ms 14556 KB Output is correct
20 Correct 16 ms 14584 KB Output is correct
21 Correct 16 ms 14584 KB Output is correct
22 Correct 17 ms 14456 KB Output is correct
23 Correct 17 ms 14584 KB Output is correct
24 Correct 16 ms 14456 KB Output is correct
25 Correct 16 ms 14456 KB Output is correct
26 Correct 15 ms 14584 KB Output is correct
27 Correct 15 ms 14456 KB Output is correct
28 Correct 15 ms 14460 KB Output is correct
29 Correct 15 ms 14584 KB Output is correct
30 Correct 15 ms 14428 KB Output is correct
31 Correct 2859 ms 23728 KB Output is correct
32 Correct 122 ms 20064 KB Output is correct
33 Correct 234 ms 21812 KB Output is correct
34 Correct 2314 ms 22096 KB Output is correct
35 Correct 1265 ms 23656 KB Output is correct
36 Correct 272 ms 23604 KB Output is correct
37 Correct 208 ms 21232 KB Output is correct
38 Correct 128 ms 21040 KB Output is correct
39 Correct 116 ms 20840 KB Output is correct
40 Correct 113 ms 20840 KB Output is correct
41 Correct 344 ms 21152 KB Output is correct
42 Correct 453 ms 20968 KB Output is correct
43 Correct 440 ms 23404 KB Output is correct
44 Correct 274 ms 21088 KB Output is correct
45 Correct 151 ms 21092 KB Output is correct
46 Correct 105 ms 21060 KB Output is correct
47 Correct 97 ms 20840 KB Output is correct
48 Correct 92 ms 20840 KB Output is correct
49 Correct 119 ms 20968 KB Output is correct
50 Correct 254 ms 21024 KB Output is correct
51 Correct 100 ms 20840 KB Output is correct
52 Execution timed out 5010 ms 22040 KB Time limit exceeded
53 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 20 ms 14456 KB Output is correct
2 Correct 15 ms 14456 KB Output is correct
3 Correct 15 ms 14456 KB Output is correct
4 Correct 15 ms 14456 KB Output is correct
5 Correct 15 ms 14460 KB Output is correct
6 Correct 16 ms 14456 KB Output is correct
7 Correct 16 ms 14456 KB Output is correct
8 Correct 17 ms 14456 KB Output is correct
9 Correct 18 ms 14584 KB Output is correct
10 Correct 16 ms 14456 KB Output is correct
11 Correct 16 ms 14588 KB Output is correct
12 Correct 16 ms 14584 KB Output is correct
13 Correct 19 ms 14584 KB Output is correct
14 Correct 16 ms 14584 KB Output is correct
15 Correct 16 ms 14584 KB Output is correct
16 Correct 16 ms 14584 KB Output is correct
17 Correct 16 ms 14584 KB Output is correct
18 Correct 17 ms 14584 KB Output is correct
19 Correct 16 ms 14556 KB Output is correct
20 Correct 16 ms 14584 KB Output is correct
21 Correct 16 ms 14584 KB Output is correct
22 Correct 17 ms 14456 KB Output is correct
23 Correct 17 ms 14584 KB Output is correct
24 Correct 16 ms 14456 KB Output is correct
25 Correct 16 ms 14456 KB Output is correct
26 Correct 15 ms 14584 KB Output is correct
27 Correct 15 ms 14456 KB Output is correct
28 Correct 15 ms 14460 KB Output is correct
29 Correct 15 ms 14584 KB Output is correct
30 Correct 15 ms 14428 KB Output is correct
31 Correct 2859 ms 23728 KB Output is correct
32 Correct 122 ms 20064 KB Output is correct
33 Correct 234 ms 21812 KB Output is correct
34 Correct 2314 ms 22096 KB Output is correct
35 Correct 1265 ms 23656 KB Output is correct
36 Correct 272 ms 23604 KB Output is correct
37 Correct 208 ms 21232 KB Output is correct
38 Correct 128 ms 21040 KB Output is correct
39 Correct 116 ms 20840 KB Output is correct
40 Correct 113 ms 20840 KB Output is correct
41 Correct 344 ms 21152 KB Output is correct
42 Correct 453 ms 20968 KB Output is correct
43 Correct 440 ms 23404 KB Output is correct
44 Correct 274 ms 21088 KB Output is correct
45 Correct 151 ms 21092 KB Output is correct
46 Correct 105 ms 21060 KB Output is correct
47 Correct 97 ms 20840 KB Output is correct
48 Correct 92 ms 20840 KB Output is correct
49 Correct 119 ms 20968 KB Output is correct
50 Correct 254 ms 21024 KB Output is correct
51 Correct 100 ms 20840 KB Output is correct
52 Execution timed out 5082 ms 57776 KB Time limit exceeded
53 Halted 0 ms 0 KB -