This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;
template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
int main() {
int n, q, K; scanf("%d%d%d", &n, &K, &q);
std::vector<int> x(n), t(n), a(n), b(n), l(n), y(n);
for(int i = 0; i < n; i++) {
scanf("%d%d%d%d", &x[i], &t[i], &a[i], &b[i]); t[i]--;
}
for(int i = 0; i < q; i++) scanf("%d%d", &l[i], &y[i]);
std::function<int (std::set<std::pair<int, int>>&, int)> calcDistSet = [](std::set<std::pair<int, int>>& st, int t) {
auto it = lower_bound(begin(st), end(st), std::make_pair(t, 0));
auto la = std::prev(it);
return std::min(std::abs((*it).first - t), std::abs((*la).first - t));
};
std::function<int (std::vector<std::pair<int, int>>&, int)> calcDist = [](std::vector<std::pair<int, int>>& vec, int t) {
int k = lower_bound(begin(vec), end(vec), std::make_pair(t, 0)) - begin(vec);
int ret = std::abs(vec[k].first - t);
if(k != 0) ret = std::min(ret, std::abs(vec[k - 1].first - t));
return ret;
};
std::vector<int> ans(q, -1);
if(K <= 400) {
std::vector<std::pair<int, int>> A, B;
for(int i = 0; i < n; i++) {
A.push_back({a[i], i});
B.push_back({b[i] + 1, i});
}
sort(begin(A), end(A)); sort(begin(B), end(B));
std::vector<std::pair<int, int>> query;
for(int i = 0; i < q; i++) query.push_back({y[i], i});
int curA = 0, curB = 0;
std::vector<std::set<std::pair<int, int>>> vec(K);
for(auto YYS: query) {
int L = l[YYS.second], Y = y[YYS.second];
while(curA < A.size() and A[curA].first <= Y) {
int p = A[curA++].second;
vec[t[p]].insert({x[p], p});
}
while(curB < B.size() and B[curB].first <= Y) {
int p = B[curB++].second;
vec[t[p]].erase({x[p], p});
}
/*
cout << "YEAR: " << Y << endl;
for(int k = 0; k < K; k++) {
cout << k << ": ";
for(auto v: vec[k]) cout << v.second + 1 << " ";
cout << endl;
}
cout << endl;
*/
int ret = -1;
for(int k = 0; k < K; k++) {
if(vec[k].empty()) {
ret = -1;
break;
}
ret = std::max(ret, calcDistSet(vec[k], L));
}
ans[YYS.second] = ret;
}
} else {
assert(0);
for(int i = 0; i < n; i++) assert(a[i] == 1 and b[i] == 1e8);
}
for(auto v: ans) printf("%d\n", v);
return 0;
}
Compilation message (stderr)
new_home.cpp: In function 'int main()':
new_home.cpp:53:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(curA < A.size() and A[curA].first <= Y) {
~~~~~^~~~~~~~~~
new_home.cpp:57:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(curB < B.size() and B[curB].first <= Y) {
~~~~~^~~~~~~~~~
new_home.cpp:17:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
int n, q, K; scanf("%d%d%d", &n, &K, &q);
~~~~~^~~~~~~~~~~~~~~~~~~~~~
new_home.cpp:20:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d%d", &x[i], &t[i], &a[i], &b[i]); t[i]--;
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
new_home.cpp:22:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for(int i = 0; i < q; i++) scanf("%d%d", &l[i], &y[i]);
~~~~~^~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |