#include "bits/stdc++.h"
using namespace std;
const int MAXN = 1e5+5;
int type[MAXN];
vector< multiset<int> > locations(MAXN);
vector< pair< pair<int, int>, pair<int, int> > > stores;
vector< pair<int, pair<int, int> > > queries;
vector<int> ans(MAXN);
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, k, q;
cin >> n >> k >> q;
for(int i = 0; i < n; i++)
{
int x, t, a, b;
cin >> x >> t >> a >> b;
stores.push_back({{a, 0}, {x, t}});
stores.push_back({{b + 1, 1}, {x, t}});
}
for(int i = 0; i < q; i++)
{
int l, y;
cin >> l >> y;
queries.push_back({y, {i, l}});
}
sort(queries.begin(), queries.end());
sort(stores.begin(), stores.end());
int curr = 0, use = 0;
multiset<int> elems;
for(int i = 0; i < q; i++)
{
while(curr < stores.size() && stores[curr].first.first <= queries[i].first)
{
if(stores[curr].first.second == 0)
{
type[stores[curr].second.second]++;
if(type[stores[curr].second.second] == 1)
use++;
locations[stores[curr].second.second].insert(stores[curr].second.first);
//elems.insert(stores[curr].second.first);
} else
{
type[stores[curr].second.second]--;
if(type[stores[curr].second.second] == 0)
use--;
locations[stores[curr].second.second].erase(locations[stores[curr].second.second].find(stores[curr].second.first));
//elems.erase(elems.find(stores[curr].second.first));
}
curr++;
}
if(use != k)
{
ans[queries[i].second.first] = -1;
} else
{
int res = 0;
for(int idx = 1; idx <= k; idx++)
{
if(locations[idx].size() == 0)
break;
auto it = locations[idx].upper_bound(queries[i].second.second);
int temp = 1e9;
if(it != locations[idx].end())
{
temp = min(temp, abs(queries[i].second.second - (*it)));
//cout << queries[i].second.second << "\n";
}
if(it != locations[idx].begin()) {
it--;
temp = min(temp, abs(queries[i].second.second - (*it)));
}
res = max(res, temp);
}
ans[queries[i].second.first] = res;
}
}
for(int i = 0; i < q; i++)
cout << ans[i] << "\n";
}
Compilation message
new_home.cpp: In function 'int main()':
new_home.cpp:36:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<int, int>, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
36 | while(curr < stores.size() && stores[curr].first.first <= queries[i].first)
| ~~~~~^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5332 KB |
Output is correct |
2 |
Correct |
3 ms |
5332 KB |
Output is correct |
3 |
Correct |
3 ms |
5428 KB |
Output is correct |
4 |
Correct |
3 ms |
5432 KB |
Output is correct |
5 |
Correct |
4 ms |
5456 KB |
Output is correct |
6 |
Correct |
4 ms |
5460 KB |
Output is correct |
7 |
Correct |
4 ms |
5400 KB |
Output is correct |
8 |
Correct |
4 ms |
5460 KB |
Output is correct |
9 |
Correct |
3 ms |
5460 KB |
Output is correct |
10 |
Correct |
4 ms |
5440 KB |
Output is correct |
11 |
Correct |
4 ms |
5440 KB |
Output is correct |
12 |
Correct |
3 ms |
5444 KB |
Output is correct |
13 |
Correct |
4 ms |
5460 KB |
Output is correct |
14 |
Correct |
4 ms |
5436 KB |
Output is correct |
15 |
Correct |
4 ms |
5460 KB |
Output is correct |
16 |
Correct |
4 ms |
5440 KB |
Output is correct |
17 |
Correct |
3 ms |
5460 KB |
Output is correct |
18 |
Correct |
5 ms |
5460 KB |
Output is correct |
19 |
Correct |
4 ms |
5440 KB |
Output is correct |
20 |
Correct |
3 ms |
5416 KB |
Output is correct |
21 |
Correct |
3 ms |
5440 KB |
Output is correct |
22 |
Correct |
4 ms |
5460 KB |
Output is correct |
23 |
Correct |
5 ms |
5460 KB |
Output is correct |
24 |
Correct |
5 ms |
5436 KB |
Output is correct |
25 |
Correct |
4 ms |
5444 KB |
Output is correct |
26 |
Correct |
4 ms |
5460 KB |
Output is correct |
27 |
Correct |
3 ms |
5460 KB |
Output is correct |
28 |
Correct |
4 ms |
5448 KB |
Output is correct |
29 |
Correct |
3 ms |
5460 KB |
Output is correct |
30 |
Correct |
4 ms |
5460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5332 KB |
Output is correct |
2 |
Correct |
3 ms |
5332 KB |
Output is correct |
3 |
Correct |
3 ms |
5428 KB |
Output is correct |
4 |
Correct |
3 ms |
5432 KB |
Output is correct |
5 |
Correct |
4 ms |
5456 KB |
Output is correct |
6 |
Correct |
4 ms |
5460 KB |
Output is correct |
7 |
Correct |
4 ms |
5400 KB |
Output is correct |
8 |
Correct |
4 ms |
5460 KB |
Output is correct |
9 |
Correct |
3 ms |
5460 KB |
Output is correct |
10 |
Correct |
4 ms |
5440 KB |
Output is correct |
11 |
Correct |
4 ms |
5440 KB |
Output is correct |
12 |
Correct |
3 ms |
5444 KB |
Output is correct |
13 |
Correct |
4 ms |
5460 KB |
Output is correct |
14 |
Correct |
4 ms |
5436 KB |
Output is correct |
15 |
Correct |
4 ms |
5460 KB |
Output is correct |
16 |
Correct |
4 ms |
5440 KB |
Output is correct |
17 |
Correct |
3 ms |
5460 KB |
Output is correct |
18 |
Correct |
5 ms |
5460 KB |
Output is correct |
19 |
Correct |
4 ms |
5440 KB |
Output is correct |
20 |
Correct |
3 ms |
5416 KB |
Output is correct |
21 |
Correct |
3 ms |
5440 KB |
Output is correct |
22 |
Correct |
4 ms |
5460 KB |
Output is correct |
23 |
Correct |
5 ms |
5460 KB |
Output is correct |
24 |
Correct |
5 ms |
5436 KB |
Output is correct |
25 |
Correct |
4 ms |
5444 KB |
Output is correct |
26 |
Correct |
4 ms |
5460 KB |
Output is correct |
27 |
Correct |
3 ms |
5460 KB |
Output is correct |
28 |
Correct |
4 ms |
5448 KB |
Output is correct |
29 |
Correct |
3 ms |
5460 KB |
Output is correct |
30 |
Correct |
4 ms |
5460 KB |
Output is correct |
31 |
Correct |
1736 ms |
14164 KB |
Output is correct |
32 |
Correct |
78 ms |
10308 KB |
Output is correct |
33 |
Correct |
141 ms |
12288 KB |
Output is correct |
34 |
Correct |
1371 ms |
12476 KB |
Output is correct |
35 |
Correct |
828 ms |
14148 KB |
Output is correct |
36 |
Correct |
180 ms |
14060 KB |
Output is correct |
37 |
Correct |
147 ms |
12124 KB |
Output is correct |
38 |
Correct |
83 ms |
11988 KB |
Output is correct |
39 |
Correct |
70 ms |
11980 KB |
Output is correct |
40 |
Correct |
73 ms |
11968 KB |
Output is correct |
41 |
Correct |
249 ms |
12220 KB |
Output is correct |
42 |
Correct |
195 ms |
12072 KB |
Output is correct |
43 |
Correct |
421 ms |
13756 KB |
Output is correct |
44 |
Correct |
196 ms |
12220 KB |
Output is correct |
45 |
Correct |
102 ms |
12184 KB |
Output is correct |
46 |
Correct |
61 ms |
12124 KB |
Output is correct |
47 |
Correct |
64 ms |
11684 KB |
Output is correct |
48 |
Correct |
64 ms |
11720 KB |
Output is correct |
49 |
Correct |
64 ms |
11852 KB |
Output is correct |
50 |
Correct |
121 ms |
12000 KB |
Output is correct |
51 |
Correct |
68 ms |
11804 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
455 ms |
66204 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
405 ms |
66060 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5332 KB |
Output is correct |
2 |
Correct |
3 ms |
5332 KB |
Output is correct |
3 |
Correct |
3 ms |
5428 KB |
Output is correct |
4 |
Correct |
3 ms |
5432 KB |
Output is correct |
5 |
Correct |
4 ms |
5456 KB |
Output is correct |
6 |
Correct |
4 ms |
5460 KB |
Output is correct |
7 |
Correct |
4 ms |
5400 KB |
Output is correct |
8 |
Correct |
4 ms |
5460 KB |
Output is correct |
9 |
Correct |
3 ms |
5460 KB |
Output is correct |
10 |
Correct |
4 ms |
5440 KB |
Output is correct |
11 |
Correct |
4 ms |
5440 KB |
Output is correct |
12 |
Correct |
3 ms |
5444 KB |
Output is correct |
13 |
Correct |
4 ms |
5460 KB |
Output is correct |
14 |
Correct |
4 ms |
5436 KB |
Output is correct |
15 |
Correct |
4 ms |
5460 KB |
Output is correct |
16 |
Correct |
4 ms |
5440 KB |
Output is correct |
17 |
Correct |
3 ms |
5460 KB |
Output is correct |
18 |
Correct |
5 ms |
5460 KB |
Output is correct |
19 |
Correct |
4 ms |
5440 KB |
Output is correct |
20 |
Correct |
3 ms |
5416 KB |
Output is correct |
21 |
Correct |
3 ms |
5440 KB |
Output is correct |
22 |
Correct |
4 ms |
5460 KB |
Output is correct |
23 |
Correct |
5 ms |
5460 KB |
Output is correct |
24 |
Correct |
5 ms |
5436 KB |
Output is correct |
25 |
Correct |
4 ms |
5444 KB |
Output is correct |
26 |
Correct |
4 ms |
5460 KB |
Output is correct |
27 |
Correct |
3 ms |
5460 KB |
Output is correct |
28 |
Correct |
4 ms |
5448 KB |
Output is correct |
29 |
Correct |
3 ms |
5460 KB |
Output is correct |
30 |
Correct |
4 ms |
5460 KB |
Output is correct |
31 |
Correct |
1736 ms |
14164 KB |
Output is correct |
32 |
Correct |
78 ms |
10308 KB |
Output is correct |
33 |
Correct |
141 ms |
12288 KB |
Output is correct |
34 |
Correct |
1371 ms |
12476 KB |
Output is correct |
35 |
Correct |
828 ms |
14148 KB |
Output is correct |
36 |
Correct |
180 ms |
14060 KB |
Output is correct |
37 |
Correct |
147 ms |
12124 KB |
Output is correct |
38 |
Correct |
83 ms |
11988 KB |
Output is correct |
39 |
Correct |
70 ms |
11980 KB |
Output is correct |
40 |
Correct |
73 ms |
11968 KB |
Output is correct |
41 |
Correct |
249 ms |
12220 KB |
Output is correct |
42 |
Correct |
195 ms |
12072 KB |
Output is correct |
43 |
Correct |
421 ms |
13756 KB |
Output is correct |
44 |
Correct |
196 ms |
12220 KB |
Output is correct |
45 |
Correct |
102 ms |
12184 KB |
Output is correct |
46 |
Correct |
61 ms |
12124 KB |
Output is correct |
47 |
Correct |
64 ms |
11684 KB |
Output is correct |
48 |
Correct |
64 ms |
11720 KB |
Output is correct |
49 |
Correct |
64 ms |
11852 KB |
Output is correct |
50 |
Correct |
121 ms |
12000 KB |
Output is correct |
51 |
Correct |
68 ms |
11804 KB |
Output is correct |
52 |
Correct |
71 ms |
14244 KB |
Output is correct |
53 |
Correct |
67 ms |
12464 KB |
Output is correct |
54 |
Correct |
78 ms |
14064 KB |
Output is correct |
55 |
Execution timed out |
5097 ms |
12032 KB |
Time limit exceeded |
56 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5332 KB |
Output is correct |
2 |
Correct |
3 ms |
5332 KB |
Output is correct |
3 |
Correct |
3 ms |
5428 KB |
Output is correct |
4 |
Correct |
3 ms |
5432 KB |
Output is correct |
5 |
Correct |
4 ms |
5456 KB |
Output is correct |
6 |
Correct |
4 ms |
5460 KB |
Output is correct |
7 |
Correct |
4 ms |
5400 KB |
Output is correct |
8 |
Correct |
4 ms |
5460 KB |
Output is correct |
9 |
Correct |
3 ms |
5460 KB |
Output is correct |
10 |
Correct |
4 ms |
5440 KB |
Output is correct |
11 |
Correct |
4 ms |
5440 KB |
Output is correct |
12 |
Correct |
3 ms |
5444 KB |
Output is correct |
13 |
Correct |
4 ms |
5460 KB |
Output is correct |
14 |
Correct |
4 ms |
5436 KB |
Output is correct |
15 |
Correct |
4 ms |
5460 KB |
Output is correct |
16 |
Correct |
4 ms |
5440 KB |
Output is correct |
17 |
Correct |
3 ms |
5460 KB |
Output is correct |
18 |
Correct |
5 ms |
5460 KB |
Output is correct |
19 |
Correct |
4 ms |
5440 KB |
Output is correct |
20 |
Correct |
3 ms |
5416 KB |
Output is correct |
21 |
Correct |
3 ms |
5440 KB |
Output is correct |
22 |
Correct |
4 ms |
5460 KB |
Output is correct |
23 |
Correct |
5 ms |
5460 KB |
Output is correct |
24 |
Correct |
5 ms |
5436 KB |
Output is correct |
25 |
Correct |
4 ms |
5444 KB |
Output is correct |
26 |
Correct |
4 ms |
5460 KB |
Output is correct |
27 |
Correct |
3 ms |
5460 KB |
Output is correct |
28 |
Correct |
4 ms |
5448 KB |
Output is correct |
29 |
Correct |
3 ms |
5460 KB |
Output is correct |
30 |
Correct |
4 ms |
5460 KB |
Output is correct |
31 |
Correct |
1736 ms |
14164 KB |
Output is correct |
32 |
Correct |
78 ms |
10308 KB |
Output is correct |
33 |
Correct |
141 ms |
12288 KB |
Output is correct |
34 |
Correct |
1371 ms |
12476 KB |
Output is correct |
35 |
Correct |
828 ms |
14148 KB |
Output is correct |
36 |
Correct |
180 ms |
14060 KB |
Output is correct |
37 |
Correct |
147 ms |
12124 KB |
Output is correct |
38 |
Correct |
83 ms |
11988 KB |
Output is correct |
39 |
Correct |
70 ms |
11980 KB |
Output is correct |
40 |
Correct |
73 ms |
11968 KB |
Output is correct |
41 |
Correct |
249 ms |
12220 KB |
Output is correct |
42 |
Correct |
195 ms |
12072 KB |
Output is correct |
43 |
Correct |
421 ms |
13756 KB |
Output is correct |
44 |
Correct |
196 ms |
12220 KB |
Output is correct |
45 |
Correct |
102 ms |
12184 KB |
Output is correct |
46 |
Correct |
61 ms |
12124 KB |
Output is correct |
47 |
Correct |
64 ms |
11684 KB |
Output is correct |
48 |
Correct |
64 ms |
11720 KB |
Output is correct |
49 |
Correct |
64 ms |
11852 KB |
Output is correct |
50 |
Correct |
121 ms |
12000 KB |
Output is correct |
51 |
Correct |
68 ms |
11804 KB |
Output is correct |
52 |
Runtime error |
455 ms |
66204 KB |
Execution killed with signal 11 |
53 |
Halted |
0 ms |
0 KB |
- |