#pragma GCC optimize("O1,O2,O3,Ofast,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
const char nl = '\n';
void fastIO() {
ios::sync_with_stdio(false);
cin.tie(0);
}
int main() {
fastIO();
int N, K, Q;
cin>>N>>K>>Q;
// stores of each type
vector<pair<int, ii>> stores[K];
// {pos, {start, end}}
// keep track of all openings / closings
vector<pair<ii, ii>> actions;
// {time, type}, {store type, pos}}
// type = 0 if open, 1 if close
for (int i = 0; i < N; i++) {
int x, y, a, b;
cin>>x>>y>>a>>b;
x--; y--;
stores[y].pb({x, {a, b}});
actions.pb({{a, 0}, {y, x}}); // store open
actions.pb({{b + 1, 1}, {y, x}}); // store close
}
vector<pair<ii, int>> queries;
// {{time, type}, {pos, id}}
// type = 2 if query
for (int i = 0; i < Q; i++) {
int x, t; // x = position, t = time
cin>>x>>t;
x--;
actions.pb({{t, 2}, {x, i}});
}
sort(actions.begin(), actions.end());
// queries come after updates
multiset<int> all[K]; // current open
vi ans(Q, -1);
for (pair<ii, ii> p : actions) {
int ct = p.fi.fi;
int type = p.fi.se;
if (type == 0) { // store open
int tr = p.se.fi; // store type
int pos = p.se.se;
all[tr].insert(pos);
}
else if (type == 1) {
int tr = p.se.fi;
int pos = p.se.se;
all[tr].erase(all[tr].find(pos));
}
else {
int x = p.se.fi;
int id = p.se.se;
ans[id] = -1;
for (int j = 0; j < K; j++) {
int md = 1e9; // minimum distance
// get lower and upper
auto it1 = all[j].lower_bound(x);
if (it1 != all[j].end())
md = min(md, (*it1) - x);
if (it1 != all[j].begin()) {
it1--;
md = min(md, x - (*it1));
}
ans[id] = max(ans[id], md);
}
}
}
// cout<<"ANSWER: "<<endl;
for (int i = 0; i < Q; i++) {
if (ans[i] != 1e9)
cout<<ans[i]<<endl;
else
cout<<-1<<endl;
}
}
Compilation message
new_home.cpp: In function 'int main()':
new_home.cpp:53:7: warning: unused variable 'ct' [-Wunused-variable]
53 | int ct = p.fi.fi;
| ^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 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 |
348 KB |
Output is correct |
9 |
Correct |
2 ms |
348 KB |
Output is correct |
10 |
Correct |
2 ms |
348 KB |
Output is correct |
11 |
Correct |
2 ms |
600 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
2 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
352 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 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 |
348 KB |
Output is correct |
9 |
Correct |
2 ms |
348 KB |
Output is correct |
10 |
Correct |
2 ms |
348 KB |
Output is correct |
11 |
Correct |
2 ms |
600 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
2 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
352 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
1658 ms |
8352 KB |
Output is correct |
32 |
Correct |
105 ms |
7016 KB |
Output is correct |
33 |
Correct |
188 ms |
8468 KB |
Output is correct |
34 |
Correct |
1215 ms |
8992 KB |
Output is correct |
35 |
Correct |
821 ms |
10324 KB |
Output is correct |
36 |
Correct |
223 ms |
11504 KB |
Output is correct |
37 |
Correct |
164 ms |
8160 KB |
Output is correct |
38 |
Correct |
118 ms |
9016 KB |
Output is correct |
39 |
Correct |
110 ms |
7968 KB |
Output is correct |
40 |
Correct |
118 ms |
9784 KB |
Output is correct |
41 |
Correct |
260 ms |
8704 KB |
Output is correct |
42 |
Correct |
255 ms |
8736 KB |
Output is correct |
43 |
Correct |
329 ms |
10592 KB |
Output is correct |
44 |
Correct |
191 ms |
7952 KB |
Output is correct |
45 |
Correct |
139 ms |
9060 KB |
Output is correct |
46 |
Correct |
109 ms |
8104 KB |
Output is correct |
47 |
Correct |
102 ms |
8216 KB |
Output is correct |
48 |
Correct |
95 ms |
8224 KB |
Output is correct |
49 |
Correct |
108 ms |
8988 KB |
Output is correct |
50 |
Correct |
186 ms |
7964 KB |
Output is correct |
51 |
Correct |
139 ms |
8204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5065 ms |
45464 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5058 ms |
40484 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 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 |
348 KB |
Output is correct |
9 |
Correct |
2 ms |
348 KB |
Output is correct |
10 |
Correct |
2 ms |
348 KB |
Output is correct |
11 |
Correct |
2 ms |
600 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
2 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
352 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
1658 ms |
8352 KB |
Output is correct |
32 |
Correct |
105 ms |
7016 KB |
Output is correct |
33 |
Correct |
188 ms |
8468 KB |
Output is correct |
34 |
Correct |
1215 ms |
8992 KB |
Output is correct |
35 |
Correct |
821 ms |
10324 KB |
Output is correct |
36 |
Correct |
223 ms |
11504 KB |
Output is correct |
37 |
Correct |
164 ms |
8160 KB |
Output is correct |
38 |
Correct |
118 ms |
9016 KB |
Output is correct |
39 |
Correct |
110 ms |
7968 KB |
Output is correct |
40 |
Correct |
118 ms |
9784 KB |
Output is correct |
41 |
Correct |
260 ms |
8704 KB |
Output is correct |
42 |
Correct |
255 ms |
8736 KB |
Output is correct |
43 |
Correct |
329 ms |
10592 KB |
Output is correct |
44 |
Correct |
191 ms |
7952 KB |
Output is correct |
45 |
Correct |
139 ms |
9060 KB |
Output is correct |
46 |
Correct |
109 ms |
8104 KB |
Output is correct |
47 |
Correct |
102 ms |
8216 KB |
Output is correct |
48 |
Correct |
95 ms |
8224 KB |
Output is correct |
49 |
Correct |
108 ms |
8988 KB |
Output is correct |
50 |
Correct |
186 ms |
7964 KB |
Output is correct |
51 |
Correct |
139 ms |
8204 KB |
Output is correct |
52 |
Execution timed out |
5097 ms |
14652 KB |
Time limit exceeded |
53 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 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 |
348 KB |
Output is correct |
9 |
Correct |
2 ms |
348 KB |
Output is correct |
10 |
Correct |
2 ms |
348 KB |
Output is correct |
11 |
Correct |
2 ms |
600 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
2 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
352 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
1658 ms |
8352 KB |
Output is correct |
32 |
Correct |
105 ms |
7016 KB |
Output is correct |
33 |
Correct |
188 ms |
8468 KB |
Output is correct |
34 |
Correct |
1215 ms |
8992 KB |
Output is correct |
35 |
Correct |
821 ms |
10324 KB |
Output is correct |
36 |
Correct |
223 ms |
11504 KB |
Output is correct |
37 |
Correct |
164 ms |
8160 KB |
Output is correct |
38 |
Correct |
118 ms |
9016 KB |
Output is correct |
39 |
Correct |
110 ms |
7968 KB |
Output is correct |
40 |
Correct |
118 ms |
9784 KB |
Output is correct |
41 |
Correct |
260 ms |
8704 KB |
Output is correct |
42 |
Correct |
255 ms |
8736 KB |
Output is correct |
43 |
Correct |
329 ms |
10592 KB |
Output is correct |
44 |
Correct |
191 ms |
7952 KB |
Output is correct |
45 |
Correct |
139 ms |
9060 KB |
Output is correct |
46 |
Correct |
109 ms |
8104 KB |
Output is correct |
47 |
Correct |
102 ms |
8216 KB |
Output is correct |
48 |
Correct |
95 ms |
8224 KB |
Output is correct |
49 |
Correct |
108 ms |
8988 KB |
Output is correct |
50 |
Correct |
186 ms |
7964 KB |
Output is correct |
51 |
Correct |
139 ms |
8204 KB |
Output is correct |
52 |
Execution timed out |
5065 ms |
45464 KB |
Time limit exceeded |
53 |
Halted |
0 ms |
0 KB |
- |