# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
77334 |
2018-09-25T19:53:00 Z |
298iq |
New Home (APIO18_new_home) |
C++14 |
|
5000 ms |
996976 KB |
#include <bits/stdc++.h>
using namespace std;
const int MEM = 10e8;
char mem[MEM];
int ptr = 0;
void* operator new(size_t n) {
ptr += n;
return mem + (ptr - n);
}
void operator delete(void *) {}
const int INF = 1e9 + 7;
const int MAXV = 1e8 + 7;
namespace DD {
struct Node {
multiset <int> ms;
Node *l, *r;
Node() {
ms = {};
l = r = NULL;
}
};
void push(Node *t) {
if (!t->l) t->l = new Node();
if (!t->r) t->r = new Node();
}
void add(Node *t, int tl, int tr, int p, int x) {
t->ms.insert(x);
if (tl == tr) return;
int tm = tl + (tr - tl) / 2;
push(t);
if (p <= tm) add(t->l, tl, tm, p, x);
else add(t->r, tm + 1, tr, p, x);
}
void del(Node *t, int tl, int tr, int p, int x) {
t->ms.erase(t->ms.find(x));
if (tl == tr) return;
int tm = tl + (tr - tl) / 2;
if (p <= tm) del(t->l, tl, tm, p, x);
else del(t->r, tm + 1, tr, p, x);
}
bool get(Node *t, int tl, int tr, int l, int r, int x) {
if (tr < l || r < tl) return 0;
if (l <= tl && tr <= r) return (t->ms.size() && *t->ms.rbegin() >= x);
int tm = tl + (tr - tl) / 2;
push(t);
return get(t->l, tl, tm, l, r, x) || get(t->r, tm + 1, tr, l, r, x);
}
};
const int MAXN = 3e5 + 7;
int n, k, q;
int p[MAXN], c[MAXN], l[MAXN], r[MAXN];
int p2[MAXN], t2[MAXN];
void read() {
cin >> n >> k >> q;
for (int i = 0; i < n; ++i) {
cin >> p[i] >> c[i] >> l[i] >> r[i];
--c[i];
}
for (int i = 0; i < q; ++i) {
cin >> p2[i] >> t2[i];
}
}
struct Event {
bool type;
int t, i;
Event(bool type_, int t_, int i_) {
type = type_; t = t_; i = i_;
}
Event(){}
};
bool comp(Event a, Event b) {
return a.t < b.t;
}
int ans[MAXN];
int qper[MAXN];
bool comp1(int i, int j) {
return t2[i] < t2[j];
}
using namespace DD;
Node *dd = new Node;
multiset <int> ps[MAXN];
void add(int c, int p, int num) {
auto r = ps[c].lower_bound(p);
auto l = r; --l;
del(dd, -INF, INF, *l, *r);
add(dd, -INF, INF, *l, p);
add(dd, -INF, INF, p, *r);
ps[c].insert(p);
}
void del(int c, int p, int num) {
auto it = ps[c].lower_bound(p);
auto l = it; --l;
auto r = it; ++r;
del(dd, -INF, INF, *l, p);
del(dd, -INF, INF, p, *r);
add(dd, -INF, INF, *l, *r);
ps[c].erase(it);
}
void upd(Event e) {
if (e.type) {
add(c[e.i], p[e.i], e.i);
}
else {
del(c[e.i], p[e.i], e.i);
}
}
bool check(int l, int r) {
l = max(l, 1);
r = min(r, MAXV);
--l; ++r;
return !get(dd, -INF, INF, -INF, l, r);
}
int get(int p) {
if (!check(1, MAXV)) return -1;
int l = -1;
int r = MAXV;
while (l < r - 1) {
int m = (l + r) / 2;
if (!check(p - m, p + m)) l = m;
else r = m;
}
return r;
}
void solve() {
vector <Event> v;
for (int i = 0; i < n; ++i) {
v.push_back(Event(1, l[i], i));
v.push_back(Event(0, r[i] + 1, i));
}
sort(v.begin(), v.end(), comp);
for (int i = 0; i < q; ++i) qper[i] = i;
sort(qper, qper + q, comp1);
for (int i = 0; i < k; ++i) {
ps[i].insert(-INF);
ps[i].insert(INF);
add(dd, -INF, INF, -INF, INF);
}
int u = 0;
for (int i = 0; i < q; ++i) {
while (u < (int)v.size() && v[u].t <= t2[qper[i]]) {
upd(v[u]);
++u;
}
ans[qper[i]] = get(p2[qper[i]]);
}
}
void print() {
for (int i = 0; i < q; ++i) {
cout << ans[i] << '\n';
}
}
signed main() {
//freopen("input.txt", "r", stdin);
ios_base::sync_with_stdio(0);
cin.tie(0);
read();
solve();
print();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
14584 KB |
Output is correct |
2 |
Correct |
13 ms |
14584 KB |
Output is correct |
3 |
Correct |
14 ms |
14620 KB |
Output is correct |
4 |
Correct |
17 ms |
15080 KB |
Output is correct |
5 |
Correct |
20 ms |
16060 KB |
Output is correct |
6 |
Correct |
27 ms |
21824 KB |
Output is correct |
7 |
Correct |
29 ms |
21824 KB |
Output is correct |
8 |
Correct |
22 ms |
21824 KB |
Output is correct |
9 |
Correct |
24 ms |
21824 KB |
Output is correct |
10 |
Correct |
28 ms |
22212 KB |
Output is correct |
11 |
Correct |
19 ms |
22212 KB |
Output is correct |
12 |
Correct |
27 ms |
23156 KB |
Output is correct |
13 |
Correct |
19 ms |
23156 KB |
Output is correct |
14 |
Correct |
21 ms |
23156 KB |
Output is correct |
15 |
Correct |
25 ms |
23156 KB |
Output is correct |
16 |
Correct |
26 ms |
23156 KB |
Output is correct |
17 |
Correct |
27 ms |
23156 KB |
Output is correct |
18 |
Correct |
24 ms |
23156 KB |
Output is correct |
19 |
Correct |
25 ms |
23156 KB |
Output is correct |
20 |
Correct |
27 ms |
23156 KB |
Output is correct |
21 |
Correct |
21 ms |
23156 KB |
Output is correct |
22 |
Correct |
24 ms |
23156 KB |
Output is correct |
23 |
Correct |
24 ms |
23156 KB |
Output is correct |
24 |
Correct |
24 ms |
23156 KB |
Output is correct |
25 |
Correct |
24 ms |
23156 KB |
Output is correct |
26 |
Correct |
26 ms |
23156 KB |
Output is correct |
27 |
Correct |
20 ms |
23156 KB |
Output is correct |
28 |
Correct |
27 ms |
23156 KB |
Output is correct |
29 |
Correct |
22 ms |
23156 KB |
Output is correct |
30 |
Correct |
25 ms |
23156 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
14584 KB |
Output is correct |
2 |
Correct |
13 ms |
14584 KB |
Output is correct |
3 |
Correct |
14 ms |
14620 KB |
Output is correct |
4 |
Correct |
17 ms |
15080 KB |
Output is correct |
5 |
Correct |
20 ms |
16060 KB |
Output is correct |
6 |
Correct |
27 ms |
21824 KB |
Output is correct |
7 |
Correct |
29 ms |
21824 KB |
Output is correct |
8 |
Correct |
22 ms |
21824 KB |
Output is correct |
9 |
Correct |
24 ms |
21824 KB |
Output is correct |
10 |
Correct |
28 ms |
22212 KB |
Output is correct |
11 |
Correct |
19 ms |
22212 KB |
Output is correct |
12 |
Correct |
27 ms |
23156 KB |
Output is correct |
13 |
Correct |
19 ms |
23156 KB |
Output is correct |
14 |
Correct |
21 ms |
23156 KB |
Output is correct |
15 |
Correct |
25 ms |
23156 KB |
Output is correct |
16 |
Correct |
26 ms |
23156 KB |
Output is correct |
17 |
Correct |
27 ms |
23156 KB |
Output is correct |
18 |
Correct |
24 ms |
23156 KB |
Output is correct |
19 |
Correct |
25 ms |
23156 KB |
Output is correct |
20 |
Correct |
27 ms |
23156 KB |
Output is correct |
21 |
Correct |
21 ms |
23156 KB |
Output is correct |
22 |
Correct |
24 ms |
23156 KB |
Output is correct |
23 |
Correct |
24 ms |
23156 KB |
Output is correct |
24 |
Correct |
24 ms |
23156 KB |
Output is correct |
25 |
Correct |
24 ms |
23156 KB |
Output is correct |
26 |
Correct |
26 ms |
23156 KB |
Output is correct |
27 |
Correct |
20 ms |
23156 KB |
Output is correct |
28 |
Correct |
27 ms |
23156 KB |
Output is correct |
29 |
Correct |
22 ms |
23156 KB |
Output is correct |
30 |
Correct |
25 ms |
23156 KB |
Output is correct |
31 |
Correct |
4964 ms |
761100 KB |
Output is correct |
32 |
Correct |
2917 ms |
761100 KB |
Output is correct |
33 |
Correct |
4264 ms |
940784 KB |
Output is correct |
34 |
Correct |
4229 ms |
940784 KB |
Output is correct |
35 |
Correct |
4859 ms |
940784 KB |
Output is correct |
36 |
Correct |
4809 ms |
957540 KB |
Output is correct |
37 |
Correct |
3403 ms |
957540 KB |
Output is correct |
38 |
Correct |
3535 ms |
996976 KB |
Output is correct |
39 |
Correct |
2674 ms |
996976 KB |
Output is correct |
40 |
Correct |
2770 ms |
996976 KB |
Output is correct |
41 |
Correct |
1771 ms |
996976 KB |
Output is correct |
42 |
Correct |
1654 ms |
996976 KB |
Output is correct |
43 |
Correct |
1103 ms |
996976 KB |
Output is correct |
44 |
Correct |
1782 ms |
996976 KB |
Output is correct |
45 |
Correct |
1715 ms |
996976 KB |
Output is correct |
46 |
Correct |
1721 ms |
996976 KB |
Output is correct |
47 |
Correct |
1485 ms |
996976 KB |
Output is correct |
48 |
Correct |
1680 ms |
996976 KB |
Output is correct |
49 |
Correct |
1795 ms |
996976 KB |
Output is correct |
50 |
Correct |
1944 ms |
996976 KB |
Output is correct |
51 |
Correct |
1759 ms |
996976 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5048 ms |
996976 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5050 ms |
996976 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
14584 KB |
Output is correct |
2 |
Correct |
13 ms |
14584 KB |
Output is correct |
3 |
Correct |
14 ms |
14620 KB |
Output is correct |
4 |
Correct |
17 ms |
15080 KB |
Output is correct |
5 |
Correct |
20 ms |
16060 KB |
Output is correct |
6 |
Correct |
27 ms |
21824 KB |
Output is correct |
7 |
Correct |
29 ms |
21824 KB |
Output is correct |
8 |
Correct |
22 ms |
21824 KB |
Output is correct |
9 |
Correct |
24 ms |
21824 KB |
Output is correct |
10 |
Correct |
28 ms |
22212 KB |
Output is correct |
11 |
Correct |
19 ms |
22212 KB |
Output is correct |
12 |
Correct |
27 ms |
23156 KB |
Output is correct |
13 |
Correct |
19 ms |
23156 KB |
Output is correct |
14 |
Correct |
21 ms |
23156 KB |
Output is correct |
15 |
Correct |
25 ms |
23156 KB |
Output is correct |
16 |
Correct |
26 ms |
23156 KB |
Output is correct |
17 |
Correct |
27 ms |
23156 KB |
Output is correct |
18 |
Correct |
24 ms |
23156 KB |
Output is correct |
19 |
Correct |
25 ms |
23156 KB |
Output is correct |
20 |
Correct |
27 ms |
23156 KB |
Output is correct |
21 |
Correct |
21 ms |
23156 KB |
Output is correct |
22 |
Correct |
24 ms |
23156 KB |
Output is correct |
23 |
Correct |
24 ms |
23156 KB |
Output is correct |
24 |
Correct |
24 ms |
23156 KB |
Output is correct |
25 |
Correct |
24 ms |
23156 KB |
Output is correct |
26 |
Correct |
26 ms |
23156 KB |
Output is correct |
27 |
Correct |
20 ms |
23156 KB |
Output is correct |
28 |
Correct |
27 ms |
23156 KB |
Output is correct |
29 |
Correct |
22 ms |
23156 KB |
Output is correct |
30 |
Correct |
25 ms |
23156 KB |
Output is correct |
31 |
Correct |
4964 ms |
761100 KB |
Output is correct |
32 |
Correct |
2917 ms |
761100 KB |
Output is correct |
33 |
Correct |
4264 ms |
940784 KB |
Output is correct |
34 |
Correct |
4229 ms |
940784 KB |
Output is correct |
35 |
Correct |
4859 ms |
940784 KB |
Output is correct |
36 |
Correct |
4809 ms |
957540 KB |
Output is correct |
37 |
Correct |
3403 ms |
957540 KB |
Output is correct |
38 |
Correct |
3535 ms |
996976 KB |
Output is correct |
39 |
Correct |
2674 ms |
996976 KB |
Output is correct |
40 |
Correct |
2770 ms |
996976 KB |
Output is correct |
41 |
Correct |
1771 ms |
996976 KB |
Output is correct |
42 |
Correct |
1654 ms |
996976 KB |
Output is correct |
43 |
Correct |
1103 ms |
996976 KB |
Output is correct |
44 |
Correct |
1782 ms |
996976 KB |
Output is correct |
45 |
Correct |
1715 ms |
996976 KB |
Output is correct |
46 |
Correct |
1721 ms |
996976 KB |
Output is correct |
47 |
Correct |
1485 ms |
996976 KB |
Output is correct |
48 |
Correct |
1680 ms |
996976 KB |
Output is correct |
49 |
Correct |
1795 ms |
996976 KB |
Output is correct |
50 |
Correct |
1944 ms |
996976 KB |
Output is correct |
51 |
Correct |
1759 ms |
996976 KB |
Output is correct |
52 |
Correct |
4540 ms |
996976 KB |
Output is correct |
53 |
Correct |
4173 ms |
996976 KB |
Output is correct |
54 |
Correct |
4705 ms |
996976 KB |
Output is correct |
55 |
Correct |
3485 ms |
996976 KB |
Output is correct |
56 |
Correct |
3999 ms |
996976 KB |
Output is correct |
57 |
Correct |
2636 ms |
996976 KB |
Output is correct |
58 |
Correct |
3079 ms |
996976 KB |
Output is correct |
59 |
Correct |
3312 ms |
996976 KB |
Output is correct |
60 |
Correct |
2428 ms |
996976 KB |
Output is correct |
61 |
Correct |
2141 ms |
996976 KB |
Output is correct |
62 |
Correct |
4203 ms |
996976 KB |
Output is correct |
63 |
Correct |
4453 ms |
996976 KB |
Output is correct |
64 |
Correct |
4395 ms |
996976 KB |
Output is correct |
65 |
Correct |
3573 ms |
996976 KB |
Output is correct |
66 |
Correct |
2163 ms |
996976 KB |
Output is correct |
67 |
Correct |
3983 ms |
996976 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
14584 KB |
Output is correct |
2 |
Correct |
13 ms |
14584 KB |
Output is correct |
3 |
Correct |
14 ms |
14620 KB |
Output is correct |
4 |
Correct |
17 ms |
15080 KB |
Output is correct |
5 |
Correct |
20 ms |
16060 KB |
Output is correct |
6 |
Correct |
27 ms |
21824 KB |
Output is correct |
7 |
Correct |
29 ms |
21824 KB |
Output is correct |
8 |
Correct |
22 ms |
21824 KB |
Output is correct |
9 |
Correct |
24 ms |
21824 KB |
Output is correct |
10 |
Correct |
28 ms |
22212 KB |
Output is correct |
11 |
Correct |
19 ms |
22212 KB |
Output is correct |
12 |
Correct |
27 ms |
23156 KB |
Output is correct |
13 |
Correct |
19 ms |
23156 KB |
Output is correct |
14 |
Correct |
21 ms |
23156 KB |
Output is correct |
15 |
Correct |
25 ms |
23156 KB |
Output is correct |
16 |
Correct |
26 ms |
23156 KB |
Output is correct |
17 |
Correct |
27 ms |
23156 KB |
Output is correct |
18 |
Correct |
24 ms |
23156 KB |
Output is correct |
19 |
Correct |
25 ms |
23156 KB |
Output is correct |
20 |
Correct |
27 ms |
23156 KB |
Output is correct |
21 |
Correct |
21 ms |
23156 KB |
Output is correct |
22 |
Correct |
24 ms |
23156 KB |
Output is correct |
23 |
Correct |
24 ms |
23156 KB |
Output is correct |
24 |
Correct |
24 ms |
23156 KB |
Output is correct |
25 |
Correct |
24 ms |
23156 KB |
Output is correct |
26 |
Correct |
26 ms |
23156 KB |
Output is correct |
27 |
Correct |
20 ms |
23156 KB |
Output is correct |
28 |
Correct |
27 ms |
23156 KB |
Output is correct |
29 |
Correct |
22 ms |
23156 KB |
Output is correct |
30 |
Correct |
25 ms |
23156 KB |
Output is correct |
31 |
Correct |
4964 ms |
761100 KB |
Output is correct |
32 |
Correct |
2917 ms |
761100 KB |
Output is correct |
33 |
Correct |
4264 ms |
940784 KB |
Output is correct |
34 |
Correct |
4229 ms |
940784 KB |
Output is correct |
35 |
Correct |
4859 ms |
940784 KB |
Output is correct |
36 |
Correct |
4809 ms |
957540 KB |
Output is correct |
37 |
Correct |
3403 ms |
957540 KB |
Output is correct |
38 |
Correct |
3535 ms |
996976 KB |
Output is correct |
39 |
Correct |
2674 ms |
996976 KB |
Output is correct |
40 |
Correct |
2770 ms |
996976 KB |
Output is correct |
41 |
Correct |
1771 ms |
996976 KB |
Output is correct |
42 |
Correct |
1654 ms |
996976 KB |
Output is correct |
43 |
Correct |
1103 ms |
996976 KB |
Output is correct |
44 |
Correct |
1782 ms |
996976 KB |
Output is correct |
45 |
Correct |
1715 ms |
996976 KB |
Output is correct |
46 |
Correct |
1721 ms |
996976 KB |
Output is correct |
47 |
Correct |
1485 ms |
996976 KB |
Output is correct |
48 |
Correct |
1680 ms |
996976 KB |
Output is correct |
49 |
Correct |
1795 ms |
996976 KB |
Output is correct |
50 |
Correct |
1944 ms |
996976 KB |
Output is correct |
51 |
Correct |
1759 ms |
996976 KB |
Output is correct |
52 |
Execution timed out |
5048 ms |
996976 KB |
Time limit exceeded |
53 |
Halted |
0 ms |
0 KB |
- |