#include <bits/stdc++.h>
#define int long long
using namespace std;
typedef pair<int,int> P;
int X[300005];
int type[300005];
int A[300005];
int B[300005];
int L[300005];
int Y[300005];
int ans[300005];
signed main() {
cin.sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int N, K, Q;
cin >> N >> K >> Q;
int i, j;
for(i=0;i<N;i++) cin >> X[i] >> type[i] >> A[i] >> B[i];
vector<map<int,int>> S;
S.resize(K);
for(i=0;i<Q;i++) cin >> L[i] >> Y[i];
map<int,vector<P>> In;
map<int,vector<P>> Out;
for(i=0;i<N;i++) {
type[i]--;
In[A[i]].push_back(P(type[i],X[i]));
Out[B[i]].push_back(P(type[i],X[i]));
}
map<int,vector<P>> Query;
for(i=0;i<Q;i++) {
Query[Y[i]].push_back(P(L[i],i));
}
vector<int> idx;
for(i=0;i<Q;i++) idx.push_back(Y[i]);
for(i=0;i<N;i++) {
idx.push_back(A[i]);
idx.push_back(B[i]);
}
sort(idx.begin(),idx.end());
idx.erase(unique(idx.begin(),idx.end()),idx.end());
for(i=0;i<idx.size();i++) {
for(P k : In[idx[i]]) {
S[k.first][k.second]++;
//S[k.first].insert(k.second);
}
for(P k : Query[idx[i]]) {
int ma = 0;
int pos = k.first;
for(j=0;j<K;j++) {
int dis = 1e18;
auto it = S[j].lower_bound(pos);
if(it != S[j].end()) dis = min(dis, it->first - pos);
if(it != S[j].begin()) {
it--;
dis = min(dis, pos - it->first);
}
ma = max(ma, dis);
}
ans[k.second] = (ma > 1e9 ? -1 : ma);
}
for(P k : Out[idx[i]]) {
S[k.first][k.second]--;
if(S[k.first][k.second]==0) {
S[k.first].erase(k.second);
}
}
}
for(i=0;i<Q;i++) cout << ans[i] << '\n';
}
Compilation message
new_home.cpp: In function 'int main()':
new_home.cpp:42:14: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
42 | for(i=0;i<idx.size();i++) {
| ~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
320 KB |
Output is correct |
4 |
Correct |
0 ms |
328 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
2 ms |
724 KB |
Output is correct |
7 |
Correct |
3 ms |
760 KB |
Output is correct |
8 |
Correct |
2 ms |
760 KB |
Output is correct |
9 |
Correct |
2 ms |
724 KB |
Output is correct |
10 |
Correct |
2 ms |
716 KB |
Output is correct |
11 |
Correct |
2 ms |
724 KB |
Output is correct |
12 |
Correct |
2 ms |
724 KB |
Output is correct |
13 |
Correct |
2 ms |
724 KB |
Output is correct |
14 |
Correct |
2 ms |
724 KB |
Output is correct |
15 |
Correct |
2 ms |
720 KB |
Output is correct |
16 |
Correct |
2 ms |
724 KB |
Output is correct |
17 |
Correct |
2 ms |
636 KB |
Output is correct |
18 |
Correct |
2 ms |
724 KB |
Output is correct |
19 |
Correct |
2 ms |
724 KB |
Output is correct |
20 |
Correct |
2 ms |
724 KB |
Output is correct |
21 |
Correct |
1 ms |
468 KB |
Output is correct |
22 |
Correct |
2 ms |
724 KB |
Output is correct |
23 |
Correct |
2 ms |
724 KB |
Output is correct |
24 |
Correct |
2 ms |
720 KB |
Output is correct |
25 |
Correct |
2 ms |
724 KB |
Output is correct |
26 |
Correct |
2 ms |
724 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
2 ms |
724 KB |
Output is correct |
29 |
Correct |
2 ms |
648 KB |
Output is correct |
30 |
Correct |
1 ms |
596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
320 KB |
Output is correct |
4 |
Correct |
0 ms |
328 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
2 ms |
724 KB |
Output is correct |
7 |
Correct |
3 ms |
760 KB |
Output is correct |
8 |
Correct |
2 ms |
760 KB |
Output is correct |
9 |
Correct |
2 ms |
724 KB |
Output is correct |
10 |
Correct |
2 ms |
716 KB |
Output is correct |
11 |
Correct |
2 ms |
724 KB |
Output is correct |
12 |
Correct |
2 ms |
724 KB |
Output is correct |
13 |
Correct |
2 ms |
724 KB |
Output is correct |
14 |
Correct |
2 ms |
724 KB |
Output is correct |
15 |
Correct |
2 ms |
720 KB |
Output is correct |
16 |
Correct |
2 ms |
724 KB |
Output is correct |
17 |
Correct |
2 ms |
636 KB |
Output is correct |
18 |
Correct |
2 ms |
724 KB |
Output is correct |
19 |
Correct |
2 ms |
724 KB |
Output is correct |
20 |
Correct |
2 ms |
724 KB |
Output is correct |
21 |
Correct |
1 ms |
468 KB |
Output is correct |
22 |
Correct |
2 ms |
724 KB |
Output is correct |
23 |
Correct |
2 ms |
724 KB |
Output is correct |
24 |
Correct |
2 ms |
720 KB |
Output is correct |
25 |
Correct |
2 ms |
724 KB |
Output is correct |
26 |
Correct |
2 ms |
724 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
2 ms |
724 KB |
Output is correct |
29 |
Correct |
2 ms |
648 KB |
Output is correct |
30 |
Correct |
1 ms |
596 KB |
Output is correct |
31 |
Correct |
3262 ms |
60160 KB |
Output is correct |
32 |
Correct |
43 ms |
9580 KB |
Output is correct |
33 |
Correct |
444 ms |
57560 KB |
Output is correct |
34 |
Correct |
2274 ms |
57896 KB |
Output is correct |
35 |
Correct |
1549 ms |
60024 KB |
Output is correct |
36 |
Correct |
521 ms |
59860 KB |
Output is correct |
37 |
Correct |
372 ms |
56512 KB |
Output is correct |
38 |
Correct |
296 ms |
56416 KB |
Output is correct |
39 |
Correct |
249 ms |
56140 KB |
Output is correct |
40 |
Correct |
262 ms |
56128 KB |
Output is correct |
41 |
Correct |
457 ms |
56260 KB |
Output is correct |
42 |
Correct |
549 ms |
56292 KB |
Output is correct |
43 |
Correct |
89 ms |
10828 KB |
Output is correct |
44 |
Correct |
440 ms |
56308 KB |
Output is correct |
45 |
Correct |
294 ms |
56344 KB |
Output is correct |
46 |
Correct |
228 ms |
56320 KB |
Output is correct |
47 |
Correct |
189 ms |
54384 KB |
Output is correct |
48 |
Correct |
195 ms |
53988 KB |
Output is correct |
49 |
Correct |
220 ms |
54944 KB |
Output is correct |
50 |
Correct |
363 ms |
55852 KB |
Output is correct |
51 |
Correct |
224 ms |
54720 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5058 ms |
87344 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5032 ms |
114604 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
320 KB |
Output is correct |
4 |
Correct |
0 ms |
328 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
2 ms |
724 KB |
Output is correct |
7 |
Correct |
3 ms |
760 KB |
Output is correct |
8 |
Correct |
2 ms |
760 KB |
Output is correct |
9 |
Correct |
2 ms |
724 KB |
Output is correct |
10 |
Correct |
2 ms |
716 KB |
Output is correct |
11 |
Correct |
2 ms |
724 KB |
Output is correct |
12 |
Correct |
2 ms |
724 KB |
Output is correct |
13 |
Correct |
2 ms |
724 KB |
Output is correct |
14 |
Correct |
2 ms |
724 KB |
Output is correct |
15 |
Correct |
2 ms |
720 KB |
Output is correct |
16 |
Correct |
2 ms |
724 KB |
Output is correct |
17 |
Correct |
2 ms |
636 KB |
Output is correct |
18 |
Correct |
2 ms |
724 KB |
Output is correct |
19 |
Correct |
2 ms |
724 KB |
Output is correct |
20 |
Correct |
2 ms |
724 KB |
Output is correct |
21 |
Correct |
1 ms |
468 KB |
Output is correct |
22 |
Correct |
2 ms |
724 KB |
Output is correct |
23 |
Correct |
2 ms |
724 KB |
Output is correct |
24 |
Correct |
2 ms |
720 KB |
Output is correct |
25 |
Correct |
2 ms |
724 KB |
Output is correct |
26 |
Correct |
2 ms |
724 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
2 ms |
724 KB |
Output is correct |
29 |
Correct |
2 ms |
648 KB |
Output is correct |
30 |
Correct |
1 ms |
596 KB |
Output is correct |
31 |
Correct |
3262 ms |
60160 KB |
Output is correct |
32 |
Correct |
43 ms |
9580 KB |
Output is correct |
33 |
Correct |
444 ms |
57560 KB |
Output is correct |
34 |
Correct |
2274 ms |
57896 KB |
Output is correct |
35 |
Correct |
1549 ms |
60024 KB |
Output is correct |
36 |
Correct |
521 ms |
59860 KB |
Output is correct |
37 |
Correct |
372 ms |
56512 KB |
Output is correct |
38 |
Correct |
296 ms |
56416 KB |
Output is correct |
39 |
Correct |
249 ms |
56140 KB |
Output is correct |
40 |
Correct |
262 ms |
56128 KB |
Output is correct |
41 |
Correct |
457 ms |
56260 KB |
Output is correct |
42 |
Correct |
549 ms |
56292 KB |
Output is correct |
43 |
Correct |
89 ms |
10828 KB |
Output is correct |
44 |
Correct |
440 ms |
56308 KB |
Output is correct |
45 |
Correct |
294 ms |
56344 KB |
Output is correct |
46 |
Correct |
228 ms |
56320 KB |
Output is correct |
47 |
Correct |
189 ms |
54384 KB |
Output is correct |
48 |
Correct |
195 ms |
53988 KB |
Output is correct |
49 |
Correct |
220 ms |
54944 KB |
Output is correct |
50 |
Correct |
363 ms |
55852 KB |
Output is correct |
51 |
Correct |
224 ms |
54720 KB |
Output is correct |
52 |
Execution timed out |
5040 ms |
38284 KB |
Time limit exceeded |
53 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
320 KB |
Output is correct |
4 |
Correct |
0 ms |
328 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
2 ms |
724 KB |
Output is correct |
7 |
Correct |
3 ms |
760 KB |
Output is correct |
8 |
Correct |
2 ms |
760 KB |
Output is correct |
9 |
Correct |
2 ms |
724 KB |
Output is correct |
10 |
Correct |
2 ms |
716 KB |
Output is correct |
11 |
Correct |
2 ms |
724 KB |
Output is correct |
12 |
Correct |
2 ms |
724 KB |
Output is correct |
13 |
Correct |
2 ms |
724 KB |
Output is correct |
14 |
Correct |
2 ms |
724 KB |
Output is correct |
15 |
Correct |
2 ms |
720 KB |
Output is correct |
16 |
Correct |
2 ms |
724 KB |
Output is correct |
17 |
Correct |
2 ms |
636 KB |
Output is correct |
18 |
Correct |
2 ms |
724 KB |
Output is correct |
19 |
Correct |
2 ms |
724 KB |
Output is correct |
20 |
Correct |
2 ms |
724 KB |
Output is correct |
21 |
Correct |
1 ms |
468 KB |
Output is correct |
22 |
Correct |
2 ms |
724 KB |
Output is correct |
23 |
Correct |
2 ms |
724 KB |
Output is correct |
24 |
Correct |
2 ms |
720 KB |
Output is correct |
25 |
Correct |
2 ms |
724 KB |
Output is correct |
26 |
Correct |
2 ms |
724 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
2 ms |
724 KB |
Output is correct |
29 |
Correct |
2 ms |
648 KB |
Output is correct |
30 |
Correct |
1 ms |
596 KB |
Output is correct |
31 |
Correct |
3262 ms |
60160 KB |
Output is correct |
32 |
Correct |
43 ms |
9580 KB |
Output is correct |
33 |
Correct |
444 ms |
57560 KB |
Output is correct |
34 |
Correct |
2274 ms |
57896 KB |
Output is correct |
35 |
Correct |
1549 ms |
60024 KB |
Output is correct |
36 |
Correct |
521 ms |
59860 KB |
Output is correct |
37 |
Correct |
372 ms |
56512 KB |
Output is correct |
38 |
Correct |
296 ms |
56416 KB |
Output is correct |
39 |
Correct |
249 ms |
56140 KB |
Output is correct |
40 |
Correct |
262 ms |
56128 KB |
Output is correct |
41 |
Correct |
457 ms |
56260 KB |
Output is correct |
42 |
Correct |
549 ms |
56292 KB |
Output is correct |
43 |
Correct |
89 ms |
10828 KB |
Output is correct |
44 |
Correct |
440 ms |
56308 KB |
Output is correct |
45 |
Correct |
294 ms |
56344 KB |
Output is correct |
46 |
Correct |
228 ms |
56320 KB |
Output is correct |
47 |
Correct |
189 ms |
54384 KB |
Output is correct |
48 |
Correct |
195 ms |
53988 KB |
Output is correct |
49 |
Correct |
220 ms |
54944 KB |
Output is correct |
50 |
Correct |
363 ms |
55852 KB |
Output is correct |
51 |
Correct |
224 ms |
54720 KB |
Output is correct |
52 |
Execution timed out |
5058 ms |
87344 KB |
Time limit exceeded |
53 |
Halted |
0 ms |
0 KB |
- |