#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define debug(a) cout << #a << " = " << a << endl
#define debugsl(a) cout << #a << " = " << a << ", "
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define repa(i,a,b) for(int i = (a); i >= (b); i--)
#define pll pair<lli,lli>
#define MAX 300000
#define INF (1ll<<60)
#define LIM 10000000000
//para el vector de orden
#define pos first
#define tipo second.first
#define id second.second
lli n,q,k,a,b,c,d,dif;
vector<pair<lli,pll>> orden;
lli res[MAX],vis[MAX+2];
void solve() {
//inicializa
lli last[MAX+2];
set<pll> activos;
rep(i,1,n) last[i] = INF;
for (auto act : orden) {
if(act.tipo == 0) {
if (last[act.id] != INF) activos.erase({last[act.id],act.id});
last[act.id] = act.pos;
activos.insert({last[act.id],act.id});
}
else {
if (activos.empty()) continue;
lli op = (*activos.begin()).first;
lli mejor = abs( abs(op) - abs(act.pos) );
res[act.id] = max(res[act.id],mejor);
}
}
}
//solucion de s3
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> k >> q;
rep(i,1,n) {
cin >> a >> b >> c >> d;
orden.push_back({a,{0,b}});
if (!vis[b]) {
vis[b] = 1;
dif++;
}
}
rep(i,1,q) {
cin >> a >> b;
orden.push_back({a,{1,i}});
}
if(dif < k) {
rep(i,1,q) cout << "-1\n";
return 0;
}
sort(orden.begin(),orden.end());
solve();
reverse(orden.begin(), orden.end());
for(auto &act : orden) act.pos *= (-1);
solve();
rep(i,1,q) if (res[i] > LIM) cout << "-1\n";
else cout << res[i] << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2644 KB |
Output is correct |
2 |
Incorrect |
1 ms |
2644 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2644 KB |
Output is correct |
2 |
Incorrect |
1 ms |
2644 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
393 ms |
26024 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
323 ms |
25024 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2644 KB |
Output is correct |
2 |
Incorrect |
1 ms |
2644 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2644 KB |
Output is correct |
2 |
Incorrect |
1 ms |
2644 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |