# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
51993 | pzdba | New Home (APIO18_new_home) | C++14 | 3327 ms | 146460 KiB |
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;
typedef pair<int, int> pii;
map<int, int> ht;
map<int, int>::iterator its;
int x[300005], t[300005], a[300005], b[300005];
int l[300005], y[300005];
int tot[300005];
int mn[1000005], mx[1000005];
bool ok[1000005];
vector<int> st[1000005], en[1000005];
int main(){
int n, k, q;
scanf("%d%d%d", &n, &k, &q);
for(int i=1;i<=n;i++){
scanf("%d%d%d%d", &x[i], &t[i], &a[i], &b[i]);
ht[a[i]] = 1;
ht[b[i]] = 1;
}
for(int i=1;i<=q;i++){
scanf("%d%d", &l[i], &y[i]);
ht[y[i]] = 1;
}
int sum = 1;
for(its = ht.begin();its != ht.end();its++){
its->second = sum++;
}
sum--;
for(int i=1;i<=n;i++){
a[i] = ht[a[i]];
b[i] = ht[b[i]];
printf("i = %d %d %d\n", i, a[i], b[i]);
st[a[i]].push_back(i);
en[b[i]].push_back(i);
}
int cnt = 0;
set<pii> ms;
for(int i=1;i<=sum;i++){
for(int j=0;j<st[i].size();j++){
int idx = st[i][j];
tot[t[idx]]++;
if(tot[t[idx]] == 1) cnt++;
ms.insert(pii(x[idx], idx));
}
if(cnt == k){
ok[i] = 1;
mn[i] = ms.begin()->first;
mx[i] = (--ms.end())->first;
}
for(int j=0;j<en[i].size();j++){
int idx = en[i][j];
tot[t[idx]]--;
if(tot[t[idx]] == 0) cnt--;
ms.erase(ms.find(pii(x[idx], idx)));
}
}
for(int i=1;i<=q;i++){
y[i] = ht[y[i]];
if(!ok[y[i]]) printf("%d\n", -1);
else printf("%d\n", max(abs(mn[y[i]]-l[i]), abs(mx[y[i]]-l[i])));
}
}
Compilation message (stderr)
# | 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... |