#include "bits/stdc++.h"
using namespace std;
const int MAXN = 1e5+5;
int type[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++;
elems.insert(stores[curr].second.first);
} else
{
type[stores[curr].second.second]--;
if(type[stores[curr].second.second] == 0)
use--;
elems.erase(elems.find(stores[curr].second.first));
}
curr++;
}
if(use != k)
{
ans[queries[i].second.first] = -1;
} else
{
auto it = elems.end();
it--;
int left = abs(queries[i].second.second - (*elems.begin())), right = abs(queries[i].second.second - (*it));
ans[queries[i].second.first] = max(left, right);
}
}
for(int i = 0; i < q; i++)
cout << ans[i] << "\n";
}
Compilation message
new_home.cpp: In function 'int main()':
new_home.cpp:35: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]
35 | while(curr < stores.size() && stores[curr].first.first <= queries[i].first)
| ~~~~~^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
724 KB |
Output is correct |
2 |
Correct |
1 ms |
724 KB |
Output is correct |
3 |
Correct |
1 ms |
724 KB |
Output is correct |
4 |
Incorrect |
1 ms |
732 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
724 KB |
Output is correct |
2 |
Correct |
1 ms |
724 KB |
Output is correct |
3 |
Correct |
1 ms |
724 KB |
Output is correct |
4 |
Incorrect |
1 ms |
732 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
368 ms |
70060 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
375 ms |
69056 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
724 KB |
Output is correct |
2 |
Correct |
1 ms |
724 KB |
Output is correct |
3 |
Correct |
1 ms |
724 KB |
Output is correct |
4 |
Incorrect |
1 ms |
732 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
724 KB |
Output is correct |
2 |
Correct |
1 ms |
724 KB |
Output is correct |
3 |
Correct |
1 ms |
724 KB |
Output is correct |
4 |
Incorrect |
1 ms |
732 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |