#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
#define F first
#define S second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define SZ(x) (int)(x).size()
//#define int ll
const int N = 3e5 + 10;
vector<pair<int, int>> add[N], del[N], que[N];
int ans[N];
multiset<int> have[N];
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, k, q;
cin >> n >> k >> q;
vector<int> x(n), type(n), l(n), r(n), interesting;
for (int i = 0; i < n; i++) {
cin >> x[i] >> type[i] >> l[i] >> r[i];
interesting.pb(l[i]);
interesting.pb(r[i]);
type[i]--;
}
vector<int> pos(q), tt(q);
for (int i = 0; i < q; i++) {
cin >> pos[i] >> tt[i];
interesting.pb(tt[i]);
}
sort(all(interesting));
interesting.resize(unique(all(interesting)) - interesting.begin());
for (int i = 0; i < n; i++) {
l[i] = upper_bound(all(interesting), l[i]) - interesting.begin();
r[i] = upper_bound(all(interesting), r[i]) - interesting.begin();
}
for (int i = 0; i < q; i++) {
tt[i] = upper_bound(all(interesting), tt[i]) - interesting.begin();
}
int max_time = SZ(interesting);
for (int i = 0; i < n; i++) {
add[l[i]].pb({x[i], type[i]});
del[r[i]].pb({x[i], type[i]});
}
for (int i = 0; i < q; i++) {
que[tt[i]].pb({pos[i], i});
}
for (int cur_time = 1; cur_time <= max_time; cur_time++) {
for (auto it : add[cur_time]) {
have[it.S].insert(it.F);
}
for (auto it : que[cur_time]) {
for (int i = 0; i < k; i++) {
int rez = 1e9;
auto kek = have[i].upper_bound(it.F);
if (kek != have[i].end()) {
rez = min(rez, *kek - it.F);
}
if (kek != have[i].begin()) {
kek--;
rez = min(rez, it.F - *kek);
}
ans[it.S] = max(ans[it.S], rez);
}
}
for (auto it : del[cur_time]) {
have[it.S].erase(have[it.S].find(it.F));
}
}
for (int i = 0; i < q; i++) {
if (ans[i] == 1e9) {
cout << -1 << '\n';
}
else {
cout << ans[i] << '\n';
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
35584 KB |
Output is correct |
2 |
Correct |
25 ms |
35584 KB |
Output is correct |
3 |
Correct |
25 ms |
35584 KB |
Output is correct |
4 |
Correct |
25 ms |
35616 KB |
Output is correct |
5 |
Correct |
26 ms |
35576 KB |
Output is correct |
6 |
Correct |
26 ms |
35584 KB |
Output is correct |
7 |
Correct |
26 ms |
35584 KB |
Output is correct |
8 |
Correct |
31 ms |
35584 KB |
Output is correct |
9 |
Correct |
27 ms |
35584 KB |
Output is correct |
10 |
Correct |
26 ms |
35584 KB |
Output is correct |
11 |
Correct |
26 ms |
35584 KB |
Output is correct |
12 |
Correct |
29 ms |
35584 KB |
Output is correct |
13 |
Correct |
26 ms |
35584 KB |
Output is correct |
14 |
Correct |
26 ms |
35584 KB |
Output is correct |
15 |
Correct |
26 ms |
35584 KB |
Output is correct |
16 |
Correct |
31 ms |
35584 KB |
Output is correct |
17 |
Correct |
26 ms |
35584 KB |
Output is correct |
18 |
Correct |
31 ms |
35688 KB |
Output is correct |
19 |
Correct |
27 ms |
35584 KB |
Output is correct |
20 |
Correct |
26 ms |
35584 KB |
Output is correct |
21 |
Correct |
26 ms |
35584 KB |
Output is correct |
22 |
Correct |
27 ms |
35712 KB |
Output is correct |
23 |
Correct |
31 ms |
35584 KB |
Output is correct |
24 |
Correct |
32 ms |
35584 KB |
Output is correct |
25 |
Correct |
31 ms |
35704 KB |
Output is correct |
26 |
Correct |
25 ms |
35712 KB |
Output is correct |
27 |
Correct |
26 ms |
35576 KB |
Output is correct |
28 |
Correct |
26 ms |
35584 KB |
Output is correct |
29 |
Correct |
28 ms |
35584 KB |
Output is correct |
30 |
Correct |
25 ms |
35584 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
35584 KB |
Output is correct |
2 |
Correct |
25 ms |
35584 KB |
Output is correct |
3 |
Correct |
25 ms |
35584 KB |
Output is correct |
4 |
Correct |
25 ms |
35616 KB |
Output is correct |
5 |
Correct |
26 ms |
35576 KB |
Output is correct |
6 |
Correct |
26 ms |
35584 KB |
Output is correct |
7 |
Correct |
26 ms |
35584 KB |
Output is correct |
8 |
Correct |
31 ms |
35584 KB |
Output is correct |
9 |
Correct |
27 ms |
35584 KB |
Output is correct |
10 |
Correct |
26 ms |
35584 KB |
Output is correct |
11 |
Correct |
26 ms |
35584 KB |
Output is correct |
12 |
Correct |
29 ms |
35584 KB |
Output is correct |
13 |
Correct |
26 ms |
35584 KB |
Output is correct |
14 |
Correct |
26 ms |
35584 KB |
Output is correct |
15 |
Correct |
26 ms |
35584 KB |
Output is correct |
16 |
Correct |
31 ms |
35584 KB |
Output is correct |
17 |
Correct |
26 ms |
35584 KB |
Output is correct |
18 |
Correct |
31 ms |
35688 KB |
Output is correct |
19 |
Correct |
27 ms |
35584 KB |
Output is correct |
20 |
Correct |
26 ms |
35584 KB |
Output is correct |
21 |
Correct |
26 ms |
35584 KB |
Output is correct |
22 |
Correct |
27 ms |
35712 KB |
Output is correct |
23 |
Correct |
31 ms |
35584 KB |
Output is correct |
24 |
Correct |
32 ms |
35584 KB |
Output is correct |
25 |
Correct |
31 ms |
35704 KB |
Output is correct |
26 |
Correct |
25 ms |
35712 KB |
Output is correct |
27 |
Correct |
26 ms |
35576 KB |
Output is correct |
28 |
Correct |
26 ms |
35584 KB |
Output is correct |
29 |
Correct |
28 ms |
35584 KB |
Output is correct |
30 |
Correct |
25 ms |
35584 KB |
Output is correct |
31 |
Correct |
2254 ms |
47596 KB |
Output is correct |
32 |
Correct |
130 ms |
41712 KB |
Output is correct |
33 |
Correct |
278 ms |
47984 KB |
Output is correct |
34 |
Correct |
1752 ms |
48284 KB |
Output is correct |
35 |
Correct |
1069 ms |
49780 KB |
Output is correct |
36 |
Correct |
347 ms |
49776 KB |
Output is correct |
37 |
Correct |
273 ms |
47088 KB |
Output is correct |
38 |
Correct |
184 ms |
46960 KB |
Output is correct |
39 |
Correct |
178 ms |
46832 KB |
Output is correct |
40 |
Correct |
161 ms |
46832 KB |
Output is correct |
41 |
Correct |
365 ms |
47088 KB |
Output is correct |
42 |
Correct |
452 ms |
46868 KB |
Output is correct |
43 |
Correct |
266 ms |
45032 KB |
Output is correct |
44 |
Correct |
318 ms |
47092 KB |
Output is correct |
45 |
Correct |
212 ms |
46960 KB |
Output is correct |
46 |
Correct |
172 ms |
46960 KB |
Output is correct |
47 |
Correct |
126 ms |
46448 KB |
Output is correct |
48 |
Correct |
163 ms |
46352 KB |
Output is correct |
49 |
Correct |
150 ms |
46540 KB |
Output is correct |
50 |
Correct |
283 ms |
46832 KB |
Output is correct |
51 |
Correct |
135 ms |
46576 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5012 ms |
80772 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
540 ms |
124108 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
35584 KB |
Output is correct |
2 |
Correct |
25 ms |
35584 KB |
Output is correct |
3 |
Correct |
25 ms |
35584 KB |
Output is correct |
4 |
Correct |
25 ms |
35616 KB |
Output is correct |
5 |
Correct |
26 ms |
35576 KB |
Output is correct |
6 |
Correct |
26 ms |
35584 KB |
Output is correct |
7 |
Correct |
26 ms |
35584 KB |
Output is correct |
8 |
Correct |
31 ms |
35584 KB |
Output is correct |
9 |
Correct |
27 ms |
35584 KB |
Output is correct |
10 |
Correct |
26 ms |
35584 KB |
Output is correct |
11 |
Correct |
26 ms |
35584 KB |
Output is correct |
12 |
Correct |
29 ms |
35584 KB |
Output is correct |
13 |
Correct |
26 ms |
35584 KB |
Output is correct |
14 |
Correct |
26 ms |
35584 KB |
Output is correct |
15 |
Correct |
26 ms |
35584 KB |
Output is correct |
16 |
Correct |
31 ms |
35584 KB |
Output is correct |
17 |
Correct |
26 ms |
35584 KB |
Output is correct |
18 |
Correct |
31 ms |
35688 KB |
Output is correct |
19 |
Correct |
27 ms |
35584 KB |
Output is correct |
20 |
Correct |
26 ms |
35584 KB |
Output is correct |
21 |
Correct |
26 ms |
35584 KB |
Output is correct |
22 |
Correct |
27 ms |
35712 KB |
Output is correct |
23 |
Correct |
31 ms |
35584 KB |
Output is correct |
24 |
Correct |
32 ms |
35584 KB |
Output is correct |
25 |
Correct |
31 ms |
35704 KB |
Output is correct |
26 |
Correct |
25 ms |
35712 KB |
Output is correct |
27 |
Correct |
26 ms |
35576 KB |
Output is correct |
28 |
Correct |
26 ms |
35584 KB |
Output is correct |
29 |
Correct |
28 ms |
35584 KB |
Output is correct |
30 |
Correct |
25 ms |
35584 KB |
Output is correct |
31 |
Correct |
2254 ms |
47596 KB |
Output is correct |
32 |
Correct |
130 ms |
41712 KB |
Output is correct |
33 |
Correct |
278 ms |
47984 KB |
Output is correct |
34 |
Correct |
1752 ms |
48284 KB |
Output is correct |
35 |
Correct |
1069 ms |
49780 KB |
Output is correct |
36 |
Correct |
347 ms |
49776 KB |
Output is correct |
37 |
Correct |
273 ms |
47088 KB |
Output is correct |
38 |
Correct |
184 ms |
46960 KB |
Output is correct |
39 |
Correct |
178 ms |
46832 KB |
Output is correct |
40 |
Correct |
161 ms |
46832 KB |
Output is correct |
41 |
Correct |
365 ms |
47088 KB |
Output is correct |
42 |
Correct |
452 ms |
46868 KB |
Output is correct |
43 |
Correct |
266 ms |
45032 KB |
Output is correct |
44 |
Correct |
318 ms |
47092 KB |
Output is correct |
45 |
Correct |
212 ms |
46960 KB |
Output is correct |
46 |
Correct |
172 ms |
46960 KB |
Output is correct |
47 |
Correct |
126 ms |
46448 KB |
Output is correct |
48 |
Correct |
163 ms |
46352 KB |
Output is correct |
49 |
Correct |
150 ms |
46540 KB |
Output is correct |
50 |
Correct |
283 ms |
46832 KB |
Output is correct |
51 |
Correct |
135 ms |
46576 KB |
Output is correct |
52 |
Execution timed out |
5059 ms |
48160 KB |
Time limit exceeded |
53 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
35584 KB |
Output is correct |
2 |
Correct |
25 ms |
35584 KB |
Output is correct |
3 |
Correct |
25 ms |
35584 KB |
Output is correct |
4 |
Correct |
25 ms |
35616 KB |
Output is correct |
5 |
Correct |
26 ms |
35576 KB |
Output is correct |
6 |
Correct |
26 ms |
35584 KB |
Output is correct |
7 |
Correct |
26 ms |
35584 KB |
Output is correct |
8 |
Correct |
31 ms |
35584 KB |
Output is correct |
9 |
Correct |
27 ms |
35584 KB |
Output is correct |
10 |
Correct |
26 ms |
35584 KB |
Output is correct |
11 |
Correct |
26 ms |
35584 KB |
Output is correct |
12 |
Correct |
29 ms |
35584 KB |
Output is correct |
13 |
Correct |
26 ms |
35584 KB |
Output is correct |
14 |
Correct |
26 ms |
35584 KB |
Output is correct |
15 |
Correct |
26 ms |
35584 KB |
Output is correct |
16 |
Correct |
31 ms |
35584 KB |
Output is correct |
17 |
Correct |
26 ms |
35584 KB |
Output is correct |
18 |
Correct |
31 ms |
35688 KB |
Output is correct |
19 |
Correct |
27 ms |
35584 KB |
Output is correct |
20 |
Correct |
26 ms |
35584 KB |
Output is correct |
21 |
Correct |
26 ms |
35584 KB |
Output is correct |
22 |
Correct |
27 ms |
35712 KB |
Output is correct |
23 |
Correct |
31 ms |
35584 KB |
Output is correct |
24 |
Correct |
32 ms |
35584 KB |
Output is correct |
25 |
Correct |
31 ms |
35704 KB |
Output is correct |
26 |
Correct |
25 ms |
35712 KB |
Output is correct |
27 |
Correct |
26 ms |
35576 KB |
Output is correct |
28 |
Correct |
26 ms |
35584 KB |
Output is correct |
29 |
Correct |
28 ms |
35584 KB |
Output is correct |
30 |
Correct |
25 ms |
35584 KB |
Output is correct |
31 |
Correct |
2254 ms |
47596 KB |
Output is correct |
32 |
Correct |
130 ms |
41712 KB |
Output is correct |
33 |
Correct |
278 ms |
47984 KB |
Output is correct |
34 |
Correct |
1752 ms |
48284 KB |
Output is correct |
35 |
Correct |
1069 ms |
49780 KB |
Output is correct |
36 |
Correct |
347 ms |
49776 KB |
Output is correct |
37 |
Correct |
273 ms |
47088 KB |
Output is correct |
38 |
Correct |
184 ms |
46960 KB |
Output is correct |
39 |
Correct |
178 ms |
46832 KB |
Output is correct |
40 |
Correct |
161 ms |
46832 KB |
Output is correct |
41 |
Correct |
365 ms |
47088 KB |
Output is correct |
42 |
Correct |
452 ms |
46868 KB |
Output is correct |
43 |
Correct |
266 ms |
45032 KB |
Output is correct |
44 |
Correct |
318 ms |
47092 KB |
Output is correct |
45 |
Correct |
212 ms |
46960 KB |
Output is correct |
46 |
Correct |
172 ms |
46960 KB |
Output is correct |
47 |
Correct |
126 ms |
46448 KB |
Output is correct |
48 |
Correct |
163 ms |
46352 KB |
Output is correct |
49 |
Correct |
150 ms |
46540 KB |
Output is correct |
50 |
Correct |
283 ms |
46832 KB |
Output is correct |
51 |
Correct |
135 ms |
46576 KB |
Output is correct |
52 |
Execution timed out |
5012 ms |
80772 KB |
Time limit exceeded |
53 |
Halted |
0 ms |
0 KB |
- |