#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 3e5 + 10, inf = 1e9;
struct store
{
int x, t, a, b;
}s[maxn];
struct query
{
int l, y, idx;
}task[maxn];
int n, k, q;
void input()
{
cin >> n >> k >> q;
for (int i = 1; i <= n; i ++)
cin >> s[i].x >> s[i].t >> s[i].a >> s[i].b;
for (int i = 1; i <= q; i ++)
cin >> task[i].l >> task[i].y, task[i].idx = i;
}
int type[maxn];
int solve_naive(int pivot, int year)
{
for (int i = 1; i <= k; i ++)
type[i] = inf;
for (int i = 1; i <= n; i ++)
{
if (s[i].a <= year && s[i].b >= year)
type[s[i].t] = min(type[s[i].t], abs(pivot - s[i].x));
}
int ans = -1;
for (int i = 1; i <= k; i ++)
{
if (type[i] == inf)
return -1;
ans = max(ans, type[i]);
}
return ans;
}
bool cmp_query(query t1, query t2)
{
return t1.y < t2.y;
}
struct event
{
int type, cor, add, arrive;
event(int _type, int _cor, int _add, int _arrive)
{
type = _type;
cor = _cor;
add = _add;
arrive = _arrive;
}
};
bool cmp_event(event e1, event e2)
{
if (e1.arrive != e2.arrive)
return e1.arrive < e2.arrive;
if (e1.add != e2.add)
return e1.add < e2.add;
return e1.cor < e2.cor; /// could have dublicates
}
multiset < int > act[maxn];
void add_event(int type, int cor)
{
act[type].insert(cor);
}
void remove_event(int type, int cor)
{
act[type].erase(act[type].find(cor));
}
int ans[maxn];
int single_query(int cor)
{
int far = 0;
for (int i = 1; i <= k; i ++)
{
if (act[i].empty())
return -1;
multiset < int > :: iterator it = act[i].upper_bound(cor);
int closest = inf;
///if (it != act[i].end())
///cout << "here " << cor << " " << *it << endl;
if (it != act[i].end())
closest = min(closest, *it - cor);
if (it != act[i].begin())
closest = min(closest, cor - *prev(it));
far = max(far, closest);
///cout << far << endl;
}
return far;
}
void answer_queries()
{
sort(task + 1, task + q + 1, cmp_query);
vector < event > events;
for (int i = 1; i <= n; i ++)
{
events.push_back(event(s[i].t, s[i].x, 1, s[i].a));
events.push_back(event(s[i].t, s[i].x, -1, s[i].b + 1));
}
sort(events.begin(), events.end(), cmp_event);
int pt = 1;
for (event cur : events)
{
while(pt <= q && task[pt].y < cur.arrive)
{
ans[task[pt].idx] = single_query(task[pt].l);
pt ++;
}
if (cur.add == 1)
add_event(cur.type, cur.cor);
else
remove_event(cur.type, cur.cor);
}
while(pt <= q)
{
ans[task[pt].idx] = single_query(task[pt].l);
pt ++;
}
for (int i = 1; i <= q; i ++)
cout << ans[i] << endl;
}
void solve()
{
input();
answer_queries();
}
int main()
{
solve();
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 |
3 ms |
18780 KB |
Output is correct |
2 |
Correct |
3 ms |
18780 KB |
Output is correct |
3 |
Correct |
3 ms |
18780 KB |
Output is correct |
4 |
Correct |
3 ms |
18892 KB |
Output is correct |
5 |
Correct |
4 ms |
18776 KB |
Output is correct |
6 |
Correct |
5 ms |
18936 KB |
Output is correct |
7 |
Correct |
5 ms |
18776 KB |
Output is correct |
8 |
Correct |
5 ms |
18780 KB |
Output is correct |
9 |
Correct |
5 ms |
18776 KB |
Output is correct |
10 |
Correct |
5 ms |
18956 KB |
Output is correct |
11 |
Correct |
5 ms |
18932 KB |
Output is correct |
12 |
Correct |
5 ms |
18780 KB |
Output is correct |
13 |
Correct |
5 ms |
18776 KB |
Output is correct |
14 |
Correct |
6 ms |
18780 KB |
Output is correct |
15 |
Correct |
4 ms |
18780 KB |
Output is correct |
16 |
Correct |
5 ms |
18928 KB |
Output is correct |
17 |
Correct |
5 ms |
18780 KB |
Output is correct |
18 |
Correct |
5 ms |
18964 KB |
Output is correct |
19 |
Correct |
5 ms |
18780 KB |
Output is correct |
20 |
Correct |
4 ms |
18780 KB |
Output is correct |
21 |
Correct |
5 ms |
18780 KB |
Output is correct |
22 |
Correct |
6 ms |
19036 KB |
Output is correct |
23 |
Correct |
5 ms |
18780 KB |
Output is correct |
24 |
Correct |
5 ms |
18780 KB |
Output is correct |
25 |
Correct |
4 ms |
18780 KB |
Output is correct |
26 |
Correct |
4 ms |
18780 KB |
Output is correct |
27 |
Correct |
5 ms |
18780 KB |
Output is correct |
28 |
Correct |
5 ms |
18776 KB |
Output is correct |
29 |
Correct |
4 ms |
18892 KB |
Output is correct |
30 |
Correct |
4 ms |
18924 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
18780 KB |
Output is correct |
2 |
Correct |
3 ms |
18780 KB |
Output is correct |
3 |
Correct |
3 ms |
18780 KB |
Output is correct |
4 |
Correct |
3 ms |
18892 KB |
Output is correct |
5 |
Correct |
4 ms |
18776 KB |
Output is correct |
6 |
Correct |
5 ms |
18936 KB |
Output is correct |
7 |
Correct |
5 ms |
18776 KB |
Output is correct |
8 |
Correct |
5 ms |
18780 KB |
Output is correct |
9 |
Correct |
5 ms |
18776 KB |
Output is correct |
10 |
Correct |
5 ms |
18956 KB |
Output is correct |
11 |
Correct |
5 ms |
18932 KB |
Output is correct |
12 |
Correct |
5 ms |
18780 KB |
Output is correct |
13 |
Correct |
5 ms |
18776 KB |
Output is correct |
14 |
Correct |
6 ms |
18780 KB |
Output is correct |
15 |
Correct |
4 ms |
18780 KB |
Output is correct |
16 |
Correct |
5 ms |
18928 KB |
Output is correct |
17 |
Correct |
5 ms |
18780 KB |
Output is correct |
18 |
Correct |
5 ms |
18964 KB |
Output is correct |
19 |
Correct |
5 ms |
18780 KB |
Output is correct |
20 |
Correct |
4 ms |
18780 KB |
Output is correct |
21 |
Correct |
5 ms |
18780 KB |
Output is correct |
22 |
Correct |
6 ms |
19036 KB |
Output is correct |
23 |
Correct |
5 ms |
18780 KB |
Output is correct |
24 |
Correct |
5 ms |
18780 KB |
Output is correct |
25 |
Correct |
4 ms |
18780 KB |
Output is correct |
26 |
Correct |
4 ms |
18780 KB |
Output is correct |
27 |
Correct |
5 ms |
18780 KB |
Output is correct |
28 |
Correct |
5 ms |
18776 KB |
Output is correct |
29 |
Correct |
4 ms |
18892 KB |
Output is correct |
30 |
Correct |
4 ms |
18924 KB |
Output is correct |
31 |
Correct |
1606 ms |
31360 KB |
Output is correct |
32 |
Correct |
160 ms |
27232 KB |
Output is correct |
33 |
Correct |
246 ms |
29120 KB |
Output is correct |
34 |
Correct |
1272 ms |
29356 KB |
Output is correct |
35 |
Correct |
801 ms |
31196 KB |
Output is correct |
36 |
Correct |
268 ms |
30912 KB |
Output is correct |
37 |
Correct |
240 ms |
28868 KB |
Output is correct |
38 |
Correct |
194 ms |
28352 KB |
Output is correct |
39 |
Correct |
187 ms |
28372 KB |
Output is correct |
40 |
Correct |
191 ms |
28232 KB |
Output is correct |
41 |
Correct |
347 ms |
28480 KB |
Output is correct |
42 |
Correct |
275 ms |
28476 KB |
Output is correct |
43 |
Correct |
336 ms |
30716 KB |
Output is correct |
44 |
Correct |
290 ms |
28604 KB |
Output is correct |
45 |
Correct |
216 ms |
28608 KB |
Output is correct |
46 |
Correct |
179 ms |
28332 KB |
Output is correct |
47 |
Correct |
173 ms |
28332 KB |
Output is correct |
48 |
Correct |
168 ms |
28096 KB |
Output is correct |
49 |
Correct |
182 ms |
28096 KB |
Output is correct |
50 |
Correct |
260 ms |
28348 KB |
Output is correct |
51 |
Correct |
190 ms |
28092 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5007 ms |
50056 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5075 ms |
50084 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
18780 KB |
Output is correct |
2 |
Correct |
3 ms |
18780 KB |
Output is correct |
3 |
Correct |
3 ms |
18780 KB |
Output is correct |
4 |
Correct |
3 ms |
18892 KB |
Output is correct |
5 |
Correct |
4 ms |
18776 KB |
Output is correct |
6 |
Correct |
5 ms |
18936 KB |
Output is correct |
7 |
Correct |
5 ms |
18776 KB |
Output is correct |
8 |
Correct |
5 ms |
18780 KB |
Output is correct |
9 |
Correct |
5 ms |
18776 KB |
Output is correct |
10 |
Correct |
5 ms |
18956 KB |
Output is correct |
11 |
Correct |
5 ms |
18932 KB |
Output is correct |
12 |
Correct |
5 ms |
18780 KB |
Output is correct |
13 |
Correct |
5 ms |
18776 KB |
Output is correct |
14 |
Correct |
6 ms |
18780 KB |
Output is correct |
15 |
Correct |
4 ms |
18780 KB |
Output is correct |
16 |
Correct |
5 ms |
18928 KB |
Output is correct |
17 |
Correct |
5 ms |
18780 KB |
Output is correct |
18 |
Correct |
5 ms |
18964 KB |
Output is correct |
19 |
Correct |
5 ms |
18780 KB |
Output is correct |
20 |
Correct |
4 ms |
18780 KB |
Output is correct |
21 |
Correct |
5 ms |
18780 KB |
Output is correct |
22 |
Correct |
6 ms |
19036 KB |
Output is correct |
23 |
Correct |
5 ms |
18780 KB |
Output is correct |
24 |
Correct |
5 ms |
18780 KB |
Output is correct |
25 |
Correct |
4 ms |
18780 KB |
Output is correct |
26 |
Correct |
4 ms |
18780 KB |
Output is correct |
27 |
Correct |
5 ms |
18780 KB |
Output is correct |
28 |
Correct |
5 ms |
18776 KB |
Output is correct |
29 |
Correct |
4 ms |
18892 KB |
Output is correct |
30 |
Correct |
4 ms |
18924 KB |
Output is correct |
31 |
Correct |
1606 ms |
31360 KB |
Output is correct |
32 |
Correct |
160 ms |
27232 KB |
Output is correct |
33 |
Correct |
246 ms |
29120 KB |
Output is correct |
34 |
Correct |
1272 ms |
29356 KB |
Output is correct |
35 |
Correct |
801 ms |
31196 KB |
Output is correct |
36 |
Correct |
268 ms |
30912 KB |
Output is correct |
37 |
Correct |
240 ms |
28868 KB |
Output is correct |
38 |
Correct |
194 ms |
28352 KB |
Output is correct |
39 |
Correct |
187 ms |
28372 KB |
Output is correct |
40 |
Correct |
191 ms |
28232 KB |
Output is correct |
41 |
Correct |
347 ms |
28480 KB |
Output is correct |
42 |
Correct |
275 ms |
28476 KB |
Output is correct |
43 |
Correct |
336 ms |
30716 KB |
Output is correct |
44 |
Correct |
290 ms |
28604 KB |
Output is correct |
45 |
Correct |
216 ms |
28608 KB |
Output is correct |
46 |
Correct |
179 ms |
28332 KB |
Output is correct |
47 |
Correct |
173 ms |
28332 KB |
Output is correct |
48 |
Correct |
168 ms |
28096 KB |
Output is correct |
49 |
Correct |
182 ms |
28096 KB |
Output is correct |
50 |
Correct |
260 ms |
28348 KB |
Output is correct |
51 |
Correct |
190 ms |
28092 KB |
Output is correct |
52 |
Correct |
190 ms |
30912 KB |
Output is correct |
53 |
Correct |
182 ms |
29120 KB |
Output is correct |
54 |
Correct |
223 ms |
30908 KB |
Output is correct |
55 |
Execution timed out |
5026 ms |
28864 KB |
Time limit exceeded |
56 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
18780 KB |
Output is correct |
2 |
Correct |
3 ms |
18780 KB |
Output is correct |
3 |
Correct |
3 ms |
18780 KB |
Output is correct |
4 |
Correct |
3 ms |
18892 KB |
Output is correct |
5 |
Correct |
4 ms |
18776 KB |
Output is correct |
6 |
Correct |
5 ms |
18936 KB |
Output is correct |
7 |
Correct |
5 ms |
18776 KB |
Output is correct |
8 |
Correct |
5 ms |
18780 KB |
Output is correct |
9 |
Correct |
5 ms |
18776 KB |
Output is correct |
10 |
Correct |
5 ms |
18956 KB |
Output is correct |
11 |
Correct |
5 ms |
18932 KB |
Output is correct |
12 |
Correct |
5 ms |
18780 KB |
Output is correct |
13 |
Correct |
5 ms |
18776 KB |
Output is correct |
14 |
Correct |
6 ms |
18780 KB |
Output is correct |
15 |
Correct |
4 ms |
18780 KB |
Output is correct |
16 |
Correct |
5 ms |
18928 KB |
Output is correct |
17 |
Correct |
5 ms |
18780 KB |
Output is correct |
18 |
Correct |
5 ms |
18964 KB |
Output is correct |
19 |
Correct |
5 ms |
18780 KB |
Output is correct |
20 |
Correct |
4 ms |
18780 KB |
Output is correct |
21 |
Correct |
5 ms |
18780 KB |
Output is correct |
22 |
Correct |
6 ms |
19036 KB |
Output is correct |
23 |
Correct |
5 ms |
18780 KB |
Output is correct |
24 |
Correct |
5 ms |
18780 KB |
Output is correct |
25 |
Correct |
4 ms |
18780 KB |
Output is correct |
26 |
Correct |
4 ms |
18780 KB |
Output is correct |
27 |
Correct |
5 ms |
18780 KB |
Output is correct |
28 |
Correct |
5 ms |
18776 KB |
Output is correct |
29 |
Correct |
4 ms |
18892 KB |
Output is correct |
30 |
Correct |
4 ms |
18924 KB |
Output is correct |
31 |
Correct |
1606 ms |
31360 KB |
Output is correct |
32 |
Correct |
160 ms |
27232 KB |
Output is correct |
33 |
Correct |
246 ms |
29120 KB |
Output is correct |
34 |
Correct |
1272 ms |
29356 KB |
Output is correct |
35 |
Correct |
801 ms |
31196 KB |
Output is correct |
36 |
Correct |
268 ms |
30912 KB |
Output is correct |
37 |
Correct |
240 ms |
28868 KB |
Output is correct |
38 |
Correct |
194 ms |
28352 KB |
Output is correct |
39 |
Correct |
187 ms |
28372 KB |
Output is correct |
40 |
Correct |
191 ms |
28232 KB |
Output is correct |
41 |
Correct |
347 ms |
28480 KB |
Output is correct |
42 |
Correct |
275 ms |
28476 KB |
Output is correct |
43 |
Correct |
336 ms |
30716 KB |
Output is correct |
44 |
Correct |
290 ms |
28604 KB |
Output is correct |
45 |
Correct |
216 ms |
28608 KB |
Output is correct |
46 |
Correct |
179 ms |
28332 KB |
Output is correct |
47 |
Correct |
173 ms |
28332 KB |
Output is correct |
48 |
Correct |
168 ms |
28096 KB |
Output is correct |
49 |
Correct |
182 ms |
28096 KB |
Output is correct |
50 |
Correct |
260 ms |
28348 KB |
Output is correct |
51 |
Correct |
190 ms |
28092 KB |
Output is correct |
52 |
Execution timed out |
5007 ms |
50056 KB |
Time limit exceeded |
53 |
Halted |
0 ms |
0 KB |
- |